1

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 Answers1

1

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
llogan
  • 87,794
  • 21
  • 166
  • 190
pszemus
  • 106
  • 6
  • 1
    Don't forget to add the `-shortest` output option or else it will loop forever. YouTube will accept just about any colorspace/chroma subsampling, so no need to add `-pix_fmt yuv420p` for YouTube. Recommend adding the [`-map`](https://trac.ffmpeg.org/wiki/Map) output option so the default behavior doesn't choose the wrong streams: `-map 0 -map 1:a`. – llogan Feb 22 '21 at 18:51
  • 1
    Yeah, it was definitely looping forever. Note that you have to put `-shortest` before the output path. Thanks @pszemus and @llogan. – cornerstore Feb 22 '21 at 19:27
  • @cornerstore can you mark it as an accepted answer then? – pszemus Feb 23 '21 at 15:26