1

i'm using the following ffmpeg command to generate a (15s) video from a single image

ffmpeg -loop 1 -i image.png -c:v libx264 -t 15 -pix_fmt yuv420p -vf scale=1280:720 out.mp4

The second command takes the/a video and adds multiple video overlays.

ffmpeg -i movie.m4v -vf "movie=movie.m4v, scale=140:-1[inner]; movie=movie.m4v, scale=100:-1[inner2]; [in][inner] overlay=70:70 [step1]; [step1][inner2] overlay=300:70 [out]" out.mp4

Does anybody know how to combine these two lines into one single command?

1 Answer 1

5

Video only

You can use one filtergraph for all filtering.

ffmpeg -loop 1 -i image0.png -i video1.m4v -i video2.m4v -filter_complex \
"[0:v]scale=1280:-2[bg]; \
 [1:v]scale=140:-1,setpts=PTS-STARTPTS[fg1]; \
 [2:v]scale=100:-1,setpts=PTS-STARTPTS[fg2]; \
 [bg][fg1]overlay=70:70:shortest=1[ol]; \
 [ol][fg2]overlay=300:70,format=yuv420p[v]" \
-map "[v]" -movflags +faststart output.mp4
  • The movie multimedia source filter is not required.

  • setpts will reset the timestamp so it works better with overlay.

  • Note the shortest=1 in one of the overlay filters. Otherwise the image input will loop forever. Alternatively you could use the trim filter on the image input.

  • The "end of file" action of overlay can be changed with eof_action.

  • The format filter will set compatible chroma subsampling for QuickTime and other crappy players.

  • When encoding is finished -movflags +faststart will relocate some data to the beginning of the file. This is useful, for example, if you are outputting to MP4 and your viewers will watch via progressive download such as from a browser.

With audio

Assuming both videos have stereo audio and you wanted to combine audio from each video into a single stereo output.

Example 1

enter image description here

This example will place both input left channels into the output left channel, and both input right channels into the output right channel.

ffmpeg -loop 1 -i image0.png -i video1.m4v -i video2.m4v -filter_complex \
"[0:v]scale=1280:-2[bg]; \
 [1:v]scale=140:-1,setpts=PTS-STARTPTS[fg1]; \
 [2:v]scale=100:-1,setpts=PTS-STARTPTS[fg2]; \
 [bg][fg1]overlay=70:70:shortest=1[ol]; \
 [ol][fg2]overlay=300:70,format=yuv420p[v]; \
 [1:a][2:a]amerge[a]" \
-map "[v]" -map "[a]" -ac 2 -movflags +faststart output.mp4

Example 2

enter image description here

This example will place both channels from the first input into the left channel of the output, and both channels from the second input into the right channel of the output.

ffmpeg -loop 1 -i image0.png -i video1.m4v -i video2.m4v -filter_complex \
"[0:v]scale=1280:-2[bg]; \
 [1:v]scale=140:-1,setpts=PTS-STARTPTS[fg1]; \
 [2:v]scale=100:-1,setpts=PTS-STARTPTS[fg2]; \
 [bg][fg1]overlay=70:70:shortest=1[ol]; \
 [ol][fg2]overlay=300:70,format=yuv420p[v]; \
 [1:a][2:a]amerge,pan=stereo|c0<c0+c2|c1<c1+c3[a]" \
-map "[v]" -map "[a]" -movflags +faststart output.mp4

Example 3

If you just want the audio from one input, then just add a -map option to the video example above (no need for amerge and pan):

-map 1:a -c:a copy

Also see

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .