In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use FFmpeg video processing to share with you. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
FFmpeg is the most commonly used open source software for video processing.
It is powerful and versatile. It is widely used in video websites and commercial software (such as Youtube and iTunes). It is also a standard encoding / decoding implementation of many audio and video formats.
FFmpeg itself is a huge project, with many components and library files, the most commonly used being its command-line tools. This article describes how the FFmpeg command line handles video, which is more concise and efficient than desktop video processing software.
If you haven't installed it yet, you can complete the installation first according to the official documentation.
I. concept
Before introducing the usage of FFmpeg, you need to understand some basic concepts of video processing.
1.1 Container
The video file itself is actually a container, which includes video and audio, and may also have subtitles and other content.
There are several common container formats. In general, the suffix name of a video file reflects its container format.
MP4
MKV
WebM
AVI
The following command looks at the containers supported by FFmpeg.
$ffmpeg-formats1.2 encoding format
Both video and audio need to be encoded before they can be saved as a file. Different encoding formats (CODEC) have different compression ratios, which can lead to differences in file size and sharpness.
The commonly used video coding formats are as follows.
H.262
H.264
H.265
The above coding formats are copyrighted, but they can be used free of charge. In addition, there are several uncopyrighted video coding formats.
VP8
VP9
AV1
The commonly used audio coding formats are as follows.
MP3
AAC
All of the above are lossy encoding formats that lose some details in exchange for a smaller file size after compression. Lossless coding format compressed out of a larger file size, not introduced here.
The following command can view the encoding formats supported by FFmpeg, including video and audio encodings.
$ffmpeg-codecs1.3 encoder
An encoder (encoders) is a library file that implements an encoding format. Only when an encoder of a certain format is installed can the video / audio encoding and decoding of that format be realized.
Here are some FFmpeg built-in video encoders.
Libx264: the most popular open source H.264 encoder
NVENC: H.264 Encoder based on NVIDIA GPU
Libx265: an open source HEVC encoder
Libvpx: Google's VP8 and VP9 encoders
Libaom:AV1 encoder
The audio encoder is as follows.
Libfdk-aac
Aac
The following command can view the encoders that have been installed by FFmpeg.
The format of $ffmpeg-encoders II and FFmpeg
FFmpeg has so many command-line arguments that it can be divided into five parts.
$ffmpeg {1} {2}-I {3} {4} {5}
In the above command, the parameters of the five parts are as follows.
Global parameter
Enter file parameters
Input file
Output file parameters
Output file
When there are too many parameters, the ffmpeg command can be written as multiple lines for ease of viewing.
$ffmpeg\
[global parameters]\
[input file parameters]\
-I [input file]\
[output file parameters]\
[output file]
Here is an example.
$ffmpeg\-y\ # Global parameters-input.mp4 a libfdk_aac-CMV libx264\ # input file parameters-I input.mp4\ # input file-CRAV libvpx-vp9-CRAV a libvorbis\ # output file parameters output.webm # output file
The above command converts the mp4 file to a webm file, both of which are in container format. The audio encoding format of the input mp4 file is aac, and the video encoding format is H.264; the video encoding format of the output webm file is VP9, and the audio format is Vorbis.
If the encoding format is not specified, FFmpeg determines the encoding of the input file itself. Therefore, the above command can be written simply as follows.
$ffmpeg-I input.avi output.mp4 III. Common command line parameters
The common command line parameters for FFmpeg are as follows.
-c: specify the encoder
-c copy: copy directly without recoding (this is faster)
-cblov: specifies the video encoder
-CRAV a: specifies the audio encoder
-I: specify the input file
-an: remove audio stream
-vn: removes video streams
-preset: specify the video quality of the output, which will affect the speed of file generation. The following values are available: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow.
-y: without confirmation, the output will directly overwrite the file with the same name.
IV. Common usage
Here are several common uses of FFmpeg.
4.1 View file information
To view the meta-information of a video file, such as the encoding format and bit rate, you can use only the-I parameter.
$ffmpeg-I input.mp4
The above command outputs a lot of redundant information, and with the-hide_banner parameter, you can display only meta-information.
$ffmpeg-I input.mp4-hide_banner4.2 transcoding format
Conversion format (transcoding) refers to the conversion of video files from one encoding to another. For example, when converting to H.264 encoding, the encoder libx264 is generally used, so you only need to specify the video encoder of the output file.
$ffmpeg-I [input.file]-CMV libx264 output.mp4
The following is the way to convert to H.265 coding.
$ffmpeg-I [input.file]-CVR v libx265 output.mp44.3 convert container format
Conversion Container format (transmuxing) refers to the transfer of video files from one container to another. The following is how to convert mp4 to webm.
$ffmpeg-I input.mp4-c copy output.webm
In the above example, just transfer the container, and the internal encoding format remains the same, so use-c copy to specify a direct copy without transcoding, which is faster.
4.4 adjust the bit rate
Adjusting bit rate (transrating) refers to changing the bit rate of encoding, which is generally used to reduce the size of video files. The following example specifies a minimum code rate of 964K, a maximum of 3856K, and a buffer size of 2000K.
$ffmpeg\-I input.mp4\-minrate 964K-maxrate 3856K-bufsize 2000K\ output.mp44.5 change resolution (transsizing)
Here is an example of changing the video resolution (transsizing) from 1080p to 480p.
$ffmpeg\-I input.mp4\-vf scale=480:-1\ output.mp44.6 extract audio
Sometimes, you need to extract audio (demuxing) from the video, which can be written like this.
$ffmpeg\-I input.mp4\-vn-CMV a copy\ output.aac
In the above example,-vn means to remove the video, and-CRAV a copy means to copy directly without changing the audio coding.
4.7 add audio track
Adding muxing refers to adding external audio to the video, such as adding background music or narration.
$ffmpeg\-I input.aac-I input.mp4\ output.mp4
In the above example, there are two input files, audio and video, and FFmpeg combines them into one file.
4.8 Screenshot
The following example is a screenshot of a continuous video for 1 second starting at a specified time.
$ffmpeg\-y\-I input.mp4\-ss 00:01:24-t 00:00:01\ output_%3d.jpg
If you only need to take one picture, you can specify that only one frame is intercepted.
$ffmpeg\-ss 01:23:45\-I input\-vframes 1-Q input v 2\ output.jpg
In the above example,-vframes 1 specifies that only one frame is intercepted, and-qv2 represents the quality of the output picture, usually between 1 and 5 (1 is the highest quality).
4.9 cut
Cutting means to take a clip from the original video and output it as a new video. You can specify a start time (start), a duration (duration), or an end time (end).
$ffmpeg-ss [start]-I [input]-t [duration]-c copy [output] $ffmpeg-ss [start]-I [input]-to [end]-c copy [output]
Here is a practical example.
$ffmpeg-ss 00:01:50-I [input]-t 10.5-c copy [output] $ffmpeg-ss 2.5-I [input]-to 10-c copy [output]
In the above example,-c copy means to copy directly without changing the encoding format of audio and video, which is much faster.
4.10 add a cover for audio
Some video sites are only allowed to upload video files. If you want to upload an audio file, you must add a cover to the audio, convert it to video, and then upload it.
The following command converts an audio file to a video file with a cover.
$ffmpeg\-loop 1\-I cover.jpg-I input.mp3\-aac v libx264-C input.mp3 an aac-Blav 19k-shortest\ output.mp4
In the above command, there are two input files, one is the cover image cover.jpg, and the other is the audio file input.mp3. The-loop 1 parameter indicates that the picture loops indefinitely, and the-shortest parameter indicates that the audio file ends and the output video ends.
Thank you for reading! This is the end of this article on "how to use FFmpeg video processing". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.