List of useful FFMPEG Commands for Video & Audio Editing

0

FFMPEG is the most powerful video editing solution, but it uses a command line interface. To operate FFMPEG, you need to learn about the basic FFMPEG commands. Here is the list of all useful FFMPEG commands for video and audio file editing.

FFMPEG

Those of you who don’t know, FMPEG is an open-source video editor. It’s a free-to-use tool and it can do pretty much anything. At first, FFMPEG supports 100s of video and audio formats. It supports almost all the codecs that exist to date. Even the formats and codecs that are now obsolete, the FFMPEG will let you handle those. It uses a command-line interface which means you will be editing your videos and audio files using commands.

useful FFMPEG Commands

FFMPEG can be used to crop a video or change dimensions of a video. It can be further used to split a video clip or join multiple clips together. You can convert video and audio files from any format to another format. For example, you can transform the .wav audio files into .mp3 format and vice versa. Similarly, you can transform .mkv video file into .mp4 and vice versa. There is two-way support for all audio & video formats.

Furthermore, you can create a video clip by joining photos, a video slideshow to be specific. It can also speed up or slow down a video clip. One of the best features of FFMPEG is its ability to extract audio from a video file. If you like the music behind a video at a specific time, just run the FFMPEG and extract that favorite part of yours. Anything that works for the videos, that also works for the audios. 

FFMPEG is such a versatile tool, with this one tool, you won’t have to use any other video/audio conversion or crop tool. This tool can treat your audio and video files in almost all ways. Of course, it’s not a tool like Adobe Premiere Pro, Filmora, or the iMove. It’s only meant to change the video/audio size/dimensions/length/formats. The best thing about FFMPEG? Well, it’s the fastest video editing tool you will ever use. It merely takes a few seconds to perform a specific operation using FFMPEG.

As far as the FFMPEG compatibility is concerned, it’s available for Windows, macOS, and Linux. 

Now all the operations that I have mentioned above, can be performed with the help of FFMPEG commands only. Down below, I am going to list over 20 useful FFMPEG commands. The purpose of each FFMPEG command is written next to it. Take a look and find out your desired FFMPEG command.

Before you take a look a the FFMPEG commands, here are the important sources:

List of useful FFMPEG Commands

Convert a video from one format to another

ffmpeg -i inputvideo.mkv -codec copy outputvideo.mp4

useful FFMPEG Commands

This command can convert video from any format to any other format. Replace the inputvideo.mkv with your source video and format and outputvideo.mp4 with your output video and format.

Convert an Audio file

ffmpeg -i inputaudio.wav -codec copy outputaudio.mp3

Just like the video files, you can convert any audio from one format to another. Replace the inputaudio.wav with your source audio and format, and the outputaudio.mp3 with your output audio name and format.

Change Video resolution

ffmpeg -i testvid.mp4 -vf scale=1920:-1 -c:v libx264 -qp 16 convertedvideo.mp4

useful FFMPEG Commands

First of all, go to your source video’s properties > details and note down its dimensions i.e. 1920 x 1080 or if it’s a 4K video, note down its dimensions. Run the above command by replacing testvid.mp4 with your input video and format, use the -vf scale to define the output video resolution i.e. 1920 for 1080p or 2160 for 2K video, libx264 is the codec, convertedvideo.mp4 is the output file, replace it with your desired output name.

Change Video frame rate

ffmpeg -i inputvideo.mp4 -fitler:v fps=fps=30 outputvideo.mp4

Go to your video’s properties > details and find out its original frame rate. Change the inputvideo.mp4 with your source video name and format, change fps=30 to any frame rate you want, and change the outputvideo.mp4 to your desired output name and format.

Cut a video into small parts

ffmpeg -i input.mp4 -ss 00:00:50.0 -codec copy -t 20 output.mp4

Change input.mp4 to your source video and format, use -ss parameter to set the clip’s starting time, use the -t to set the clip duration and change output.mp4 to your desired output name and format.

Split a video into multiple small parts

ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4

Change video.mp4 with your source video and format, use -t to set the clip duration, change the small-1.mp4 to set clip-1’s name and format, use the -ss parameter to set the starting time of the 2nd clip and small-2.mp4 will be the name of the 2nd clip.

Speed up or slow down an audio file

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

Replace the input.mp3 and output.mp3 with your source and output file name, atempo-2.0 is the clip speed, 2.0 will speed up by 2x, set it to whatever you want. You can use any number from 0.5 to 2.0.

Speed up or slow down a video file

ffmpeg -i input.mp4 -filter:v "setpts=0.125*PTS" output.mp4

Replace input.mp4 with your source video name and format, use setpts=0.125*PTS to set slow down or speed up a video. 0.125 makes your video slow. Set the output.mp4 to your own output name and format.

Rotate a video

ffmpeg -i input.mp4 -filter:v 'transpose=1' ouput.mp4

This command will rotate your video to 90-degrees for once. To rotate to 90 degrees twice, use transpose=2.

Rotate a video to 180-degree

ffmpeg -i input.mp4 -filter:v 'transpose=2,transpose=2' output.mp4

This command will rotate your video to 180-degrees.

Add subtitles to a video

ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv

Put the source video and subtitles file in the same folder. Replace the movie.mp4 and subtitles.srt with the original file names and formats and change the output.mkv to your own output file name and format. Remember that FFMPEG supports a large number of subtitle formats.

Join video or audio clips

ffmpeg -f concat -i file-list.txt -c copy output.mp4

Put your video and audio clips in a folder. Create a text file and put the sources of those audio/video clips in that text file. Run FFMPEG with the concat command, replace the file-list.txt with your .txt file and output.mp4 with your output name and format.

Convert video into a GIF

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

Replace video.mp4 with your video and format, set the GIF scale according to your own choice, -t is the duration and -r is the framerate while image.gif is the output file name.

Extract Audio from a Video

ffmpeg -i video.mp4 -vn -ab 256 audio.mp3

Change video.mp4 to your source video and format, 256 is the bitrate of audio while audio.mp3 is out output audio name and format. You can change all this for yourself.

Extract Image Frames from a Video

ffmpeg -ss 00:00:15 -i video.mp4 -vf scale=800:-1 -vframes 1 image.jpg

This command can extract images from a video. Use the parameter -ss to set the time of image capture, video.mp4 will be your source video, the scale is the size/dimensions of the image and image.jpg is the output image name.

Convert video into images

ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png

An entire video can be converted into images with FFMPEG. Replace the movie.mp4 with your source video and frames_0%4d.png will be your output images name.

Merge Audio and Video files

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental output.mp4

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental -shortest output.mp4

The above two commands can join an audio and video clip, this will actually add background music to your video. Replace the video.mp4 and audio.mp3 with your source files and output.mp4 with the output file name and format. 

Create a video slideshow

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4

You can create a slideshow out of images. Parameter -r 1/5 defines the duration of each image i.e. 5 seconds, img%03d.png is the name of image, use names such as image001.png, image002.png, image003.png, slideshow.mp4 is the output name, you can change it accordingly.

Resize a video

ffmpeg -i input.mp4 -s 480x320 -c:a copy output.mp4

Quickly change the resolution of a video. Replace input.mp4 with your source name and format, set the 480×320 to any dimensions of your choice i.e. 1920 x 1080 or 1280 x 720, change the output name and format accordingly.

Add a poster image to audio for music players

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

Ever seen that poster while playing an mp3 song in a music player? Well, you can add that on your own too. Replace the image.jpg with the name and format of your source image, audio.mp3 is your source audio file with its format, 192k is the bitrate and the output.mp4 is the audio output file name and format.

Convert an image into a video

ffmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p video.mp4

To convert an image into a video, replace the image.png with your image and format, set the -t 30 to any number, this is the duration of the video, and set the video.mp4 to your output name and format.

Crop an audio file

ffmpeg -ss 00:01:30 -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3

This is the command to crop any audio file using FFMPEG. -ss is the starting time of an audio clip, -t is the duration, inputfile.mp3 is the source file and outputfile.mp3 is the output. Replace the names and formats accordingly.

Change audio volume level

ffmpeg -i input.wav -af 'volume=0.5' output.wav

To change the default audio level of a clip using FFMPEG, use this command. Input.wav is your source file, 0.5 is the volume level, change it to any level of your choice and output.wav is the output file name and format.

Mute a video

ffmpeg -i video.mp4 -an mute-video.mp4

This command will remove the audio from a video. This will actually mute the clip using FFMPEG. Replace the video.mp4 with your source video name and format.

Final Words

That’s all with the most common FFMPEG commands. These also happen to be the most popular FFMPEG commands, but that’s not it. There are hundreds of other commands that you can find on the official FFMPEG page. If you run into any problems while using these commands, feel free to reach out to us. We will try our best to help you out.

SHARE
Usama M, a software engineer by profession, is the founder and editor-in-chief at Techbeasts. At Techbeasts, he uses his expertise to craft solutions to solve everyday consumer tech problems. His main areas of interest are Android, iOS, and Windows. You can find him on YouTube at "Tech with Usama".

Got a question/query or a suggestion? Drop it below.