< FFMPEG An Intermediate Guide

Ever wondered how an MP3 file can tell you what the name of the song is and who made it? Well, there's a reason for that, and it has to do with how MPEG designed the format. It can handle metadata, called ID3 tags that MP3 players would read from the format, all while playing the music from a codec. Formats are also commonly called file formats, container formats, or containers. Some examples for video include Advanced Systems Format (ASF), Audio Video Interleave (AVI), and MPEG-4 Part 14 (.mp4), {{w|Ogg||, and Matroska (.mkv).

To understand how codecs are used in formats, you can look to commercial DVDs and Blu-Ray Discs produced and sold in countries where multiple languages are spoken by many people. The back of the case usually explains that the disc has two different audio tracks; one in the primary language of the country, and the other in a second language or the original language if the content is dubbed. Alternatively, some major studios publish movies with mastered audio for 5.1 and Stereo speaker setups, or they may provide an audio description or visually impaired consumers. Whatever the case, most DVD players have the ability to change between these tracks on-the-fly, and if not automatically, the studio will usually provide a way for people to navigate to an options menu in the DVD and pick it before playing the movie. The same goes for subtitles.

With the right software, these tracks can be completely isolated from each other in a process known as demuxing, and it shouldn't be much of a surprise that FFmpeg is one of those programs. It can do both demuxing and decoding as one of the capabilities of a multimedia tool. Consult the general documentation for the list of codecs supported by FFmpeg.

Formats

FFmpeg uses a library called libavformat to interact with formats. Some formats have default codecs and settings that you don't have to set yourself. This is why ffmpeg -i input -o output works without any specific flags.

Codecs

FFmpeg uses a library called libavcodec to interact with codecs. Much like formats, some codecs have default settings that you don't have to set yourself.

Stream copying

It's possible to transfer codecs between formats without having to reencode streams.[1]

ffmpeg -i input -acodec copy -vcodec copy -o output

While this does allow subtitles to be added on top of existing video codecs, it also means you sacrifice support from media players. Depending on the format you're switching to, you may need to reencode.

References

  1. Stream Copy in FFmpeg's documentation.
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.