FFmpeg is a set of libraries and programs to convert and stream multimedia.
Install FFmpeg
In Debian:
$ sudo aptitude install ffmpegShow help
$ ffmpeg -h$ man ffmpegShow all options in help:
$ ffmpeg -h fullShow all available codecs
$ ffmpeg -codecsCodecs:
D..... = Decoding supported
.E.... = Encoding supported
..V... = Video codec
..A... = Audio codec
..S... = Subtitle codec
...I.. = Intra frame-only codec
....L. = Lossy compression
.....S = Lossless compression
-------
D.VI.. 012v Uncompressed 4:2:2 10-bit
D.V.L. 4xm 4X Movie
D.VI.S 8bps QuickTime 8BPS video
.EVIL. a64_multi Multicolor charset for Commodore 64 (encoders: a64multi )
.EVIL. a64_multi5 Multicolor charset for Commodore 64, extended with 5th color (colram) (encoders: a64multi5 )
D.V..S aasc Autodesk RLE
...
Show supported file formats
Display file formats and devices:
$ ffmpeg -formatsFile formats:
D. = Demuxing supported
.E = Muxing supported
--
E 3g2 3GP2 (3GPP2 file format)
E 3gp 3GP (3GPP file format)
D 4xm 4X Technologies
E a64 a64 - video for Commodore 64
D aa Audible AA format files
D aac raw ADTS AAC (Advanced Audio Coding)
DE ac3 raw AC-3
D act ACT Voice file format
...
DE avi AVI (Audio Video Interleaved)
...
DE flv FLV (Flash Video)
...
E webm WebM
...
E xv XV (XVideo) output device
Show devices
Display input and output devices:
$ffmpeg -devicesDevices:
D. = Demuxing supported
.E = Muxing supported
--
DE alsa ALSA audio output
E caca caca (color ASCII art) output device
D dv1394 DV1394 A/V grab
DE fbdev Linux framebuffer
...
D openal OpenAL audio capture device
E opengl OpenGL output
DE oss OSS (Open Sound System) playback
DE pulse Pulse audio output
E sdl SDL output device
E v4l2 Video4Linux2 output device
D video4linux2,v4l2 Video4Linux2 device grab
D x11grab X11 screen capture, using XCB
E xv XV (XVideo) output device
Play a file
E.g: Play media_file.avi
$ ffplay media_file.aviKeystrokes enabled while playing:
q,ESC quit
f toggle full screen
p,SPC pause
a cycle audio channel in the current program
v cycle video channel
t cycle subtitle channel in the current program
c cycle program
w cycle video filters or show modes
s activate frame-step mode
left/right seek backward/forward 10 seconds
down/up seek backward/forward 1 minute
page down/page up seek backward/forward 10 minutes
mouse click seek to percentage in file corresponding to fraction of width
Get info from a multimedia file
ffprobe analyzes multimedia streams and outputs information in human- and machine-readable formats, including the container format and the format and type of each stream.
$ ffprobe some_film.mkvInteresting FFmpeg commands
Resize video
$ ffmpeg -i some_film.mkv -s 960x540 -c:a copy resized_film.mkvThis command copies the audio of film.mkv, resizes video to 960x540 size and outputs the result to resized_film.mkv.
Resize video and encode it using mpeg4 codec
$ ffmpeg -i some_film.mkv -s 960x540 -c:a copy -c:v mpeg4 resized_film.mkvConvert an audio file to mp3 format
$ ffmpeg -formats | grep mp3 # check if mp3 format is available$ ffmpeg -i input_file.wav -f mp3 output_file.mp3Trim a video file
Trim a file starting at 4 minutes 41 seconds point and finish after a duration of 54 minutes and 12 seconds:
$ ffmpeg -ss 4:41 -t 54:12 -i input_file.mkv -c:a copy -c:v copy trimmed_film.mkv-ss start_position and -t duration options come before -i one in this case.
Extract subtitles from a video file and save them in SRT format
Extract subtitles from a video file and store them in SRT format.
$ ffmpeg -i input_file.mkv -map 0:s:1 output_subtitle_file.srt-map 0:s:1 selects the second subtitle stream (1) from the first input file (0).
ffmpeg automatically determines the output subtitle format from the file extension (.srt).
Alternatively, the output codec can be specified explicitly:
$ ffmpeg -i input_file.mkv -map 0:s:1 -c:s srt output_subtitle_file.srtDelay or advance subtitles in a SRT file
Advance the subtitles by one second and save them in the same SRT format.
$ ffmpeg -itsoffset -1 -i input_file.srt -c copy output_file.srt-itsoffset -1 advances subtitles by one second relative to the audio. A positive number delays the subtitles by the specified number of seconds.
-c copy selects the “copy” encoder (stream copy), which means no decoding or encoding takes place.
Reference
FFmpeg (Wikipedia)
$ man ffmpeg$ man ffmpeg-devices$ man ffmpeg-utils