The 28 most useful ffmpeg commands


FFmpeg is a very powerful, free software tool, it can be used to record, convert and stream audio and video. This software includes a library of codecs, libavcodec. FFmpeg is developed in GNU / Linux but can be compiled in most Operating Systems including Windows. FFmpeg is a very simple and very easy-to-use program, targeting both people with advanced knowledge and new users.

You can download FFmpeg from its official site easily from the link given below. Link

Some useful commands from FFmpeg.

1- Get information about a video

 $ ffmpeg -i video.mp4 

2- Convert video formats

– From AVI to MP4

$ ffmpeg -i video_original.avi video_final.mp4

 – From Matroshka to Avi

$ ffmpeg -i video_source.mkv video_final.avi

 – From m4V to mp4

$ ffmpeg -i video_souce.m4v -codec copy video_final.mp4

3- Convert images to video
It changes 0.3 to give faster, when higher  faster, it formats mp4 and avi

$ cat *.JPG | ffmpeg -f image2pipe -r 0.3 -vcodec mjpeg -i - -vcodec libx264 out4.mp4 
$ cat *.JPG | ffmpeg -f image2pipe -r 0.3 -vcodec mjpeg -i - -vcodec libx264 out4.avi 

4- Extract audio from a video

$ ffmpeg -i video.mp4 -vn audio.mp3 

5- Mute the audio of a video

$ ffmpeg -i video.mp4 -an video_mute.mp4 

6- Upload the volume of a video

$ ffmpeg -i video.mp4 -vol 512 video_final.mp4 ffmpeg -i video.mp4 -af volume=2 

7- Rotate a video

$ ffmpeg -i video.mp4 -vf transpose=clock video_rotado_90.mp4 
$ ffmpeg -i video.mp4 -vf transpose=clock,transpose=clock video_rotado_180.mp4 
$ ffmpeg -i video.mp4 -vf hflip video_invertido_horizontalmente.mp4 
$ ffmpeg -i video.mp4 -vf vflip video_invertido_verticalmente.mp4 

8- Resize a video

$ ffmpeg -i video.mp4 -vf scale=320:240 video_320x240.mp4 
$ ffmpeg -i video.mp4 -vf scale=320:-1 video_320x180.mp4
$ ffmpeg -i video.mp4 -vf scale=iw/2:ih/2 video_x.mp4

9- Cut fragments of a video

$ ffmpeg -i video.mp4 -ss 35 -t 30 fragmento.mp4 
$ ffmpeg -i video.mp4 -ss 00:35 -to 01:05 fragmento.mp4 

10- Add or remove audio tracks

$ ffmpeg -i video.mp4 -i audio_es.mp3 -map 0:v -map 0:a -map 1:a -vcodec copy video_final.mp4
$ ffmpeg -i video.mp4 -map 0:0 -map 0:2 solo_canal1_audio.mp4

11- Mix audio tracks

$ ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex amerge audio_mezclado.mp3 

12- Cut areas of the video

$ ffmpeg -i screencast.mp4 -ss 00:30 -to 03:50 -vf crop=640:480:500:250 video_final.mp4 

13- Apply bulleted to the video

$ ffmpeg -i video.mp4 -vf vignette=PI/4 video_vignette.mp4 
$ ffmpeg -i video.mp4 -vf vignette='PI/4+random(1)*PI/50':eval=frame 

14- Create a fade-in,fade-out

$ ffmpeg -i video.mp4 -vf fade=t=in:st=0:d=5 video-fadein.mp4 
$ ffmpeg -i video.mp4 -vf fade=t=in:st=0:d=5,fade=t=out:st=25:d=5 video-fadeout.mp4 

15- Audio fade

$ ffmpeg -i true.mp4 -vf fade=t=in:st=0:d=5,fade=t=out:st=25:d=5 -af afade=t=in:ss=0:d=5,afade=t=out:st=25:d=5 truefade.mp4 

16- Extract frames from a video

$ ffmpeg -i video.mp4 image%d.jpg 

17- Extract frames from a video, one image per second

$ ffmpeg -i video.mp4 -vf fps=1 image%d.png 

18- Create video from a series of images

$ ffmpeg -f image2 -i image%d.jpg video.mp4 

19- Put a logo or watermark on the video

$ ffmpeg -i video.mp4 -i logo.png -filter_complex overlay=10:10 final.mp4 
$ ffmpeg -i video.mp4 -i logo.png -filter_complex overlay=x=(main_w-overlay_w):y=(main_h-overlay_h) final.mp4 

20- Join audio and video

$ ffmpeg -i audio.mp3 -i video.avi video_audio_mix.mpg 

21- Make a gif from a video

$ ffmpeg -i video.mp4 -vf scale=300:-1 -t 10 -r 10 image.gif 

22- Convert video to audio files

$ ffmpeg -i video.flv -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3 

23- Make a video to watch on the PSP

$ ffmpeg -i carpeta/ -b300 -s 320X240 -vcodec xvid -ab 12 -ar 24000 -acodec aac video_final.mp4 

24- Make a 5 sec video from an image and an audio

$ ffmpeg -loop 1 -y -i imagen.jpg -i audio.mp3 -shortest video.mp4 

25- Join videos

$ ffmpeg -i "concat:video1.mp4|video2.mp4|video3.mp4" -c copy videounido.mp4 

26- Record the main monitor

$ ffmpeg -framerate 25 -video_size 1920x1080 -f x11grab -draw_mouse 1 -show_region 1 -region_border 3 -i :0.0 -f alsa -ac 2 -i pulse -vcodec libx264 -crf 0 -preset medium -acodec libmp3lame output.mp4 

27- Record secondary monitor

$ ffmpeg -framerate 25 -video_size 1280x1024 -f x11grab -i :0.0+1920,0 -f alsa -ac 2 -i pulse -vcodec libx264 -crf 0 -preset medium -acodec libmp3lame output.mp4 

28- Extract audio from any video

$ ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3 

On the last command we can say:

-vn: Disables the understanding / recording of the video
-ar: audio rate
-ac: audio canals
-ab: bitrate d’ audio
-f: output format

Leave a Reply

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