ffmpeg - executing 2 or more command in one time - ffmpeg

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.

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

ffmpeg combining multiple commands into one

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

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

combine two -filter_complex command together

Below, I have two ffmpeg commands (1, 2) to be combined into (3).
add sounds from 1.mp3 and 1.3gp into muted 1.mp4
code works without error:
ffmpeg -i 1.mp3 -i 1.3gp -i 1.mp4 \
-filter_complex "[1]adelay=640|640[s1];[0][s1]amix=2[mixout];" \
-map 2:v -map [mixout] -c:v copy result.mp4
add watermark to top-right of 1.mp4
code works without error:
ffmpeg -i 1.mp4 -i logo.png \
-filter_complex "overlay=x=main_w-overlay_w:y=1" \
result.mp4
combine above two commands into one
My code fails
ffmpeg -i 1.mp3 -i 1.3gp -i 1.mp4 -i logo.png \
-filter_complex "[1]adelay=640|640[s1];[0][s1]amix=2[mixout];[2:v][3]overlay=x=main_w-overlay_w:y=1[outv]" \
-map [outv] -map [mixout] -c:v copy result.mp4
What am I doing wrong here?
Use
ffmpeg -i 1.mp3 -i 1.3gp -i 1.mp4 -i logo.png \
-filter_complex "[1]adelay=640|640[s1];[0][s1]amix=2[mixout];
[2:v][3]overlay=x=main_w-overlay_w:y=1[outv]" \
-map [outv] -map [mixout] result.mp4
If you're filtering the video stream e.g. adding an overlay, then you can't copy that video stream.

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