[FFmpeg-user] Help needed with command

Arjun Kaneria arjunk.w3nuts at gmail.com
Thu May 2 13:54:41 EEST 2024


I have a video editor app, so videos can be of any dimension and at any
position in the scene. I want to apply a transition between 2 videos which
are placed side by side in the timeline with one starting immediately after
another but those 2 videos can be of any dimension and at any position with
crop and rotation options. I have successfully managed to produce an export
command using overlay filter which combines videos at any given time at any
position transparently. For transition I and trying to replace overlay with
xfade. The xfade filter requires 2 videos to have the same fps, and the
same dimensions to combine and apply various transition effects.

The initial command with overlay.
C:\ffmpeg-6.0-full_build\bin\ffmpeg.exe -y -threads 12 -loop 1 -i
C:\background.png -i C:\1526909-sd_960_540_24fps.mp4 -i
C:\1409899-sd_960_540_25fps.mp4 -i C:\2169880-sd_960_540_30fps.mp4
-filter_complex "\
[0]setpts=PTS/1-STARTPTS+0/TB,scale=966:544,setsar=1:1,setdar=dar=16/9,format=yuva420p[s0];\
[1]trim=start=0:end=5,setpts=PTS/1-STARTPTS+0/TB,format=pix_fmts=yuva420p,crop=w=320:h=539.99956497196:x=320:y=0.00021751402186965,scale=322:544,setsar=1:1,setdar=dar=16/9[s1];\
[s0][s1]overlay=x=0:y=0:enable='between(t,'0','5')'[out_1];\
[2]trim=start=0:end=5,setpts=PTS/1-STARTPTS+5/TB,format=pix_fmts=yuva420p,crop=w=320:h=539.99956497196:x=320:y=0.00021751402186965,scale=322:544,setsar=1:1,setdar=dar=16/9[s2];\
[out_1][s2]overlay=x=322:y=0:enable='between(t,'5','10')'[out_2];\
[3]trim=start=0:end=5,setpts=PTS/1-STARTPTS+10/TB,format=pix_fmts=yuva420p,crop=w=320:h=539.99956497196:x=320:y=0.00021751402186965,scale=322:544,setsar=1:1,setdar=dar=16/9[s3];\
[out_2][s3]overlay=x=643:y=0:enable='between(t,'10','15')'[out_3];\
[3]atrim=start=0:end=5,atempo=1,asetpts=PTS-STARTPTS[vao_3];\
[vao_3]adelay=10000|10000[va3]\
" -map [out_3] -map [va3] -vcodec libx264 -acodec libmp3lame -b:a 128k -t
15 C:\output.mp4

My attempt with xfade filter
C:\ffmpeg-6.0-full_build\bin\ffmpeg.exe -y -threads 12 -loop 1 -i
C:\background.png -i C:\1526909-sd_960_540_24fps.mp4 -i
C:\1409899-sd_960_540_25fps.mp4 -i C:\2169880-sd_960_540_30fps.mp4
-filter_complex "\
[0]fps=24,setpts=PTS/1-STARTPTS+0/TB,scale=966:544,setsar=1:1,setdar=dar=16/9,format=yuva420p[s0];\
[1]fps=24,trim=start=0:end=5,setpts=PTS/1-STARTPTS+0/TB,format=pix_fmts=yuva420p,crop=w=320:h=540:x=320:y=0:exact=1,scale=322:544,setsar=1:1,setdar=dar=16/9[s1];\
[s0][s1]overlay=x=0:y=0:enable='between(t,'0','5')'[out_1];\
[2]fps=24,trim=start=0:end=5,setpts=PTS/1-STARTPTS+4/TB,format=pix_fmts=yuva420p,crop=w=320:h=540:x=320:y=0:exact=1,scale=322:544:force_original_aspect_ratio=decrease,pad=966:544:322:0:color=0xff000000,setsar=1:1,setdar=dar=16/9[s2];\
[out_1][s2]xfade=transition=fadeblack:duration=1:offset=4[out_2];\
[3]fps=24,trim=start=0:end=5,setpts=PTS/1-STARTPTS+8/TB,format=pix_fmts=yuva420p,crop=w=320:h=540:x=320:y=0:exact=1,scale=322:544:force_original_aspect_ratio=decrease,pad=966:544:643:0:color=0xff000000,setsar=1:1,setdar=dar=16/9[s3];\
[out_2][s3]xfade=transition=fadewhite:duration=1:offset=8[out_3];\
[3]atrim=start=0:end=5,atempo=1,asetpts=PTS-STARTPTS[vao_3];\
[vao_3]adelay=8000|8000[va3]\
" -map [out_3] -map [va3] -vcodec vp9 -acodec libmp3lame -b:a 128k -t 13
C:\output.mp4

But with this command, I am not able to generate the transparent padded
area and the transition effect applies to the whole area, whereas I want it
to apply to only the 2 videos area.

Any possible help or suggestion is appreciated.


Thanks,


More information about the ffmpeg-user mailing list