Virtually anybody who offers with movies could have heard of FFmpeg earlier than. For individuals who are unfamiliar, FFmpeg is a free and open-source program that may convert any video format to a different and alter its codecs.
FFmpeg helps practically all audio/video codecs (H.264, H.265, VP8, VP9, AAC, OPUS, and extra), file codecs (MP4, FLV, MKV, TS, WEBM, MP3, and many others.), and even streaming protocols (HTTP, RTMP, RTSP, HLS, and many others.).
Here is how one can set up and use FFmpeg to course of audio and video recordsdata on Linux.
FFmpeg Set up on Linux
FFmpeg is a free and open-source instrument obtainable within the default repositories of just about each main Linux distribution. It’s also possible to get its source code without spending a dime should you want to compile it your self.
sudo apt set up ffmpeg
sudo dnf set up https://download1.rpmfusion.org/free/fedora/rpmfusion-free-launch-$(rpm -E %fedora).noarch.rpm
sudo dnf -y set up ffmpeg
yum set up ffmpeg ffmpeg-devel
pacman -S ffmpeg
If all the things goes properly throughout set up, you must be capable of see the FFmpeg model whenever you use the -version argument.
ffmpeg -version
Getting Video Info With FFmpeg
It’s potential to see the knowledge of a video that you simply wish to edit with FFmpeg utilizing the -i flag:
ffmpeg -i example-video.mp4 -hide_banner
Right here, the -hide_banner parameter’s job is to cover pointless info. You may take away this parameter and see the distinction within the output.
As you may see, it’s potential to get plenty of info such as video codec type, creation date, metadata, and encoder construction of the pattern video.
Changing Video or Audio Recordsdata to One other Format
Some of the helpful options of FFmpeg is that it may well convert a video or audio to a different format. You are able to do this with easy one-liners.
MOV to MP4 With FFmpeg
You may convert your MOV format video file to MP4 with FFmpeg utilizing the command beneath:
ffmpeg -i input-mov-video.mov output-video.mp4
First, use the -i parameter, which stands for enter video. Then, enter the file you wish to convert. Lastly, enter the format you wish to convert it to. You can provide your output any title you need.
Whereas FFmpeg is working, it is going to present you the adjustments it has made on the command display. Your output file can be saved in your current working listing.
WAV to MP3 With FFmpeg
Much like movies, you are able to do the identical conversions for audio recordsdata. For instance, you may convert a WAV audio file to MP3 as follows:
ffmpeg -i example-wav.wav -vn -ar 48000 -ac 2 -b:a 256 output.mp3
This command has extra parameters than the video conversion methodology, however they don’t seem to be obscure. To clarify these:
- -vn: Generally the audio recordsdata you take heed to have footage. These photos often originate from movies. If you do not need such photos within the output, you should utilize this parameter.
- -ar: This parameter means that you can set the audio frequency of the audio file you wish to convert. You may regulate the sound high quality and frequency with values similar to 8kHz, 44.1kHz, or 48kHz.
- -ac: You could have heard the phrases mono and stereo earlier than. This parameter can assist you set the variety of audio channels.
- -b:a: This parameter means that you can set the audio bitrate per second. The upper the kilobit, the upper the sound high quality.
Audio Operations With FFmpeg
FFmpeg also can separate audio from movies. For this, it’s enough to make use of the -vn parameter:
ffmpeg -i example-video.mp4 -vn output.mp3
In the event you managed to separate the audio from the video, now you can attempt to take away the audio from the movies. The distinction right here is the -an parameter. It’s best to preserve this parameter in thoughts if you wish to disable any sound in a video:
ffmpeg -i example-video.mp4 -an output-mute.mp4
Video Dimension Processing With FFmpeg
Video sizes may be fairly annoying typically, particularly whenever you wish to add them someplace. You not have to obtain applications to trim them as FFmpeg can do that for you. There are some parameters you’ll want to know for this, although:
- -ss: Use this parameter to set the beginning time of the clip
- -to: Means that you can specify the top time of the clip
- -c: Set the codec of your clip utilizing this parameter
- -t: Use this parameter to set the length of the clip
You may derive many examples utilizing these parameters. For instance, if you wish to trim a video, you should utilize one thing like:
ffmpeg -i example-video.mp4 -ss 00:02:25 -to 00:03:50 -c copy output-trim.mp4
It is usually potential to crop solely the picture contained in the video and never the entire video. For this, you may resort to one thing like:
ffmpeg -i example-video.mp4 -filter:v "crop=w:h:x:y" output-crop.mp4
Listed below are the parameters used within the aforementioned command:
- -filter:v: This parameter specifies the filtering course of you’ll apply to the video
- crop: This parameter is for specifying {that a} clipping operation can be carried out
- w:h:x:y: As you would possibly’ve guessed already, the w, h, x, and y variables denote width, top, and place of the crop field, respectively
Modifying Movies on Linux With FFmpeg
Modifying movies does not finish with simply trimming and slicing. Generally you additionally want to vary the dimensions of the video. The next command will resize the video to a measurement you need:
ffmpeg -i example-video.mp4 -vf scale=1920:1080 output-scale.mp4
- -vf: This parameter works the identical because the -filter:v argument seen above
- scale: You may specify the dimensions sizes you need in your output with this parameter
FFmpeg additionally means that you can mix a number of movies. Think about you’ve a number of clips encoded with the identical codec. Enter the listing of movies you wish to merge right into a .txt file. Then, run the next command:
ffmpeg -f concat -i my-video-list.txt -c copy sum-output.mp4
The concat parameter right here combines your recordsdata. It is usually potential to rotate movies with FFmpeg:
ffmpeg -i example-video.mp4 -vf "transpose=2" output-rotate.mp4
- transpose=0: Flip vertically (default)
- transpose=1: Rotate 90 levels clockwise
- transpose=2: Rotate 90 levels counterclockwise
- transpose=3: Flip vertically
To rotate movies 180 levels clockwise, you’ll want to specify the transpose parameter twice:
ffmpeg -i example-video.mp4 -vf "transpose=2,transpose=2" output-rotate.mp4
FPS and GOP Operations
As you already know, FPS means frames per second. GOP (group of images) is the space between two keyframes. FFmpeg can also be helpful for altering some parameters, together with FPS and GOP. In the event you use the command beneath, FFmpeg will change the unique FPS to the worth you set:
ffmpeg -i example-video.mp4 -vf "fps=60" output-fps.mp4
For GOP, you should utilize the -g parameter and set its worth to no matter you need. Notice that forcing too many keyframes may be dangerous to some encoders’ ahead algorithms.
ffmpeg -i example-video.mp4 -g 200 output-gop.mp4
Create Animated GIFs With FFmpeg
FFmpeg can also be best for converting a video to animated GIFs. You should utilize a easy convert command to do that:
ffmpeg -i example-video.mp4 output-gif.gif
However typically, you could wish to customise the GIF. You should utilize the varied parameters mentioned above to realize this:
ffmpeg -ss 00:01:15 -i example-video.mp4 -to 10 -r 10 -vf scale=250:-1 output-gif.gif
The -r parameter right here means the body fee. As you may see, many alternative customizations are potential in a single line command.
Aside from changing one or many photos to video, you can too extract frames from a video. The next command will extract one body each second out of your enter video. Additionally, these extracted photos can have two-digit names like 01.jpeg, 02.jpeg, and many others. If you want, you can too add different parameters you’ve discovered.
ffmpeg -i example-video.mp4 -r 1 image-%02d.jpeg
It’s also possible to use different codecs similar to PNG and BMP for the extracted photos.
Why Ought to You Use FFmpeg on Linux?
As you may see, FFmpeg could be very advantageous in some ways. You don’t want to have any technical information or skilled Linux expertise for this. You may carry out numerous media-processing capabilities with just some parameters. If you will make edits that aren’t very lengthy, you don’t want costly pc applications and on-line premium memberships. Furthermore, FFmpeg works very properly even on low-end gadgets.
Additionally, the options of FFmpeg should not restricted to the above. Once you learn the documentation and person guide, you may see how highly effective the software program really is. Even utilizing the –help parameter and the man command, you may get extra detailed details about utilizing FFmpeg. There are additionally different nice converters for Linux to rival FFmpeg.