ffmpeg combining multiple commands into one - ffmpeg

Justing wondering how to combine below commands into one, I have searched how to combine simple filters with comma and complex filter with colon, but I'm not sure how to do this.
Basically I want the output of the first command to be the input of the second.
Command 1: concatenate multiple clips into one with different xfade transitions.
Command 2: add a fade in for a video
ffmpeg -i input0.mp4 -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -filter_complex "[0:v][1:v]xfade=transition=fade:duration=0.500:offset=27.486[v01];[v01][2:v]xfade=transition=fadeblack:duration=1.000:offset=31.531[v02];[v02][3:v]xfade=transition=fadeblack:duration=1.000:offset=42.972[v03];[v03][4:v]xfade=transition=fade:duration=0.500:offset=94.149,format=yuv420p[video];[0:a][1:a]acrossfade=d=0.500:c1=tri:c2=tri[a01];[a01][2:a]acrossfade=d=1.000:c1=tri:c2=tri[a02];[a02][3:a]acrossfade=d=1.000:c1=tri:c2=tri[a03];[a03][4:a]acrossfade=d=0.500:c1=tri:c2=tri[audio]" -map [video] -map [audio] -movflags +faststart output.mp4
ffmpeg -i input.mp4 -vf "fade=t=in:st=0.000:d=1.000:color=black" -c:a copy output.mp4

Combined command:
ffmpeg -i input0.mp4 -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -filter_complex "[0:v][1:v]xfade=transition=fade:duration=0.500:offset=27.486[v01];[v01][2:v]xfade=transition=fadeblack:duration=1.000:offset=31.531[v02];[v02][3:v]xfade=transition=fadeblack:duration=1.000:offset=42.972[v03];[v03][4:v]xfade=transition=fade:duration=0.500:offset=94.149,format=yuv420p,fade=t=in:st=0.000:d=1.000:color=black[video];[0:a][1:a]acrossfade=d=0.500:c1=tri:c2=tri[a01];[a01][2:a]acrossfade=d=1.000:c1=tri:c2=tri[a02];[a02][3:a]acrossfade=d=1.000:c1=tri:c2=tri[a03];[a03][4:a]acrossfade=d=0.500:c1=tri:c2=tri[audio]" -map [video] -map [audio] -movflags +faststart output.mp4

Related

How to use -filter_complex and -vf in same command in FFMPEG

I edit the video with the command
ffmpeg -i video.mp4 -y -vf eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t -c:a copy output.mp4
then the resulting video
ffmpeg -i output.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I tried to combine all this together so that I didn't have to spend time processing the video twice, but I couldn't do it because you can't use the -vf and -filter_complex commands together. How can this problem be solved?
First apply the video specific filters before using the result as overlay input.
ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v]eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t[vid];[vid][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4

can we use -vf and -filter:a with -filter_complex

I want to combine some videos with some specific features like(video Speed, volume increase, resolution, rotation, framerate) of the final output of the video
We can do this process in 2 steps like
Combine video
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] output.mp4
Then apply filters
ffmpeg -i output.mp4 -filter:a volume=1.0,atempo=1.0 -vf transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30 final.mp4
I can do it this way but is there any way to do it in 1 step
thank you
You have to apply the filters after concat.
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[v][a];[v]transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30[outv];[a]volume=1.0,atempo=1.0[outa] -map [outv] -map [outa] output.mp4

Combine multiple filter_complex and overlay functions with FFMpeg Commands

I am having trouble combining these 4 passes in ffmpeg into a single process.
First
exec("$this->ffmpeg -i ".storage_path('/app/public_html/uploads/job.mp4')." -codec:a libmp3lame -b:a 128k -vf scale=".$res_dimension->res_width."x".$res_dimension->res_height.",setsar=1:1 ".storage_path('2.mp4'));
Second
exec("$this->ffmpeg -i ".storage_path($original_file_path)." -codec:a libmp3lame -b:a 128k -vf scale=".$res_dimension->res_width."x".$res_dimension->res_height.",setsar=1:1 ".storage_path('3.mp4'));
Third
exec("$this->ffmpeg -i ".storage_path('3.mp4')." -i ".storage_path('/app/public_html/uploads/images/index2.png')." -filter_complex 'overlay=20:20' ".storage_path('4.mp4'));
Forth
exec("$this->ffmpeg -i ".storage_path('2.mp4')." -i ".storage_path('3.mp4')." -filter_complex '[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]' ".storage_path('out4.mp4'));
Your undefined variables make it difficult to understand what you want. The ffmpeg commands as actually being executed would have been easier to follow. But as far as I can tell you want to do something like this:
ffmpeg -i input0.mp4 -i input1.mp4 -i image.png -filter_complex "[0:v]scale=1280:720,setsar=1[v0];[1:v]scale=1280:720,setsar=1[bg];[bg][2]overlay=20:20[v1];[v0][0:a][v1][1:a]concat=n=2:v=1:a=1" output.mp4

ffmpeg - executing 2 or more command in one time

I have 2 ffmpeg commands, I execute them respectively, they work, but I want to execute them in one time and one command. How to do that?
ffmpeg -i 1.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-20:20" -codec:a copy 2.mp4
ffmpeg -i 2.mp4 -i picture.png -filter_complex "overlay=10:10" -codec:a copy 3.mp4
Use:
ffmpeg -i 1.mp4 -i logo.png -i picture.png -filter_complex "[0:v][1:v]overlay=main_w-overlay_w-20:20[bg];[bg][2:v]overlay=10:10[v]" -map "[v]" -map 0:a -c:a copy output.mp4
See the FFmpeg Filter Documentation for a description of the syntax.

ffmpeg concatenate videos and then merge with an audio

I have a few video files without any audio. I want to concatenate these videos to create a single video and then add a sound track (an mp3 file) to it. Currently I am doing it in two phases -
First concatenate videos...
ffmpeg -y -i video1.mp4 -i video2.mp4 -i video3.mp4 -filter_complex "[0:v:0] [1:v:0] [2:v:0] concat=n=3:v=1 [v]" -map "[v]" -c:v libx264 concat_video.mp4
and then add audio...
ffmpeg -y -i concat_video.mp4 -i sound_track.mp3 -shortest output.mp4
This produces fairly good output but it takes considerable amount of time.
I was wondering if there could be a single ffmpeg command that would do both and save time.
You just need to add your audio input and -map it:
ffmpeg -y -i video1.mp4 -i video2.mp4 -i video3.mp4 -i sound_track.mp3 -filter_complex "[0:v:0] [1:v:0] [2:v:0] concat=n=3:v=1:a=0 [v]" -map "[v]" -map 3:a -c:v libx264 -shortest output.mp4

Resources