Skip to content

Instantly share code, notes, and snippets.

@alfg
Forked from gildotdev/ffmpeg.txt
Created October 30, 2017 00:31
Show Gist options
  • Save alfg/d1483d80d69d525a834854d95be04a00 to your computer and use it in GitHub Desktop.
Save alfg/d1483d80d69d525a834854d95be04a00 to your computer and use it in GitHub Desktop.
ffmpeg cli commands
## extract audio from .avi as .aac (conversion from another audio codec)
ffmpeg -i foo.avi -acodec aac -ab 128k -strict experimental bar.aac
## extract audio from .avi as .mp3 (no conversion, just copy)
ffmpeg -i foo.avi -acodec copy bar.mp3
## convert .mp3 to .aac
ffmpeg -i foo.mp3 -acodec aac -ab 128k -strict experimental bar.aac
## extract single frame as image from .mp4
ffmpeg -i foo.mp4 -ss 0 -vframes 1 -vcodec mjpeg -f image2 bar.jpg
## convert movie to image sequence
ffmpeg -i foo.mp4 bar%d.png
## convert .mp4 to .flv
ffmpeg -i foo.mp4 -ab 64k -ar 44100 -f flv bar.flv
## convert folder full of .m4a to .mp3
for f in *.m4a; do ffmpeg -i "$f" -acodec mp3 -ab 256k "${f%.m4a}.mp3"; done
## convert .flv to .mp4
## assuming a/v codecs in the flv are what you want (i.e. h264 and aac)
ffmpeg -i foo.flv -vcodec copy -acodec copy bar.mp4
## convert .flv to .mp4 (with aac audio)
## assuming video codec in the flv is what you want (i.e. h264)
ffmpeg -i foo.flv -vcodec copy -acodec aac -aq 200 bar.mp4
## add subtitles to mp4 from srt
ffmpeg -i original.mp4 -f srt -i subtitle.srt -c:v copy -c:a copy -c:s mov_text new.mp4
## convert first audio track to 2 channel aac and copy first audio track to second audio track
ffmpeg -i original.mkv -map 0:0 -map 0:1 -map 0:1 -c:v copy -c:a:0 libfaac -b:a:0 192k -ac 2 -c:a:1 copy new.mp4
## create animated gif
ffmpeg -i original.mp4 -s wxh -pix_fmt rgb24 -r 24 -f gif - | gifsicle --optimize=3 --delay=3 > new.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment