FFmpeg commands


FFmpeg is a set of libraries and programs to convert and stream multimedia.


Install FFmpeg


In Debian:
$ sudo aptitude install ffmpeg


Show help


$ ffmpeg -h

$ man ffmpeg

Show all options in help:
$ ffmpeg -h full


Show all available codecs


$ ffmpeg -codecs
Codecs:
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 -formats
File 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 -devices
Devices:
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.avi

Keystrokes 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




Interesting FFmpeg commands


Resize video

$ ffmpeg -i some_film.mkv -s 960x540 -c:a copy resized_film.mkv
This 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.mkv


Convert 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.mp3


Trim 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.



Reference


FFmpeg (Wikipedia)

$ man ffmpeg
$ man ffmpeg-devices
$ man ffmpeg-utils