FFMPEG Combining Two Commands Into One - ffmpeg

Im currently trying to combine trim and delogo together, looked over a few tutorials but i just have no clue.
trim:
ffmpeg -i input.mp4 -ss 00:00:05 -t 00:00:10 -async 1 ouput.mp4
delogo:
ffmpeg -i input.mp4 -vf "delogo=x=1075:y=9:w=170:h=52" -c:a copy ouput.mp4
I want to combine these two commands so i can run one execution which will do both within, instead of 2 separate commands

As simple as
ffmpeg -i input.mp4 -ss 5 -t 10 -vf "delogo=x=1075:y=9:w=170:h=52" -c:a copy ouput.mp4

Related

How to add a hard code of subs to this filter_complex

ffmpeg -ss 00:11:47.970 -t 3.090 -i "file.mkv" -ss 00:11:46.470 -t 1.500 -i "file" -ss 00:11:51.060 -t 0.960 -i "file.mkv" -an -c:v libvpx -crf 31 -b:v 10000k -y -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa];[outv]scale='min(960,iw)':-1[outv];[outv]subtitles='file.srt'[outv]" -map [outv] file_out.webm -map [outa] file.mp3
I have a filter where take three different points in a file concat them together and scale them down this part works
Im looking to see how to add to the filter_complex a sub burn in step rendering the subs from the exact timings usings a file that I specify when I use the above code it doesn't work
The subtitles filter is receiving a concatenated stream. It does not contain the timestamps from the original segments. So the subtitles filter starts from the beginning. I'm assuming this is the problem when you said, "it doesn't work".
The simple method to solve this is to make temporary files then concatenate them.
Output segments
ffmpeg -ss 00:11:47.970 -t 3.090 -copyts -i "file.mkv" -filter_complex "scale='min(960,iw)':-1,subtitles='file.srt',setpts=PTS-STARTPTS;asetpts=PTS-STARTPTS" -crf 31 -b:v 10000k temp1.webm
ffmpeg -ss 00:11:46.470 -t 1.500 -copyts -i "file.mkv" -filter_complex "scale='min(960,iw)':-1,subtitles='file.srt',setpts=PTS-STARTPTS;asetpts=PTS-STARTPTS" -crf 31 -b:v 10000k temp2.webm
ffmpeg -ss 00:11:51.060 -t 0.960 -copyts -i "file.mkv" -filter_complex "scale='min(960,iw)':-1,subtitles='file.srt',setpts=PTS-STARTPTS;asetpts=PTS-STARTPTS" -crf 31 -b:v 10000k temp3.webm
The timestamps are reset when fast seek is used (-ss before -i). -copytswill preserve the timestamps so the subtitles filter knows where to start the subtitles.
Make input.txt:
file 'temp1.webm'
file 'temp2.webm'
file 'temp3.webm'
Concatenate with the concat demuxer:
ffmpeg -f concat -i input.txt -c copy output.webm
-c copy enables stream copy mode so it avoids re-encoding to concatenate.

ffmpeg, apply fade only to video input using filter_complex while concating

ffmpeg -i foo.mp4 -filter_complex "fade=d=0.5, reverse, fade=d=0.5, reverse" output.mp4
can be used to fade in and out foo.mp4 video. (we do not care about audio). According to https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration
It's good but only works in the simple situation of 1 input video, and 1 output. Now, how can I apply the fade in and out effect in the following more complex situation? I'm trying to concat a.jpg (a picture) with bar.mp4. I want only the bar.mp4 portion to fade in and out.
ffmpeg -loop 1 -t 2 -framerate 1 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[0][1][2:v][2:a] concat=n=2:v=1:a=1 [vpre][a];[vpre]fps=24[v]" -map "[v]" -map "[a]" out.mp4 -y
Of course, I could first create a temporary temp.mp4 from bar.mp4 by running the first command, then input temp.mp4 in my second command. This involves an extra step and extra encoding. Could anyone help fix the commands or suggest something even better?
Use
ffmpeg -loop 1 -t 2 -framerate 24 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[2:v]fade=d=0.5, reverse, fade=d=0.5, reverse[v2];[0][1][v2][2:a] concat=n=2:v=1:a=1 [v][a]" -map "[v]" -map "[a]" out.mp4 -y

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

How to get image from video and combine other image using ffmpeg

I want to get a frame from video to combine with other image
using two ffmpeg commands as:
command 1:
ffmpeg -ss 3 -i video.mp4 -vf \"select=gt(scene\,0.4)\"
-frames:v 5 -vsync vfr -vf fps=fps=1/100
-vf scale=150:150 output.jpeg
command 2:
ffmpeg -i output.jpeg -i other.png -filter_complex "[0:v][1:v]
overlay=(W-w)/2:(H-h)/2:enable='between(t,0,20)'"
-pix_fmt yuv420p -c:a copy output2.jpg
how to combine two commands in one, or
how to get frame from video and combine other image in one?
You can combine the two commands using the and && after the first command which allows you to execute the second command based on whether the first command completed successfully:
ffmpeg -ss 3 -i video.mp4 -vf "select=eq(n\,4)"
-frames:v 5 -vsync vfr -vf fps=fps=1/100
-vf scale=150:150 output.jpeg
&&
ffmpeg -i output.jpeg -i other.png -filter_complex "[0:v][1:v]
overlay=(W-w)/2:(H-h)/2:enable='between(t,0,20)'"
-pix_fmt yuv420p -c:a copy output2.jpg
Now if you want to combine multiple images onto one, Take a look at this solution

How to merge a video vertically by taking specific time slots from two different videos with a single ffmpeg command?

I have three ffmpeg commands. Two of those commands will trim the input videos and the third will merge into a single video.
I want to run them as a single command instead of three, which consumes a lot of time because I'm taking output of the 1st and 2nd videos individually.
Instead, I want to take specific parts from the videos which I need and merge them as a single video.
The commands which I use for singie videos trim:-
ffmpeg -y -i video1.mp4 -ss 4 -t 10000 -qscale:v 8 -strict -2 video1out.mp4
ffmpeg -y -i video2.mp4 -ss 4 -t 10000 -qscale:v 8 -strict -2 video2out.mp4
ffmpeg -i video1out.mp4 -i video2out.mp4 -filter_complex vstack -strict -2 merge.mp4
Use
ffmpeg -ss 4 -t 10000 -i video1.mp4 -ss 4 -t 10000 -i video2.mp4 -filter_complex vstack -c:a copy merge.mp4
-strict -2 hasn't been required for AAC encoder use since 2016. You should upgrade ffmpeg.

Resources