Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Last active June 19, 2019 15:02
Show Gist options
  • Save pmarreck/4d7decd61a5259e1985048d71409532f to your computer and use it in GitHub Desktop.
Save pmarreck/4d7decd61a5259e1985048d71409532f to your computer and use it in GitHub Desktop.
FFmpeg command to convert a png to a single-frame mp4 (with pretty stellar compression, especially compared to jpeg) BONUS: Full browser support!
# On OS X, with an ffmpeg installed via Homebrew, the following command works and results in a single-frame movie file that is compatible with Chrome, QuickTime and the latest iDevices:
ffmpeg -i FILENAME.png -an -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -subq 10 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -profile:v high -level 4.2 -pix_fmt yuv420p -vf “scale=trunc(iw/2)*2:trunc(ih/2)*2” -trellis 2 -partitions +parti8x8+parti4x4 -crf 24 -threads 0 -r 25 -g 25 -y FILENAME.mp4
@exadeci
Copy link

exadeci commented Jul 10, 2017

The double quotes are the wrong characters here's the line fixed:

ffmpeg -i FILENAME.png -an -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -subq 10 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -profile:v high -level 4.2 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -trellis 2 -partitions +parti8x8+parti4x4 -crf 24 -threads 0 -r 25 -g 25 -y FILENAME.mp4

It should be noted too that it's not a good solution for image compression because a browser will have performances issues if all the images of a page are mp4 and it will increase cpu usage.

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