Few ffmpeg commands for CentOS/RHEL & Ubuntu

FFmpeg is a complete solution to record, convert and stream audio and video. It includes libavcodec, the leading audio/video codec library. FFmpeg is developed under Linux, but it can compiled under most operating systems, including Windows. In ubuntu This package contains the ffplay multimedia player, the ffserver streaming server and the ffmpeg audio and video encoder. They support most existing file formats (AVI, MPEG, OGG, Matroska, ASF, …) and encoding formats (MPEG, DivX, MPEG4, AC3, DV, …).


Getting infos from a video file

You have several commands to get that information.

# ffmpeg -i video.mp4

Merge n no. of images

Create a video from series of numerically sequential images such as:

# ffmpeg -f image2 -i img%d.jpg video.mp4

This command will transform all the images from the current directory (named img1.jpg, img2.jpg, etc) to a video file named video.mp4.

Turn a video to n no. of images

It’s very simple with ffmpeg. To export as an image sequence just use img_%04d.jpg or similar as the output.

# ffmpeg -i video.mp4 img_%04d.jpg

This command will generate the files named img_0001, img_0002, …

Encode a video sequence for the iPod/iPhone

Sometime we face an issue while running videos on iPod/iPhone. So we needed to convert video to iPod/iPhone format.

# 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 320x180 -title X final_video.mp4


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

Encode video for the PSP

I figured the best way to encode PSP video using ffmpeg from the command line:

# ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4

Extracting sound from a video, and save it as Mp3

You can easily extract audio from video files such as avi, mpg, even flv into mp3 uses ffmpeg. You can even record online stream into mp3, such as stream from radio cast. The audio component can be extracted to an mp3 using following command:

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

Convert a wav file to Mp3

You can also do audio and video conversions at the same time:

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

Convert .avi video to .mpg

First you need to download your .avi file to a folder and you need to Open a terminal window and go in to the .avi file folder and type the following command

# ffmpeg -i video_origine.avi video_finale.mpg

Convert .mpg to .avi

# ffmpeg -i video_origine.mpg video_finale.avi

Convert .avi to animated gif(uncompressed)

# ffmpeg -i video_origine.avi gif_anime.gif

Mix a video with a sound file

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

Convert .avi to .flv

# ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv

Convert .avi to dv

# ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv
# ffmpeg -i video_origine.avi -target pal-dv video_finale.dv

Convert .avi to mpeg for dvd players

# ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 final_video.mpeg

Compress .avi to divx

# ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi

Compress Ogg Theora to Mpeg dvd

# ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg

Compress .avi to SVCD mpeg2

NTSC format:

# ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg

PAL format:

# ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg

Compress .avi to VCD mpeg2

NTSC format:

# ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg

PAL format:

# ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg

Multi-pass encoding with ffmpeg

# ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2 

Enjoy it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.