Skip to content

Instantly share code, notes, and snippets.

@nathanleclaire
Created June 27, 2021 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanleclaire/5b7c87e9c991fda346193482eb021da2 to your computer and use it in GitHub Desktop.
Save nathanleclaire/5b7c87e9c991fda346193482eb021da2 to your computer and use it in GitHub Desktop.
Encode YouTube compatible video file of just one image with audio using ffmpeg

Trying to crank out a video which is:

  1. YouTube compatible
  2. Small-ish
  3. Preserves lossless audio
  4. Doesn't crash VLC, etc. (this happened embedding a FLAC direct in a WMV)
  5. Encodes as quickly as possible

So far, the best I've come up with is as follows:

ffmpeg -r 1 \
  -hwaccel cuda \
  -hwaccel_output_format cuda \
  -loop 1 \
  -i image.png \
  -i audio.wav \
  -c:v libx264 \
  -tune stillimage \
  -c:a copy \
  -shortest \
  out.avi

That runs in about 2 minutes 15 seconds and produces a file about 750Mb in size.

I've got an Nvidia GPU FWIW. Anyone got better ideas or implementation?

@nathanleclaire
Copy link
Author

MP4 doesn't like WAV. Can't remember if I tried MP4 with FLAC.

Here's the YouTube formats FWIW.

@nathanleclaire
Copy link
Author

.MOV speed approximately the same.

@nathanleclaire
Copy link
Author

Adding -crf 27 -preset veryfast helped a tiny bit. Decreased time by about 10 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment