Skip to content

Instantly share code, notes, and snippets.

@marcduiker
Last active April 7, 2024 19:35
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcduiker/abe8e4b7353b4c6430d556b727666620 to your computer and use it in GitHub Desktop.
Save marcduiker/abe8e4b7353b4c6430d556b727666620 to your computer and use it in GitHub Desktop.
FFmpeg command for creating video for Twitter

Convert pngs to mp4

This FFmpeg command reads images named frame_[4 char digit].png and converts it to an mp4 using the h264 encoding which Twitter accepts. The bitrate is set to 5M to reduce blocking as much as possible while keeping the size small.

ffmpeg -framerate 10 -i frame_%04d.png -c:v h264_qsv -b:v 5M video.mp4

Convert and scale an existing mp4 to 1080:

ffmpeg -i input.mp4 -c:v h264_qsv -vf: scale=1080:-1 -b:v 5M output.mp4

Convert infinite looping gif to limited looping mp4 (no scaling)

ffmpeg -i input.gif -c:v h264_qsv -filter_complex loop=loop=<NrOfLoops>:size=<TotalFrames>:start=<FramesToSkip> -b:v 5M output.mp4

Extract a frame from a video

ffmpeg -i input.mp4 -vf "select=eq(n\,65)" -vframes 1 output.png

@khlorghaal
Copy link

if it complains about MFX error, remove _qsv from h264
twitter still wont accept it though, i think bframes need sanitized somehow especially if converting from webm

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