useful ffmpeg commands

Getting infos from a video file

ffmpeg -i video.avi

Basic Convert

ffmpeg -i video_origine.extension video_finale.extension

Turn X images to a video sequence

ffmpeg -f image2 -i image%d.jpg video.mpg

Turn a video to X images

ffmpeg -i video.mpg image%d.jpg

Encode a video sequence for the iPpod/iPhone

ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320×180 -title X final_video.mp4

Explanations :
Source : source_video.avi
Audio codec : aac
Audio bitrate : 128kb/s
Video codec : mpeg4
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4

Extracting sound from a video, and save it as Mp3

ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 sound.mp3

Explanations :
Source video : source_video.avi
Audio bitrate : 192kb/s
output format : mp3
Generated sound : sound.mp3

Convert a wav file to Mp3

ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 son_final.mp3

Mix a video with a sound file

ffmpeg -i son.wav -i video_origine.avi video_finale.mpg

ref: http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs


Basic Syntax

ffmpeg -i input output

ffmpeg -i audio.mp3 audio.wav
ffmpeg -i video.mp4 video.mkv
ffmpeg -i video.mp4 audio.wav

Specifying Video and Audio codecs

ffmpeg -codecs
ffmpeg -formats

ffmpeg -i input.wav -c:a libfaac output.mp4
ffmpeg -i input.avi -c:v libx264 -c:a libfaac output.mkv

When to copy, when to encode?
The following command is wrong: It will re-encode your video

ffmpeg -i input.mp4 output.mkv

This command however does it right:

ffmpeg -i input.mp4 -c:v copy -c:a copy output.mkv

If changing the container without encoding does not work for you, you can try the mkvmerge

mkvmerge input.avi -o output.mkv

ref: http://blog.superuser.com/2012/02/24/ffmpeg-the-ultimate-video-and-audio-manipulation-tool/


join ts files
Create a file mylist.txt with all the files you want to have concatenated in the following form (lines starting with a # are ignored):

# this is a comment
file ‘/path/to/file1’
file ‘/path/to/file2’
file ‘/path/to/file3’

Note that these can be either relative or absolute paths. Then you can stream copy or re-encode your files:

ffmpeg -f concat -i mylist.txt -c copy output.extension

or

ffmpeg -f concat -i mylist.txt output.extension

ref: https://trac.ffmpeg.org/wiki/Concatenate