How to replace the video track in a video file with a still image?

Viewed 154

I am trying to use ffmpeg to replace the video track in a video file with a still image. I tried some commands I got from other questions such as the one here

ffmpeg -i x.png -i orig.mp4 final.mp4

ffmpeg -r 1/5 -i x.png -r 30 -i orig.mp4 final.mp4

But these didn't work. I'm not sure which of these arguments are required or not. The output should be accepted by YouTube as a valid video - I was able to simply remove the video track, but apparently they don't let you upload a video without a video track.

1 Answers

You can try looping the still image like this:

ffmpeg -loop 1 -i x.png -i orig.mp4 final.mp4

Then you can tweak the encoding process by introducing the following quality parameters:

ffmpeg -loop 1 -i x.png -i orig.mp4 -crf 22 -preset slow final.mp4

they are described here.

If your colorspace gets rejected by YouTube you can try adding: -pix_fmt yuv420p.

Solution: A final solution is something like this:

  • Where -t 30 is an example duration of 30 seconds.
  • Using -c:a copy will directly copy the original audio without a new re-encoding (is faster).

ffmpeg -loop 1 -i x.png -i orig.mp4 -map 0 -map 1:a -c:v libx264 -pix_fmt yuv420p -crf 22 -preset slow -c:a copy -shortest final.mp4
Related