Home Audio/Video Converters 20+ FFmpeg Commands For Beginners
FFmpeg Commands

20+ FFmpeg Commands For Beginners

By sk
15447 Views

In this guide, I will be explaining how to use FFmpeg multimedia framework to do various audio, video transcoding and conversion operations with examples. I have compiled most commonly and frequently used 20+ FFmpeg commands for beginners. I will keep updating this guide by adding more examples from time to time. Please bookmark this guide and come back in a while to check for the updates. Let us get started, shall we? If you haven't installed FFmpeg in your Linux system yet, refer the following guide.

20+ FFmpeg Commands For Beginners

The typical syntax of the FFmpeg command is:

ffmpeg [global_options] {[input_file_options] -i input_url} ...
 {[output_file_options] output_url} ...

We are now going to see some important and useful FFmpeg commands.

1. Getting audio/video file information

To display the details of a media file, run:

$ ffmpeg -i video.mp4

Sample output:

ffmpeg version n4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181127
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:28.79, start: 0.000000, bitrate: 454 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 318 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 04/08/2019.
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 04/08/2019.
At least one output file must be specified

As you see in the above output, FFmpeg displays the media file information along with FFmpeg details such as version, configuration details, copyright notice, build and library options etc.

If you don't want to see the FFmpeg banner and other details, but only the media file information, use -hide_banner flag like below.

$ ffmpeg -i video.mp4 -hide_banner

Sample output:

View audio, video file information using FFMpeg

View audio, video file information using FFMpeg

See? Now, it displays only the media file details.


Suggested read:


2. Converting video files to different formats

Since FFmpeg is a feature-rich and powerful audio and video converter, so It's possible to convert media files between different formats. Say for example, to convert mp4 file to avi file, run:

$ ffmpeg -i video.mp4 video.avi

Similarly, you can convert media files to any format of your choice.

For example, to convert youtube flv format videos to mpeg format, run:

$ ffmpeg -i video.flv video.mpeg

If you want to preserve the quality of your source video file, use '-qscale 0' parameter:

$ ffmpeg -i input.webm -qscale 0 output.mp4

To check list of supported formats by FFmpeg, run:

$ ffmpeg -formats

3. Converting video files to audio files

To convert a video file to audio file, just specify the output format as .mp3, or .ogg, or any other audio formats.

The above command will convert input.mp4 video file to output.mp3 audio file.

$ ffmpeg -i input.mp4 -vn output.mp3

Also, you can use various audio transcoding options to the output file as shown below.

$ ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 output.mp3

Here,

  • -vn - Indicates that we have disabled video recording in the output file.
  • -ar - Set the audio frequency of the output file. The common values used are  22050, 44100, 48000 Hz.
  • -ac - Set the number of audio channels.
  • -ab - Indicates the audio bitrate.
  • -f - Output file format. In our case, it's mp3 format.

The above command will display a warning message like below.

[libmp3lame @ 0x5589ed539240] Bitrate 320 is extremely low, maybe you mean 320k
The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s

This is because we have given 320 bits/second as bitrate which is very low.  This will create a smaller output file. For best quality output, use bitrate value as 320k instead of just 320.

4. Change the volume of audio files

FFmpeg allows us to change the volume of an audio file using "volume filter" option.

For example, the following command will decrease volume by half.

$ ffmpeg -i input.mp3 -af 'volume=0.5' output.mp3

Similarly, we can increase the volume like below:

$ ffmpeg -i input.mp3 -af 'volume=1.5' output.mp3

5. Change resolution of video files

If you want to set a particular resolution to a video file, you can use following command:

$ ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4

Or,

$ ffmpeg -i input.mp4 -s 1280x720 -c:a copy output.mp4

The above command will set the resolution of the given video file to 1280x720.

Similarly, to convert the above file to 640x480 size, run:

$ ffmpeg -i input.mp4 -filter:v scale=640:480 -c:a copy output.mp4

Or,

$ ffmpeg -i input.mp4 -s 640x480 -c:a copy output.mp4

This trick will help you to scale your video files to smaller display devices such as tablets and mobiles.

6. Compressing video files

It is always an good idea to reduce the media files size to lower size to save the harddrive's space.

The following command will compress and reduce the output file's size.

$ ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4

Please note that you will lose the quality if you try to reduce the video file size. You can lower that crf value to 23 or lower if 24 is too aggressive.

You could also transcode the audio down a bit and make it stereo to reduce the size by including the following options.

-ac 2 -c:a aac -strict -2 -b:a 128k

7. Compressing Audio files

Just like compressing video files, you can also compress audio files using -ab flag in order to save some disk space.

Let us say you have an audio file of 320 kbps bitrate. You want to compress it by changing the bitrate to any lower value like below.

$ ffmpeg -i input.mp3 -ab 128 output.mp3

The list of various available audio bitrates are:

  1. 96kbps
  2. 112kbps
  3. 128kbps
  4. 160kbps
  5. 192kbps
  6. 256kbps
  7. 320kbps

8. Removing audio stream from a video file

If you don't want audio from a video file, use -an flag.

$ ffmpeg -i input.mp4 -an output.mp4

Here, 'an' indicates no audio recording. In other words, this option will mute the audio.

The above command will undo all audio related flags.

9. Removing video stream from a media file

Similarly, if you don't want video stream, you could easily remove it from the media file using 'vn' flag. vn stands for no video recording. In other words, this command converts the given media file into audio file.

The following command will remove the video from the given media file.

$ ffmpeg -i input.mp4 -vn output.mp3

You can also mention the output file's bitrate using '-ab' flag as shown in the following example.

$ ffmpeg -i input.mp4 -vn -ab 320 output.mp3

10. Extracting images from the video

Another useful feature of FFmpeg is we can easily extract images from a video file. This could be very useful, if you want to create a photo album from a video file.

To extract images from a video file, use the following command:

$ ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png

Here,

  • -r - Set the frame rate. I.e the number of frames to be extracted into images per second. The default value is 25.
  • -f - Indicates the output format i.e image format in our case.
  • image-%2d.png - Indicates how we want to name the extracted images. In this case, the names should start like image-01.png, image-02.png, image-03.png and so on. If you use %3d, then the name of images will start like image-001.png, image-002.png and so on.

11. Cropping videos

FFMpeg allows to crop a given media file in any dimension of our choice.

The syntax to crop a vide ofile is given below:

ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4

Here,

  • input.mp4 - source video file.
  • -filter:v - Indicates the video filter.
  • crop - Indicates crop filter.
  • w - Width of the rectangle that we want to crop from the source video.
  • h - Height of the rectangle.
  • x - x coordinate of the rectangle that we want to crop from the source video.
  • y - y coordinate of the rectangle.

Let us say you want to a video with a width of 640 pixels and a height of 480 pixels, from the position (200,150), the command would be:

$ ffmpeg -i input.mp4 -filter:v "crop=640:480:200:150" output.mp4

Please note that cropping videos will affect the quality. Do not do this unless it is necessary.

12. Convert a specific portion of a video

Sometimes, you might want to convert only a specific portion (duration) of the video file to different format. Say for example, the following command will convert the first 10 seconds of given video.mp4 file to video.avi format.

$ ffmpeg -i input.mp4 -t 10 output.avi

Here, we specify the the time in seconds. Also, it is possible to specify the time in hh.mm.ss format.

13. Set the aspect ratio to video

You can set the aspect ration to a video file using -aspect flag like below.

$ ffmpeg -i input.mp4 -aspect 16:9 output.mp4

The commonly used aspect ratios are:

  • 16:9
  • 4:3
  • 16:10
  • 5:4
  • 2:21:1
  • 2:35:1
  • 2:39:1

14. Adding poster image to audio files

You can add the poster images to your files, so that the images will be displayed while playing the audio files. This could be useful to host audio files in Video hosting or sharing websites.

$ ffmpeg -loop 1 -i inputimage.jpg -i inputaudio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4

15. Trim a media file using start and stop times

To trim down a video to smaller clip using start and stop times, we can use the following command.

$ ffmpeg -i input.mp4 -ss 00:00:50 -codec copy -t 50 output.mp4

Here,

  • --s - Indicates the starting time of the video clip. In our example, starting time is the 50th second.
  • -t - Indicates the total time duration.

This is very helpful when you want to cut a part from an audio or video file using starting and ending time.

Similarly, we can trim down the audio file like below.

$ ffmpeg -i audio.mp3 -ss 00:01:54 -to 00:06:53 -c copy output.mp3

16. Split audio/video files into multiple parts

Some websites will allow you to upload only a specific size of video. For example, Whatsapp will allow only 15 seconds videos to set as status message for users in India. In such cases, you can split the large video files into multiple smaller parts like below.

$ ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4

Here, -t 00:00:30 indicates a part that is created from the start of the video to the 30th second of video. -ss 00:00:30 shows the starting time stamp for the next part of video. It means that the 2nd part will start from the 30th second and will continue up to the end of the original video file.

17. Joining or merging multiple audio/video parts into one

FFmpeg will also join the multiple video parts and create a single video file.

Create join.txt file that contains the exact paths of the files that you want to join. All files should be same format (same codec). The path name of all files should be mentioned one by one like below.

file /home/sk/myvideos/part1.mp4
file /home/sk/myvideos/part2.mp4
file /home/sk/myvideos/part3.mp4
file /home/sk/myvideos/part4.mp4

Now, join all files using command:

$ ffmpeg -f concat -i join.txt -c copy output.mp4

If you get an error something like below;

[concat @ 0x555fed174cc0] Unsafe file name '/path/to/mp4'
join.txt: Operation not permitted

Add "-safe 0":

$ ffmpeg -f concat -safe 0 -i join.txt -c copy output.mp4

The above command will join part1.mp4, part2.mp4, part3.mp4, and part4.mp4 files into a single file called "output.mp4".

Alternatively, you can use the following one-liner command to join all files in a directory. Go to the directory where you have files and run the following command to join the files named audio1.mp3, audio2,mp3 and audio3.mp3 into output.mp3.

$ ffmpeg -i "concat:audio1.mp3|audio2.mp3|audio3.mp3" -c copy output.mp3

18. Add subtitles to a video file

We can also add subtitles to a video file using FFmpeg. Download the correct subtitle for your video and add it your video as shown below.

$ fmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4

19. Preview or test video or audio files

You might want to preview to verify or test whether the output file has been properly transcoded or not. To do so, you can play it from your Terminal with command:

$ ffplay video.mp4

Similarly, you can test the audio files as shown below.

$ ffplay audio.mp3

20. Increase/decrease video playback speed

FFmpeg allows you to adjust the video playback speed.

To increase the video playback speed, run:

$ ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4

The command will double the speed of the video.

To slow down your video, you need to use a multiplier greater than 1.  To decrease playback speed, run:

$ ffmpeg -i input.mp4 -vf "setpts=4.0*PTS" output.mp4

21. Increase/decrease Audio playback speed

To increase or decrease speed up or down audio playback, use the "atempo" audio filter. The following command will double the speed of audio.

$ ffmpeg -i input.mp4 -filter:a "atempo=2.0" -vn output.mp4

You can use any value between 0.5 and 2.0 for audio.

22. Create Animated GIF

We use GIF images on almost all social and professional networks for various purposes. Using FFmpeg, we can easily and quickly create animated video files. The following guide explains how to create an animated GIF file using FFmpeg and ImageMagick in Unix-like systems.


Suggested read:


23. Create videos from PDF files

I collected many PDF files, mostly Linux tutorials, over the years and saved in my Tablet PC. Sometimes I feel too lazy to read them from the tablet. So, I decided to create a video from PDF files and watch it in a big screen devices like a TV or a Computer. If you ever wondered how to make a movie file from a collection of PDF files, the following guide will help.

24. Rotate Videos

If you have video files with different orientation (portrait or landscape), you can rotate them as described in the following guide.

25. Convert Videos To WhatsApp Video Format

WhatsApp doesn't support some videos. You can't share them with your contacts or set them in whatsapp status. No worries! We can easily convert videos WhatsApp supported video format with FFmpeg as described in the following link.

26. Getting help

In this guide, I have covered the most commonly used FFmpeg commands. It has a lot more different options to do various advanced functions. To learn more about it, refer the man page.

$ man ffmpeg

Related read:


And, that's all. I hope this guide will help you to getting started with FFmpeg.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

23 comments

IJK May 12, 2017 - 4:12 am

The -sameq option is absent in recent versions of ffmpeg.

Reply
SK May 12, 2017 - 12:35 pm

Thanks for the heads up. I removed it now. Much appreciated.

Reply
IJK May 13, 2017 - 4:52 am

qscale 0 seems to do pretty much the same thing though.

Reply
Vladimir April 1, 2019 - 3:06 pm

Hi any advice for newbie how to stop playing current track and start playing other one with ffmpeg in ruby (on web)

Reply
Nuttapong Sarkana June 1, 2019 - 12:38 am

wow thank you sh much.

Reply
Anthony June 22, 2019 - 6:07 pm

This is a great breakdown of simple FFmpeg cmds, I’ll be referring others to this page in the future.

Reply
Dave July 19, 2019 - 9:41 am

Awesome article. Great job. Going right into favorites!

Reply
bruce September 20, 2019 - 9:23 am

Hello, i find a problem. When i execute a command ./ffmpeg -i input.ts -t 10 output.ts, it returns a error “Conversion failed!”. Pls check this.

Reply
Robert St.Amour October 6, 2019 - 10:34 am

Any pointers on how to record Linux audio , so far I’ve been able to record line-in, but using, eg, -i hw:0, or hw:0,0 returns resource busy.

I assume my asound.conf needs an entry but I haven’t figured out what the names in that file refer to, or what to pass to ffmpeg as an input arg.

Reply
Danilo April 17, 2020 - 3:21 am

hello thanks for this, i’m share it’s very convenient to also check the duration of a video file with this command:

$ ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ‘ ‘ -f 4 | sed s/,//

Reply
EbonCandle May 11, 2020 - 3:28 am

For Converting video files to audio files:
when i run –> ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 output.mp3
it says–>
“Bitrate 320 is extremely low, maybe you mean 320k
The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s”

then i replaced ‘320’ by ‘320k’ , it showed no errors.
please update this ^ u ^

Reply
sk May 11, 2020 - 1:28 pm

That’s not an error. It is just a notification. If you only enter 320, it simply takes bits/s as argument. If you enter 320k, it takes kbits/s as argument. It is bitrate of the output file.

Reply
HAL May 14, 2020 - 2:36 am

EbonCandle:

You can not convert video to audio yet, for that you need a HAL-9000 computer that can read the lips movement to synthesize speech. If the images contain text, you can use ffmpeg to extract the frames to be processed by an OCR and a speech synthesis program.

However you can extract audio from a video with audio file.
ffmpeg -i input.mp4 -vn -c:a copy output.mp3

-vn suppress the video track and Reply

-c:a copy, just copies the audio track without conversion.

the format is taken from the .mp3 extension.

You don’t need to convert the audio if both, source and target formats, support the video encoding.

Reply
HAL May 14, 2020 - 2:48 am

SK: You may have noticed that I accidentally pasted a “Reply” text in the above text.
That is due to the nasty big “click pad”, that one accidentally touches during typing moving the cursor anywhere or pasting or dragging text if the touch is interpreted as middle click or drag gesture.

Do you know any way to inhibit that nasty behavior of click pads?

In the past synclient could be configured with commands, but the new linux distributions use other “driver” to handle the click pad which I don’t know how to configure.

Reply
sk May 14, 2020 - 11:52 am

I don’t know what is click pad. If you meant touchpad, we can disable it while typing or disable it when an external mouse is connected. Check the following resources for details.

https://ostechnix.com/disable-touchpad-while-typing-in-ubuntu-using-syndaemon/
https://ostechnix.com/automatically-disable-touchpad-when-external-mouse-is-connected-in-ubuntu/

Reply
PL May 27, 2020 - 9:09 am

Perfect for me, the beginner. Glad that I found this. Many features I have been looking for. Didn’t know it could be this easy.

Thank you!

Reply
jasmine June 1, 2020 - 4:22 am

thank you so much,
but please help me to achieve my desired results.
i want to convert a .vob and .m2ts videos to mkv profile [email protected] in high quality like original videos, so what would be the command??

Reply
Matias June 29, 2020 - 1:03 am

Thank you so much for this guide. I came to it after getting frustrated with a couple of FFMPEG GUI wrapper.
There are many outdated wrappers that use deprecated arguments or just don´t accept latest versions of ffmpeg.
This article made me self-confident to just use FFMPEG from the command line.

Reply
Kalpesh Kumawat July 6, 2020 - 2:50 pm

Hello,
I wanna split my video into 15-second segments, My video length is 40 seconds (It is dynamic).
$ ffmpeg -i input.mp4 -t 00:00:15 -c copy part1.mp4 -ss 00:00:15 -codec copy part2.mp4

This commands not working for me because it trimmed 0-15 & 16-40 seconds
I need 0-15, 16-30, 31-40 seconds

Reply
sk July 6, 2020 - 8:01 pm

Trim one part at a time. First trim 0-15 and then try other two.

Reply
goorawin July 28, 2020 - 10:38 am

I have created a script to encode an MXF file with 2 separate audio files into a Prores with two ember ed audio tracks, and it works fine. See script.

However I would like to be able to batch encode using wildcards for the file names, so how can this be done? Note the files are all mxf and only have a number of digits that are different. The last 2 digits appear to be different for each of the 3 tracks. Video ends in 40 and audio tracks end in 50 & 60

ffmpeg -i 584198C1V01.5DE998CB.63FF40.mxf -i 584198C1A01.5DE998CB.63FE60.mxf -i 584198C1A02.5DE998CB.63FE50.mxf -c:v prores_ks -profile:v 3 -pix_fmt yuva444p10le -qscale:v 9 -r 25 -vf yadif -c:a pcm_s16le -map 0:v:0 -map 1:a:0 -map 2:a:0 “Output.mov”

Any inputs would be greatly appreciated.

Reply
sk July 28, 2020 - 12:22 pm

I don’t know much about scripting/coding. So, I couldn’t help. My apologies. Please post your question in FFmpeg reddit discussion forum – https://www.reddit.com/r/ffmpeg/

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More