Sometimes I have a video in which I like to discard the video sequence for five seconds between second 11 and second 16 (as an example) and instead incorporate an image from a jpg file that is displayed during that time and leaving the audio sequence intact.

Would be great if someone told me an apt command line for this.

Thanks in advance :)

UPDATE 20200906: The solution should not re-encode the entire video in order to rapidly process large video files with a short image-overlay.

  • You apparently have additional requirements: that the operation complete in just a few seconds, and that the operation does not reencode the entire video sequence. You are more likely to get relevant answers if you include those requirements in your question. Note that these requirements may mean there is no easy way to satisfy them using ffmpeg. Jul 24, 2020 at 19:58
  • Yes, your're right. At the time I started the thread I did not already realize that not having to re-encode the full video is of great importance to the topic. But I am not editing my original post in order not to render Gyan's reply inappropriate.
    – vyasa
    Jul 24, 2020 at 22:16
  • People do clarify their questions here, and it does sometimes undermine an answer. That's still better than leaving the question incomplete. A helpful convention is to edit the question, and put an update summary note at the bottom, e.g.: "UPDATED 2020-07-25 to make it clear that solution should not re-encode the entire video". Then readers can compare the date on the update note with the date on the answers to see if the answer matches the question. Sometimes an update to the question leads an answerer to update their answer accordingly. Jul 25, 2020 at 19:41

2 Answers 2



ffmpeg -i video -i image -filter_complex "[1][0]scale2ref[img][vid];[vid][img]overlay=enable='between(t,11,16)'" -c:a copy out.mp4

Scale2ref resizes the image to the resolution of the video. The overlay places the image on top of the video from the 12th to the end of the 16th second.

  • Update: This doesn't work as expected because not only the portion where the image is overlayed is reencoded but the whole of the video file. Especially for large input files with several GBs, this takes hours to complete, even when an image is overlayed for just a few seconds.
    – vyasa
    Jul 22, 2020 at 16:33
  • Avoiding a full re-encode requires some time-consuming and error-prone steps viz. segmenting the input video at keyframes, identifying the affected segments, overlaying the image and re-encoding these segments with parameters that match the original. Not trivial.
    – Gyan
    Jul 22, 2020 at 18:36

Just an idea, but how about: splitting the video in three parts (pre, needed-part, post)

then applying the idea posted to the "needed-part".

Afterwards concatenate the three files together again ?

PS: Using the command above kinda destroys my videos picture quality... no idea why...

  • You got it right. Use -c copy to keep the quality intact. Oct 3, 2021 at 1:37

You must log in to answer this question.

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