• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

FFmpeg Commands in Linux with Examples

286

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

Tags:
liam
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

Why do I see a slight quality degradation with multithreaded MPEG* encoding?

A

For multithreaded MPEG* encoding, the encoded slices must be independent, otherwise, thread n would practically have to wait for n-1 to finish, so it’s quite logical that there is a small reduction of quality. This is not a bug.

Q

Interlaced video looks very bad when encoded with ffmpeg, what is wrong?

A

You should use ’-flags +ilme+ildct’ and maybe ’-flags +alt’ for interlaced material, and try ’-top 0/1’ if the result looks really messed-up.

Q

Why is make fate not running all tests?

A

Make sure you have the fate-suite samples and the SAMPLES Make variable or FATE_SAMPLES environment variable or the --samples configure option is set to the right path.

Q

Why not rewrite FFmpeg in object-oriented C++?

A

FFmpeg is already organized in a highly modular manner and does not need to be rewritten in a formal object language. Further, many of the developers favor straight C; it works for them. For more arguments on this matter, read "Programming Religion".

Q

How do I encode movie to single pictures?

A

Use:

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.

Related Tutorials in FFmpeg Commands in Linux with Examples

Related Tutorials in FFmpeg Commands in Linux with Examples

FFmpeg Commands in Linux with Examples
FFmpeg Commands in Linux with Examples
Apr 4, 2016
Basic Linux Command Line Tricks
Basic Linux Command Line Tricks
Apr 20, 2016
Useful commands to manage Desktop and Server in Linux - Part 1
Useful commands to manage Desktop and Server in Linux - Part 1
Apr 27, 2016
Useful commands to manage Desktop and Server in Linux - Part 2
Useful commands to manage Desktop and Server in Linux - Part 2
Apr 27, 2016
How to use mkdir, tar and kill commands efficiently in Linux
How to use mkdir, tar and kill commands efficiently in Linux
Apr 19, 2016
Interesting Command Line Tips and Tricks in Linux
Interesting Command Line Tips and Tricks in Linux
Apr 5, 2016
How to run Linux commands every X seconds
How to run Linux commands every X seconds
Mar 25, 2016

Related Forums in FFmpeg Commands in Linux with Examples

Related Forums in FFmpeg Commands in Linux with Examples

CentOS
isaiah class=
pidstat no found
May 28, 2018
Basic Commands
FerTah class=
Command sort or uniq
Apr 10, 2019
Windows
Aditya class=
Net view usage in Windows 10
Jul 31, 2019
Basic Commands
gibbson class=
How to install locate command
Aug 25, 2018
Basic Commands
yousuf class=
How to check history command with time
Aug 25, 2018
Basic Commands
raven class=
Basic Commans are not working
Dec 29, 2017
CentOS
muhammad class=
list files on created time
Jun 12, 2018
Basic Commands
elijah class=
How to List only Directories from the Current Location in Linux
Dec 18, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaiah ?
What is the use of SUID & SGID commands

How to set the special permissions to the files and folders using SUID and SGID commands...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.