Skip to content

Instantly share code, notes, and snippets.

@andyeff
Forked from ndarville/webm.md
Last active July 20, 2023 08:40
Show Gist options
  • Save andyeff/d1d8281588111813b43aea7d8052be96 to your computer and use it in GitHub Desktop.
Save andyeff/d1d8281588111813b43aea7d8052be96 to your computer and use it in GitHub Desktop.
GIF to WebM with ffmpeg

Grab ffmpeg from https://www.ffmpeg.org/download.html

The most trivial operation would be converting gifs:

ffmpeg -i your_gif.gif -c:v libvpx-vp9 -crf 12 -b:v 500K output.webm

  • -crf values can go from 4 to 63. Lower values mean better quality.
  • -b:v is the maximum allowed bitrate. Higher means better quality.

To convert a part of a video file:

ffmpeg -i your_video.mkv -ss 00:00:10.000 -to 00:00:20.000 -c:v libvpx -crf 4 -b:v 1500K -vf scale=640:-1 -an output.webm
  • -ss is the start position in number of seconds, or in hh:mm:ss[.xxx] format. You can get it using your video player (Ctrl-G in MPC-HC).
  • -to is the end position.
  • -vf scale=640:-1 sets the width to 640px. The height will be calculated automatically according to the aspect ratio of the input.
  • -an disables audio. 4chan will reject your files if they contain audio streams.


@joecool1029
Copy link

Just a tip since I hit this on a search, the first command may fail with the error:

Transparency encoding with auto_alt_ref does not work

This can be fixed by updating the command to use libvpx-vp9:

ffmpeg -i your_gif.gif -c:v libvpx-vp9 -crf 12 -b:v 500K output.webm

@andyeff
Copy link
Author

andyeff commented Jul 20, 2023

Ah, thanks for the tip! Edited the op.

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