ffmpeg - extract subtitles from piped input? - ffmpeg

I have found two separate commands that I want to combine. One for taking piped input:
ffmpeg -i pipe:0
And another for extracting subtitles from a .ts file:
ffmpeg -i "movie=file.ts[out0+subcc]" -map s output.srt
But I can't work out how to combine them.
ffmpeg -i "movie=pipe:0[out0+subcc]" -map s output.srt
doesn't work. I'm kind of an ffmpeg newbie, so any ideas?

The solution requires escaping the colon after the "pipe".
Depending on your shell, and quoting rules, you'll need from 2 backslashes to... well, who knows :-)
Here's what has worked for me:
cat input.ts | ffmpeg -f lavfi -i 'movie=pipe\\:0[out+subcc]' -map s output.srt
If you use double quotes you'll need at least another backslash:
cat input.ts | ffmpeg -f lavfi -i "movie=pipe\\\:0[out+subcc]" -map s output.srt
Source: https://trac.ffmpeg.org/ticket/5229

Related

How to apply any mask.png on a video with ffmpeg

I am adding a 1.mp4 on a video 2.mp4, and i want to add a mask on overlay video(1.mp4)
I want to apply this mask on 1.mp4
I'm using chrome key right now
ffmpeg -t 5 -r 30 -f lavfi -i color=c=black:s=640x360
-i 1.mp4
-i mask2.png
-i 2.mp4
-filter_complex "
[1:v]scale=500x281[v1];
[2]scale=500x281[mask];
[v1][mask]overlay, chromakey=0x00FF00:0.25:0.08 [v2];
[3:v]scale=640x360[v3];
[0][v3]overlay [out1];
[out1][v2]overlay=0:0"
-y output.mp4
But it also removes color from videos.
I'm not sure but i think it can be done by negate
also i don't need audio command, i already done that part
Thanks

merge audio and video with ffmpeg doesnt work correctly

I have ubuntu 20.04 and in past days I did this job(merge video and audio) well in terminal and with ffmpeg:
ffmpeg -i input.mp4 -i input2.mp3 -c copy output.mp4
so fast I have recived output.mp4, but now I tried this one and get output without any sound!
I try another ways to merge this ones(also with ffmpeg) but there are no diffrent...
ffmpeg -f concat -safe 0 -i <(for f in ./input*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
Note -f concat will select a demuxer. This alters the way -i nput files are read.
So instead video-files 'concat expects a txt-file listing the files to concatenate.
However we somehow omit the creation of that text file and use process substitution to generate and pass that list on the fly to demux.
For more details go here:
https://trac.ffmpeg.org/wiki/Concatenate#demuxer
If you want to merge several video files, you can use these command.
merge two video files.
ffmpeg -f concat -i 1.mp4 -1 2.mp4 -codec copy out.mp4
merge multiple video files.
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mpt -vcodec copy -acodec copy out.mp4

Extract LUFS only from multiple file

ffmpeg -i input.mp4 -af ebur128=framelog=verbose -f null - 2>&1 | awk '/I:/{print $2}'
The above command extract only LUFS value from input.mp4 file. But If there are number of mp4 files, how to apply similar command to extract LUFS value only from multiple mp4 files?
Please help.
Adapting this answer from How do you convert an entire directory with ffmpeg?
for i in *.mp4; do echo "$i:"; ffmpeg -i "$i" -map 0:a -af ebur128=framelog=verbose -f null - 2>&1 | awk '/I:/{print $2}'; done
Example output:
video1.mp4:
-21.8
video2.mp4:
-21.1
video3.mp4:
-21.8
-8.3
Note that video3.mp4 contains 2 separate audio streams.
This is assuming you can use Bash shell.
-map 0:a was added to only process the audio so the video is ignored and therefore the command is faster. See FFmpeg Wiki: Map.

ffmpeg: Infinite length output when overlaying subtitles onto black image

I'm trying to do some analysis of image-based subtitles by outputting them as a sequence of PNGs to a pipe. My command line looks like this:
ffmpeg -y -i $INPUTFILE -f lavfi -i color=c=black:s=1920x1080 -filter_complex "[1:v][0:s:5]overlay[v]" -shortest -map "[v]" -c:v png -f image2pipe - | pike subspng.pike
In theory, -shortest should mean that the stream stops at the shortest input, which would be roughly seven minutes of input file. Instead, my script receives an infinite sequence of black frames after the last frame of subtitles, until I send FFMPEG a SIGINT. Placing -shortest before -filter_complex has the same effect.
Is there a different way to force the filtering to stop at the end of the input file?
EDIT: Using the shortest=1 flag on the overlay filter also doesn't help, even in combination with -shortest.
Use the shortest option in the overlay filter:
shortest
If set to 1, force the output to terminate when the shortest input terminates. Default value is 0.
ffmpeg -y -i $INPUTFILE -f lavfi -i color=c=black:s=1920x1080 -filter_complex "[1:v][0:s:5]overlay=shortest=1[v]" -map "[v]" -c:v png -f image2pipe - | pike subspng.pike
Building on the suggestions from both llogan and Gyan, here's what I came up with:
ffmpeg -y -i $INPUTFILE -filter_complex "[0:v]drawbox=c=black:t=fill[black]; [black][0:s:5]overlay=shortest=1[v]" -map "[v]" -c:v png -f image2pipe - | pike subspng.pike
Instead of creating an infinite-length source of black frames, this instead takes the original video stream, then covers the entire thing with a black box. NOTE: May require a newish version of FFMPEG for the drawbox filter.

How to add multiple audio files at specific times, on a silence audio file using ffmpeg?

I need to overlay audio files at specific times, on an existing silence.mp3. Something like that:
[----[...audio1...]----------[...audio2...]---------------]
I've tried the following but it doesn't work:
ffmpeg -y -i silence.mp3 -itsoffset 4 -i audio1.mp3 -itsoffset 30 -i audio2.mp3 -c:a copy final.mp3
Any help would be appriciated. Thank you.
There are several methods.
adelay, amix
Use the adelay and amix filters:
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0]adelay=4s:all=1[0a];[1]adelay=30s:all=1[1a];[0a][1a]amix=inputs=2[a]" -map "[a]" output.mp3
Note that the amix filter will reduce volume of the output to prevent clipping. Followup with dynaudnorm or volume filters if desired.
adelay, concat filter
Or adelay and concat filters. This assumes audio1.mp4 is 10 seconds long, and both inputs have the same sample rate and channel layout:
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0]adelay=4s:all=1[0a];[1]adelay=16s:all=1[1a];[0a][1a]concat=n=2:v=0:a=1[a]" -map "[a]" output.mp3
anullsrc, concat demuxer
Or generate silent files as spacers with the anullsrc filter:
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 4 4.mp3
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 16 16.mp3
Create input.txt:
file '4.mp3'
file 'audio1.mp3'
file '16.mp3'
file 'audio2.mp3'
Then use the concat demuxer:
ffmpeg -f concat -i input.txt -c copy output.mp3

Resources