FFMPEG An Intermediate Guide/formats

From Wikibooks, open books for an open world
< FFMPEG An Intermediate Guide
Jump to: navigation, search

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), wikipedia: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 for 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[edit]

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[edit]

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[edit]

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[edit]

  1. Stream Copy in FFmpeg's documentation.