Triming, xfade and concat videos from timeline with FFMPEG
I’m trying to build a command to output a video with some data provided with a json, sort of timeline.
In my example, I have 3 videos:
video1.mp4 (43s), video2.mp4 (28s), video3.mp4 (16s)
I’m trying to trim and set the same configuration to all videos, and I want to add transitions with (2s), “wiperight” from video1 to video2, and “wipeup” from video2 to video3.
And then concatenate all into one video.
I started with simple set configs + trim + concatenate:
ffmpeg -i video1.mp4 \
-i video2.mp4 \
-i video3.mp4 \
-filter_complex \
"[0:v]trim=start=0:end=7,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=24,format=yuv420p[v0]; \
[1:v]trim=start=0:end=10,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=24,format=yuv420p[v1]; \
[2:v]trim=start=0:end=7,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=24,format=yuv420p[v2]; \
[0:a]atrim=start=0:end=7,asetpts=PTS-STARTPTS[a0]; \
[1:a]atrim=start=0:end=10,asetpts=PTS-STARTPTS[a1]; \
[2:a]atrim=start=0:end=7,asetpts=PTS-STARTPTS[a2]; \
[v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart output.mp4
But now I can’t seem to add the transitions:
ffmpeg -i video1.mp4 \
-i video2.mp4 \
-i video3.mp4 \
-filter_complex \
"[0:v]trim=start=0:end=7,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=24[v0]; \
[1:v]trim=start=0:end=10,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=24[v1]; \
[2:v]trim=start=0:end=7,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=24[v2]; \
[0:a]atrim=start=0:end=7,asetpts=PTS-STARTPTS[a0]; \
[1:a]atrim=start=0:end=10,asetpts=PTS-STARTPTS[a1]; \
[2:a]atrim=start=0:end=7,asetpts=PTS-STARTPTS[a2]; \
[v0]xfade=transition=wiperight:duration=2:offset=5[fade0]; \
[v1]xfade=transition=wipeup:duration=2:offset=8[fade1]; \
[fade0][a0][fade1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -pix_fmt yuv420p -c:v libx264 -c:a aac -movflags +faststart concatenado_transicoes.mp4
Error on terminal: “Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_xfade_24”
I tried more different variations, the best I got was to actually build the file transitions.mp4, I can open and I can ear sound, but no image.
Thank you for your help,
Jorge
Read more here: Source link
