# codec vs file format



## Caleb11

hi,

what is the difference of codec and file format?
i know the basic but it's not enough to understand the two.

thanks.


----------



## ebackhus

Say you have a file called funny.avi. AVI is the container format, but does not dictate what codec was used. H264, XviD, and many other codecs could have been used to create the file.


----------



## zuluclayman

to expand a little on what Koala says - the file format tells you which type of container the file uses as a transport medium. This may be avi (Audio Video Interleaved) or .mpg, .mov etc. This determines the way the information is stored and delivered. 
The codec (*Co*mpression *Dec*ompression) is the algorithms used to firstly compress the video information then as you want to play it to decompress the information - a little bit like going on holidays - you get your clothes, squash them down to fit in your suitcase down then unpack again.
Video files (and to a much lesser extent audio files) are huge if uncompressed - just imagine how much information is needed to describe the position, colour, size etc of every pixel for every frame of a video! then add the audio stream and you would have massive file sizes, making it almost impossible to store and/or transport (either to have as portable files or as in streaming or downloading from the net) these files.
Codecs, to a large extent, determine the file size end quality of the video you watch. If some of the older codecs are used they will not have been able to bring the file size down and retain quality.
The newer codecs such as xVid, DivX, H.264 are able to bring file sizes down dramatically while keeping fairly high quality video - this allows us to store, transport, stream and download high quality video much, much more easily than ever before.

Hope this helps :grin:


----------



## blah789

container = wrapper (file format)
inside it you can have various streams (usually audio and video, but you could have multiple audio streams (diff languages), subtitles, or other kind of streams)
codec = compressor-decompressor. like previous poster said, uncompressed video is HUMONGOUS. a codec shrinks that data to a manageable size, and unshrinks it back when playing back. (I like the suitcase analogy).

and yes it's possible to put the same audio and video data in different containers. that's what lossless transcoding does. it rips the audio and video streams, and repackages them in a different container, without any loss of quality.
Note: The resulting file may or may not be playable, depending on the container/codec support. Some companies deliberately make their codec explicitly available to work only in one or a few containers (perhaps to protect their intellectual property) - for example Sorenson Video is designed to work in MOV only. And some codecs don't work well (or at all) in some containers (for instance H.264 in AVI - supposedly uses ugly tweaks, and doesn't work all the time).


----------



## Caleb11

hm! these info are really helpful.

what about the quality of data, does it depend on the codec or on the file format?


----------



## blah789

almost entirely on codec. that's what affects the compression-to-quality ratio of the audio and video streams. container's just a wrapper (like the wrapping around your xmas presents).
you can sometimes hear about raw stream dump. that's when a programmer grabs a stream out of a media file and puts it in another file, but doesn't wrap it in any container. it'll just be raw data (could be audio or video), but it hasn't been packaged.
if it helps, you can think of one of the main roles of the container is to synchronize things. it makes sure the video, audio, (and maybe subtitle) streams are played with correct timing (could be multiple audio streams in various languages, such as in your VOB files on DVD's).

however as mentioned, sometimes you can't put certain codecs in certain containers (or with great difficulty, or without playable results)

sometimes the choice comes down to portability (can you play the file format/container on a windows, a mac, or a unix machine)

some containers are better for streaming, but may contain more overhead because of that. others are leaner. others can contain just about anything you can put into them, including the kitchen sink (matroska/mkv).


----------

