Answers.Body: <p>The basics of that are actually not that complicated (while there is definitely more to know about that topic than would fit in this answer).</p>
  
  <p>Take a look at that graphic you can find on the <a href="http://w3.org" rel="noreferrer">w3c-website</a>:</p>
  
  <p><img src="https://i.sstatic.net/tAdMw.png" alt="Containers and file formats graphic"></p>
  
  <p>As you can see, the container is exactly that: a container that can contain different types of media, most notably video and audio, but also captions and metadata about the file. When you speak about a "file format", you're normally talking about the container format, after which the file extension for normal video files is named. This is why you've probably seen many video files with file extensions such as <code>.avi</code>, <code>.mp4</code>, <code>.mkv</code> and the likes.</p>
  
  <p>When you look at the contents of this container, you will normally have at least one video and one audio track, those are referred to as "streams". Streams can be encoded using different codecs. A codec is, in layman's terms, an algorithm (or rather a set of algorithms) which is used to compress a (video or audio) stream. The more efficient the codec, the better the ratio of (video/audio) quality to file size. Two very common codecs are the H.264 (MPEG-4/AVC) codec for video and the AAC codec for audio. Those are popular because they are very efficient, thus you can have very small files with (relatively) good quality.</p>
  
  <p>So to sum this up, the container is some sort of "wrapper" that contains the actual media streams. Different container formats allow for different kinds of streams. For example, the <code>.avi</code>-container is very limited, you can only have one audio stream and one video stream. The <a href="http://www.matroska.org/" rel="noreferrer">matroska-container</a> (<code>.mkv</code> files) is a good alternative if you need more than that. Matroska is a very flexible container that allows for multiple audio streams (e.g. for different languages), subtitles and more. However, many devices (e.g. most TVs with a USB port) don't support that standard. This is where the <code>.mp4</code>-container (MP4 being the standard-container for the <a href="https://de.wikipedia.org/wiki/MPEG-4" rel="noreferrer">MPEG-4-standard</a>, which is a huge topic on it's own) comes in handy, because nearly all devices can playback files that use this container format along with the H264 &amp; AAC codecs. This combination is the most common approach for easily interchangable video files, which for example is used by most video hosting platforms such as Youtube.</p>
  
  <p>Changing the file extension is generally a stupid idea. If you change an <code>.avi</code> file to something like <code>.mp4</code>, it might work on your TV in some instances, but that is just because your TV is stupid (i.e. it knows the codecs of the streams, but doesn't even try to play them if it doesn't recognise the file extension or something like that). Container format's don't behave like text-files, you can't just change the extension and expect the container format to somehow magically change as well. If you can't open a specific video file, use the <a href="http://www.videolan.org/vlc/" rel="noreferrer">VLC video player</a>, it supports most commonly used file formats and codecs. If you want/need to watch it on a specific device such as your TV which doesn't support the codec, you can re-encode it (not a good idea, because that means quality loss) or remux it, i.e. take the individual streams and put them in different containers (which is a bit more complicated but yields better results).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-23T21:20:22.557Z
Answers.Text: Thank you so much! That makes a lot more sense and removes the mystery of container files so I can understand what's going on in future
Answers.UserDisplayName: Bendy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-01T06:56:52.370Z
Answers.Text: such an answer, much wow  (y)
Answers.UserDisplayName: kmonsoor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-23T20:26:55.313Z
Answers.LastActivityDate: 2015-06-23T20:26:55.313Z
Answers.UserDisplayName: MoritzLost
Body: <p>So far I have been guessing my way through the types of audio/video streams and getting them mixed up with containers. For example, I have had a friend tell me that a video file which won't play on my TV will work if I can change the file extension to <code>.avi</code>/<code>.mpg</code> for example - which worked. However, when I have had the problem since, I have tried the same but with no luck.</p>
  
  <p>Could someone explain which are containers and how you can have different types of audio/video files/steams within a container file?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-23T19:10:34.157Z
Comments.Text: Have you done any research on this topic? One place to start is https://en.wikipedia.org/wiki/Comparison_of_video_container_formats
Comments.UserDisplayName: Jim Mack
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-24T03:26:00.657Z
Comments.Text: Also see this in-depth answer on Super User: [What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?](http://superuser.com/a/300997/110524)
Comments.UserDisplayName: llogan
Tags: <video><file-formats>
Title: How are video and audio streams placed in 'container' files and what interrelations do they have?
UserDisplayName: Bendy
ThreadText: # How are video and audio streams placed in 'container' files and what interrelations do they have?
  
  (Asked by: username_0 on 2015-06-23)
  
  So far I have been guessing my way through the types of audio/video streams and getting them mixed up with containers. For example, I have had a friend tell me that a video file which won't play on my TV will work if I can change the file extension to `.avi`/`.mpg` for example - which worked. However, when I have had the problem since, I have tried the same but with no luck.
  
  Could someone explain which are containers and how you can have different types of audio/video files/steams within a container file?
  
  **Tags:** video, file-formats
  
  > **Comments:**
  > **username_1**: Have you done any research on this topic? One place to start is https://en.wikipedia.org/wiki/Comparison_of_video_container_formats  
  > **username_2**: Also see this in-depth answer on Super User: [What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?](http://superuser.com/a/300997/110524)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2015-06-23. Score: 7 | Accepted answer
  
  The basics of that are actually not that complicated (while there is definitely more to know about that topic than would fit in this answer).
  
  Take a look at that graphic you can find on the [w3c-website](http://w3.org):
  
  ![Containers and file formats graphic](https://i.sstatic.net/tAdMw.png)
  
  As you can see, the container is exactly that: a container that can contain different types of media, most notably video and audio, but also captions and metadata about the file. When you speak about a "file format", you're normally talking about the container format, after which the file extension for normal video files is named. This is why you've probably seen many video files with file extensions such as `.avi`, `.mp4`, `.mkv` and the likes.
  
  When you look at the contents of this container, you will normally have at least one video and one audio track, those are referred to as "streams". Streams can be encoded using different codecs. A codec is, in layman's terms, an algorithm (or rather a set of algorithms) which is used to compress a (video or audio) stream. The more efficient the codec, the better the ratio of (video/audio) quality to file size. Two very common codecs are the H.264 (MPEG-4/AVC) codec for video and the AAC codec for audio. Those are popular because they are very efficient, thus you can have very small files with (relatively) good quality.
  
  So to sum this up, the container is some sort of "wrapper" that contains the actual media streams. Different container formats allow for different kinds of streams. For example, the `.avi`-container is very limited, you can only have one audio stream and one video stream. The [matroska-container](http://www.matroska.org/) (`.mkv` files) is a good alternative if you need more than that. Matroska is a very flexible container that allows for multiple audio streams (e.g. for different languages), subtitles and more. However, many devices (e.g. most TVs with a USB port) don't support that standard. This is where the `.mp4`-container (MP4 being the standard-container for the [MPEG-4-standard](https://de.wikipedia.org/wiki/MPEG-4), which is a huge topic on it's own) comes in handy, because nearly all devices can playback files that use this container format along with the H264 & AAC codecs. This combination is the most common approach for easily interchangable video files, which for example is used by most video hosting platforms such as Youtube.
  
  Changing the file extension is generally a stupid idea. If you change an `.avi` file to something like `.mp4`, it might work on your TV in some instances, but that is just because your TV is stupid (i.e. it knows the codecs of the streams, but doesn't even try to play them if it doesn't recognise the file extension or something like that). Container format's don't behave like text-files, you can't just change the extension and expect the container format to somehow magically change as well. If you can't open a specific video file, use the [VLC video player](http://www.videolan.org/vlc/), it supports most commonly used file formats and codecs. If you want/need to watch it on a specific device such as your TV which doesn't support the codec, you can re-encode it (not a good idea, because that means quality loss) or remux it, i.e. take the individual streams and put them in different containers (which is a bit more complicated but yields better results).
  
  > **Comments:**
  > **username_0**: Thank you so much! That makes a lot more sense and removes the mystery of container files so I can understand what's going on in future  
  > **username_4**: such an answer, much wow  (y)  
  
  ---
  
  