# FFMPEG An Intermediate Guide/formats

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), Ogg (.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.
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.
You can also cut out and convert a part from a multimedia file. This can be useful for extracting and compressing a track from a raw (PCM) audio CD rip file which contains multiple songs.
In this example, an audio track is extracted by specifying the codec (-c:a pcm_s16le PCM 16-bit little-endian), the start time within the source file -ss 1615.3, the length of the excerpt to extract which contains the track -t 279, the source file name -i RawAudio-example.bin, and an example output file name Track-6.ogg.

## Batch conversion

While ffmpeg lacks a native batch conversion feature, a for loop command can be used. For example, the following command converts all wavesound files in the working directory to the OGG format:
The file extensions are automatically detected by the FFMPEG tool. Note that the command is case-sensitive.

## References

* ↑ Stream Copy in FFmpeg's documentation.