FFmpeg Commands in Linux with Examples
FFmpeg Commands for Video, Audio and Image Conversion in Linux
In this article we will learn useful FFmpeg multimedia framework to perform various conversion procedures on audio and video files. FFmpeg utility supports almost all major audio and video formats. Now lets see some commands that give you an idea about the tool.
To Get Video File Information
By running the following command, you can get information about a file.
[user1@linuxhelp Desktop]$ ffmpeg -i bees.mp4
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --en
.
.
.
description :
title : Untitled
Duration: 00:00:16.13, start: 0.000000, bitrate: 2733 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x360 [PAR 1:1 DAR 16:9], 2657 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc
Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 77 kb/s
At least one output file must be specified
To Split a video into images
By running the following command, you can turn a video to number of images.
[user1@linuxhelp video_to_image]$ ffmpeg -i /home/user1/Desktop/bees.mp4 image%d.jpg
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-
.
.
.
Output #0, image2, to ' image%d.jpg' :
Metadata:
encoder : Lavf52.64.2
Stream #0.0(eng): Video: mjpeg, yuvj420p, 640x360 [PAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
[h264 @ 0x1bbeb10]non-existing SPS 32 referenced in buffering period
frame= 483 fps=276 q=24.8 Lsize= -0kB time=16.10 bitrate= -0.0kbits/s
video:4911kB audio:0kB global headers:0kB muxing overhead -100.000437%
Here we can list the frames of images split from the video.
[user1@linuxhelp video_to_image]$ ll
total 5896
-rw-rw-r--. 1 user1 user1 9694 Mar 22 10:49 image100.jpg
-rw-rw-r--. 1 user1 user1 9764 Mar 22 10:49 image101.jpg
-rw-rw-r--. 1 user1 user1 9811 Mar 22 10:49 image102.jpg
-rw-rw-r--. 1 user1 user1 9837 Mar 22 10:49 image103.jpg
-rw-rw-r--. 1 user1 user1 9902 Mar 22 10:49 image104.jpg
-rw-rw-r--. 1 user1 user1 9906 Mar 22 10:49 image105.jpg
-rw-rw-r--. 1 user1 user1 9979 Mar 22 10:49 image106.jpg
-rw-rw-r--. 1 user1 user1 10035 Mar 22 10:49 image107.jpg
To Convert images into a video
By running the following command, you can convert number of images into a video sequence and transforms all the images from the current directory into a single video file.
[user1@linuxhelp video_to_image]$ ffmpeg -f image2 -i image%d.jpg imagestovideo.mpg
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --e
.
.
encoder : Lavf52.64.2
Stream #0.0: Video: mpeg1video, yuv420p, 640x360, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
frame= 483 fps=443 q=31.0 Lsize= 852kB time=19.28 bitrate= 362.0kbits/s
video:842kB audio:0kB global headers:0kB muxing overhead 1.186944%
To Convert a video into mp3 format
By running the following command, you can convert .flv format video file to .mp3 format
[user1@linuxhelp Desktop]$ ffmpeg -i bees.mp4 -vn -ar 44100 -ac 2 -ab 180 -f mp3 audiofile.mp3
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libx264 --.
.
Stream #0.0(eng): Audio: libmp3lame, 44100 Hz, stereo, s16, 0 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Press [q] to stop encoding
[aac @ 0x1e743a0]Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. If you heard an audible artifact, please submit the sample to the FFmpeg developers.
size= 253kB time=16.17 bitrate= 128.0kbits/s
video:0kB audio:253kB global headers:0kB muxing overhead 0.012755%
Definition of the commands:
vn: helps to mute video recording during the conversion.
ar: helps you set audio sampling rate in Hz.
ab: set the audio bitrate.
ac: to set the number of audio channels.
-f: format.
To Covert mp4 video file to flv format
By running the following command, you can convert .mp4 format to a .flv format
[user1@linuxhelp Desktop]$ ffmpeg -i bees.mp4 beesflv.flv
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enae-libfaad
.
.
.
coding
[h264 @ 0x1393b00]non-existing SPS 32 referenced in buffering period
Last message repeated 9 times
[aac @ 0x13943a0]Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. If you heard an audible artifact, please submit the sample to the FFmpeg developers.
Last message repeated 1 times
[h264 @ 0x1393b00]non-existing SPS 32 referenced in buffering period
frame= 483 fps=284 q=31.0 Lsize= 892kB time=16.10 bitrate= 453.7kbits/s
video:748kB audio:126kB global headers:0kB muxing overhead 2.002808%
To Convert mpg into flv
By running the following command, you can convert .mpg format to .flv file.
[user1@linuxhelp Desktop]$ ffmpeg -i bees.mpg -ab 28 -f flv bees.flv
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --
.
.
.
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 483 fps= 0 q=31.0 Lsize= 973kB time=16.10 bitrate= 495.2kbits/s
video:703kB audio:253kB global headers:0kB muxing overhead 1.833574%
To Convert avi video file to mpeg
By running the following command, you can convert .avi filt to .mpeg for DVD players.
[user1@linuxhelp Desktop]$ ffmpeg -i bees.avi -target pal-dvd -ps 1000000000 -aspect 16:9 bees.mpeg
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --ena
.
.
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 403 fps=146 q=2.0 Lsize= 12678kB time=16.08 bitrate=6458.8kbits/s dup=0 drop=80
video:11552kB audio:886kB global headers:0kB muxing overhead 1.932140%
Definition of the commands,
target pal-dvd : Output format
ps 1000000000 maximum size for the output file, in bits (here, 1 Gb).
aspect 16:9 : Widescreen.
You can set the target type as vcd, svcd, dvd, dv, pal-vcd or ntsc-svcd on the command line as per your requirement.
To convert .flv file to gif file
Using this command .flv file type can be converted to gif file.
[user1@linuxhelp Desktop]$ ffmpeg -i beesflv.flv animatedfile.gif.mp4
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --ena
.
.
. Audio: libfaac, 44100 Hz, 2 channels, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 483 fps=475 q=31.0 Lsize= 753kB time=16.10 bitrate= 383.3kbits/s
video:619kB audio:124kB global headers:0kB muxing overhead 1.415495%
To Mix a video and audio together
By running the following command, you can mix video with a sound file.
[user1@linuxhelp Desktop]$ ffmpeg -i audiofile.mp3 Ubuntu 15.10 Desktop installation.mp4 newfile.mpg
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=' -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --ena
.
.
.
Stream #0.0 -> #0.0
Stream #0.0 -> #1.0
Press [q] to stop encoding
size= 130kB time=16.11 bitrate= 66.0kbits/s
video:0kB audio:250kB global headers:0kB muxing overhead -48.083044%
To view/Test Video and Audio Quality
By running the following command, you can compare videos and audios after converting and this helps you to test the quality of the videos and audios.
To test video quality
[user1@linuxhelp Desktop]$ ffplay bees.flv
To test audio quality
[user1@linuxhelp Desktop]$ ffplay audio.mp3
FFmpeg -i movie.mpg movie%d.jpg
The movie.mpg used as input will be converted to movie1.jpg, movie2.jpg, etc...
Instead of relying on file format self-recognition, you may also use
-c:v ppm
-c:v png
-c:v mjpeg
to force the encoding.
Applying that to the previous example:
ffmpeg -i movie.mpg -f image2 -c:v mjpeg menu%d.jpg
Beware that there is no "jpeg" codec. Use "mjpeg" instead.