Skip to content

Instantly share code, notes, and snippets.

@basbl
Created January 6, 2015 09:54
Show Gist options
  • Save basbl/b4280f0223309a039a6d to your computer and use it in GitHub Desktop.
Save basbl/b4280f0223309a039a6d to your computer and use it in GitHub Desktop.
FFmpeg various commands

MAKE SURE THAT YOU HAVE A RECENT VERSION, DIST BUILDS ARE OFTEN ANCIENT. https://trac.ffmpeg.org/wiki/CompilationGuide

Commands tested in ffmpeg version 2.4.git Copyright (c) 2000-2014

Stitching together multiple video's:

First convert your mp4's to .ts files (needed only once):

$ ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts

Last but not least, concat them:

$ ffmpeg -i concat:video1.ts|video2.ts -c:v copy -async 1 -movflags faststart output.mp4

Using this method a video made up of ~20 videos (2:30 worth of video) takes 3 seconds (mostly because of the sound encoding, the joining of the files themselves takes 1 second).

This also is easily doable on 1 thread, so add the flag "-thread 1" to force ffmpeg to use only 1 thread. Now you can run as many parallel render jobs as you have threads.

Make audio suitable for inclusion in an .mp4 video:

$ ffmpeg -i 2.mp3 -c:a libfdk_aac -b:a 128k 2.m4a

Stitching together images (frames) to create a video (no audio):

$ ffmpeg -r 25 -f image2 -i /path/to/frames/frame%d.bmp -c:v libx264 -pix_fmt yuv420p output.mp4

Create a video from a single image (-t is duration in seconds):

$ ffmpeg -loop 1 -i /path/to/image/image.jpg -c:v libx264 -r 25 -t 10 -pix_fmt yuv420p output.mp4

Scale a video to 1280x720 (add black borders only when needed):

$ ffmpeg -i /path/to/input.mp4 -vf scale=iw*min(1280/iw\,720/ih):ih*min(1280/iw\,720/ih), pad=1280:720:(1280-iw*min(1280/iw\,720/ih))/2:(720-ih*min(1280/iw\,720/ih))/2 -pix_fmt yuv420p output.mp4

Extract (amount of seconds) video to frames -ss is start, -to is end):

$ ffmpeg -i /path/to/input.mp4 -ss 00:00:00 -to 00:00:10 -f image2 /path/to/output/image-%d.jpg

* add the -an option to strip audio from your output.

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