Ffmpeg which codec
Note that the download will begin automatically when you click this link. The video is excerpted from a test video provided by Harmonic, Inc. This is easily done in FFmpeg with this command string:. Video codec, copy. This tells FFmpeg to copy the compressed video stream into the new file without re-encoding. Audio codec, copy. This tells FFmpeg to copy the compressed audio stream into the new file without re-encoding.
A similar scenario might involve files in the MPEG-2 container format with a. This particular conversion saved about 2 days of encoding when I had to convert about Or, you can just leave it in.
Say you have a file and want to eliminate the first 30 seconds, or simply grab a 2-minute excerpt from the middle. Again, you could bring the file into Adobe Premiere Pro and edit what you want, but that would involve another rendering and encoding cycle. You can do this quickly and simply in FFmpeg using the command shown below. The Harmonic test file is about 12 seconds long.
This command seeks to 5 seconds into the file and excerpts the next 3 seconds without re-encoding. Despite its name, it has nothing to do with the Moving Picture Experts Group or the myriad multimedia formats it has created. In this article I'll be using FFmpeg through the command-line tool ffmpeg , which is only a single, small piece of the FFmpeg project.
It's available on many different operating systems and is included in some operating systems by default. It can be downloaded from the FFmpeg website or through most package managers. FFmpeg is a powerful tool that can do almost anything you can imagine with multimedia files. In this article, we are interested in using it to convert files, so we won't be taking a deep dive into its entire feature set.
Before we look at using FFmpeg, first we need to take a quick look at what a media file exactly is. At a very high-level view, a media file is broken up into a container and its streams.
The streams include the actual AV components, such as a movie's audio or video, and are encoded using a particular media encoding, or codec. Each codec has its own properties, strengths, and weaknesses. For example, the FLAC codec is good for high-quality lossless audio, whereas Vorbis is designed to compete with MP3 in file size while offering better audio quality.
This means a FLAC-formatted file will be much larger than a Vorbis audio stream but should sound better. Neither is inherently better than the other, as each is trying to do different things. The container is the wrapper for the streams. It presents a single interface that media players and tools can interact with. Some containers are highly advanced and allow for any sort of stream, including multiple video and audio streams inside a single container.
The streams in a container don't have to be just audio or video though. Different containers will allow for different streams, e. It all depends on what the container is set to allow. This is an abstract representation of media files and skips over a lot of the differences between containers.
Many require certain streams and metadata or put restrictions on the codecs or contents allowed. This explanation is enough to get you through this article. To learn more, click on the links above.
Be aware that video and audio encoding can take a very long time to run. You should be prepared to settle in for a while when you use FFmpeg. The thing that trips up most people when it comes to converting audio and video is selecting the correct formats and containers. Luckily, FFmpeg is pretty clever with its default settings. Usually it automatically selects the correct codecs and container without any complex configuration. This command takes an MP3 file called input. You didn't have to specify stream or container types, because FFmpeg figured it out for you.
Because WebM is a well-defined format, FFmpeg automatically knows what video and audio it can support and will convert the streams to be a valid WebM file. Depending on your container of choice, this won't always work. For instance, containers like Matroska are designed to handle almost any stream you care to put in them, whether they're valid or not. This means the command:.
So what do you do when you want to use a container like Matroska which can handle almost any stream but still influence which codecs are in the output? FFmpeg to the rescue! You can select the codecs needed by using the -c flag. This flag lets you set the different codec to use for each stream. For example, to set the audio stream to be Vorbis, you would use the following command:. This will make a Matroska container with a VP9 video stream and a Vorbis audio stream, essentially the same as the WebM we made earlier.
The command ffmpeg -codecs will print every codec FFmpeg knows about. The output of this command will change depending on the version of FFmpeg you have installed. More often than you'd like, the file you have is partially correct with only a single stream in the wrong format.
It can be very time consuming to re-encode the correct stream. FFmpeg can help with this situation:. This command copies the video stream from input. The -c flag is really powerful. The prior example can be applied to both the audio and video streams, allowing you to convert from one container format to another without having to do any additional stream encoding:.
Now that we have a handle on the codecs, the next question is: How do we set the quality of each stream? The simplest method is to change the bitrate, which may or may not result in a different quality. Humans' ability to see and hear isn't as clean and clear cut as we'd like to think. Sometimes changing bitrates makes a huge difference to the subjective quality.
Other times it might do nothing but change the file size. Sometimes it's very difficult to tell what will happen without trying it out. To set the bitrate of each stream, you use the -b flag, which works in a similar fashion to the -c flag, except instead of codec options you set a bitrate.
This will copy the audio -c:a copy from input. Another way we can impact quality is to adjust the frame rate of the video using the -r option:.
This creates a new Matroska with the audio stream copied over and the video stream's frame rate forced to 30 frames per second, instead of using the frame rate from the input -r You can also adjust the dimensions of your video using FFmpeg.
You will see some letters next to the codecs: Codecs: D Marek Sebera You can see the list of supported codecs in the official documentation: Supported video codecs Supported audio codecs. Sign up or log in Sign up using Google. Sign up using Facebook.
Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile.
Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.
0コメント