I am trying to produce video containing static image and smaller video which would be overlaid on top of it. Dimensions and position of overlay video are dynamically sent to the server script which runs FFMPEG, so I need to scale video before overlaying it. So, numeric values I used are just for test. Original video has dimensions 72:48px. I tried command like this:

ffmpeg -i background.jpg -vf "movie=overlay.mp4, scale=128:96 [inner]; [in][inner] overlay=70:70 [out]" -y output.mp4

However, it just instantly produces an empty video. If, on the other hand, I try inserting -loop 1 right after ffmpeg command, the processing of video seems to take endless time and it never finishes.

What I am trying to achieve is to avoid creating scaled video first. Is it possible and what am I doing wrong?



ffmpeg -loop 1 -i background.jpg \
       -vf "movie=overlay.mp4,scale=128:96[inner];[in][inner]overlay=70:70:shortest=1[out]" \
       -y output.mp4

The image needs to be looped, but that will create an unending stream, so the shortest argument in the overlay filter stops the filter when the movie ends.

With the overlay's audio included

ffmpeg -loop 1 -i background.jpg -i overlay.mp4 \
       -filter_complex "[1]scale=128:96[inner];[0][inner]overlay=70:70:shortest=1[out]" \
       -map "[out]" -map 1:a -c:a copy -y output.mp4
  • Thanks, this works perfect except that there is no audio in output file. I need the output video to use audio stream from overlay.mp4. If I try to append -c:a copy after image path, or after video path as well, it throws an error. What is proper way? – cincplug Apr 26 '16 at 9:28
  • This should perhaps be another question, but since it inherits the code, I put it here first: how do I concatenate another video (using own audio stream) after output.mp4 which is produced as described above? I managed to do that separately like: ffmpeg -f concat -i concatlist.txt -c copy finaloutput.mp4, but I need to remain in scope of one ffmpeg directive, because it runs on remote server and second directive starts before the first finishes. Concatenated video has same size, codec, and frame rate as output.mp4. I struggle with concat filter all day with no good results :) – cincplug Apr 27 '16 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.