Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from revolunet/ffmpeg-tips.md
Created December 14, 2015 08:25
Show Gist options
  • Save JT5D/a9b44f025bd852ef72fc to your computer and use it in GitHub Desktop.
Save JT5D/a9b44f025bd852ef72fc to your computer and use it in GitHub Desktop.
ffmpeg tips

convert to another format, resize withouth quality loss

ffmpeg -i vitrine.mp4 -vf scale=1024:-1 -q:vscale 0 vitrine.avi

concat video files

ffmpeg -f concat -i repeat.txt -c copy vitrine2.mp4

in repeat.txt:

file 'file1.avi'
file 'file2.avi'
file 'file3.avi'
file 'file4.avi'
...

Create high-quality animated gifs

-> http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

ffmpeg -i in.mov -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

Extract thumbnails

extract image every 5sec and resize to 90px width

ffmpeg -i input.mp4 -f image2 -vf "fps=fps=1/5, scale=90:-1" thumb-%04d.jpg

Join thumbs

join images to a single horizontal image

convert *.jpg +append out.jpg

Split image horizontally

create 11 equal-width thumbs from image

convert input.jpg -crop 11x1@ +repage +adjoin output-%04d.jpg

Create video sequence from thumbnails

create a 30fps mp4 with 3 frames per image (30/10). (vf fix image scale if incorrect)

ffmpeg -framerate 10 -i output-%04d.jpg -c:v libx264 -r 30 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pix_fmt yuv420p output.mp4

Produce m3u8 + ts files for HLS streaming (OSX)

in you get Unknown encoder 'libfdk_aac' on the mac, do this:

sudo brew unlink ffmpeg ; sudo brew reinstall ffmpeg --with-fdk-aac

or compile ffmpeg

Download the apple HLS tools from https://developer.apple.com/downloads/index.action?=http%20live%20streaming%20tools

this generates m3u8 + ts fragments for a given bitrate

ffmpeg -i input.mp4 -hls_time 30 -s 1024x768 -c:v libx264 -b:v 528k -b:a 128k -ar 44100 -ac 2 -c:a libfaac out/768.m3u8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment