PapaJohn Productions

Newsletter #191
2008 - About Codecs - Part 2 of ??
Uncompressed and DV-AVI

You've heard it many times... a 'codec' is to compress and/or decompress a file. It's easy to say but doesn't go very far in helping you understand the practical things about what's happening. Why do we need compression? Why are there so many codecs?
The reason for compression is simple... uncompressed video files are too large to move around easily or play smoothly. That was so even before we got into streaming them from online places like YouTube, which need even more compression.
CDs, DVDs, and camcorders can only transmit data in real time at certain bitrates, as set by standards. TV is also limited by transmission standards.
To illustrate it, this week's sample video is a tiny video... a tad over 5 seconds in length... made in Movie Maker 2.1 using a title clip fading into a still picture. Here's the beginning, middle, and ending.
I saved the project to a DV-AVI file. For most home video editing that's the highest quality file we can easily edit and go through generations of renderings without losing quality at each step. I used that as the source file for 4 other test files, two of them larger uncompressed files, and two smaller ones with lossy compression.
Some do their video editing work with uncompressed files, doing the compression at the last step when saving the movie. Here's the list of 5 test files sorted by size from the biggest to the smallest... each is 153 frames... 5 seconds long.
You can see from this file list that the Best WMV file for my HP Pavilion zd8000 laptop weighs in at 3% the size of the DV-AVI file. My current rule of thumb for videos I upload to my website for online viewing is to use ones of 768 kbps, even smaller files. Anything larger risks choppy uneven playback.

The smaller ones are made by using 'lossy compression'... something in the way of quality is removed in a way you hopefully won't notice.
YouTube knocks the quality down to even smaller files... one quality hit is stereo WMV files uploaded coming back as mono flash files.

Hardware and software that make or play video files use codecs... built into the hardware circuitry like in a camera or capture device... or contained in any of hundreds of little pieces of software on your computer. The interplay among software and codecs often result in weird video editing or viewing results, or clashing and crashing.

Let's explore uncompressed and DV-AVI files in this issue and leave the subject of lossy compression for future issues.
... before going into details, here's...
a note...

The March edition of Videomaker magazine has a six page article about 'Formats and Codecs'...
One table shows DV as being 'lossy'... the article says '...DV, which is unique in that its compression is particularly gentle (... processing-wise... ).... the reason any computer editing DV can perform editing operations so quickly is that all compression on DV is performed intra-frame, so each frame stands alone. You can perform any cut cleanly, and dissolves take a minimum of processor power to execute....".
The article isn't any easier to read than this newsletter series, but it's good to have some company in trying to cover the topic.
... back to the main subject  

Uncompressed Video Files 
You might think a benefit of using uncompressed files would be not having to be concerned about codec issues. Let's see what GSpot says about the video codec...
UncompressedAVIFor the uncompressed AVI file made by VirtualDub, GSpot provides some video codec info and says 'No Codec Required'.
Uncompressed WMVFor the uncompressed WMV file, GSpot provides different video codec info, and also says 'No Codec Required'.

Maybe so, but we soon run into codec-related issues.
Windows Media Player opens and plays the uncompressed AVI file fine. The WMV file is heard but not seen. I didn't find any tool on my XP computer that could play the video portion of the uncompressed wmv file.
Movie Maker Can't Handle the Uncompressed File it MadeMovie Maker 2.1 imports, previews and uses the uncompressed AVI file.
... but it doesn't know how to handle an uncompressed WMV file, even though it just finished making it.
It's surely related to codecs, but in this case it's in the programming of Movie Maker, not in how the codecs are working or not.
When Movie Maker opens a WMV file it checks to see what codec it should use.. It considers the option of having an uncompressed AVI file, but not an uncompressed WMV.
On my Vista Ultimate SP1 system, the uncompressed WMV plays completely but not smoothly in Windows Media Player, and imports into Movie Maker 6... where it goes through the motions of playing but isn't seen or heard when previewing in the collection or on the timeline.

DV-AVI files
I keep mulling over how to categorize them. At the moment I consider them 'losslessly compressed'... obviously much smaller than uncompressed AVI or WMV files.... and maintaining their original quality through as many editing generations as I want to take them. 
Movie Maker 1 makes type II DV-AVI files, while MM2 and higher make type I. The type II files are a bit larger in file size as they have an extra audio track.
I used to think all DV-AVI files were the same... until I started using the Panasonic and Canopus DV codecs in addition to the Microsoft one that comes with Windows.
DV-AVI files are 'frame-based'. All info about each frame is self-contained in the file... it reminds me of my old film-based videos, where each frame was self-contained. I could see the analog frames with a magnifying glass, each one being a little picture. I can see each digital frame, but they look like computer code rather than little pictures.
The compression codec makes the video file.... packing it with code ready for any decompression codec that wants to try putting the pieces back together in a viewable way.

Opening a DV-AVI file
The decompression codec reads the code in the video file and translates it into smoothly playing frames. If one codec can't do it right, then another might. The packaging and the unpacking obviously needs to be coordinated. Sometimes your system doesn't have a codec that can read the code, and sometimes it does a poor job of trying... and you have an issue related to codecs.
To play a DV-AVI file, I can
Running down my current list, the DV-AVI file...
GSpot - DV-AVI

a DV-AVI file in Notepad
Notepad is on the list because I sometimes use it to look at video files. Not being a programmer, it's just a bunch of code to me... but liking puzzles, I enjoy hacking information that I don't yet understand.
It starts with a section of code I'll call the file header. The first tidbit of data says RIFF. The link takes you to a Wikipedia page that says it stands for Resource Interchange File Format, a format for storing data in chunks. RIFF was introduced by Microsoft in 1991. The page says the first four bytes of a correctly-formatted RIFF file will spell out "R", "I", "F", "F". This one does.
AVI Header
I don't want to go too deeply into what I don't understand. Hopefully just enough to help you understand codecs in general.
After the header comes lots of white space followed by this section. The Wiki page says: Two chunk identifiers, "RIFF" and "LIST", introduce a chunk that can contain subchunks. Here's the beginning of the LIST section.
After more white stuff comes the code for the individual frames. The sample file has only blackness at the beginning as the title fades in so the code for the beginning of this first frame is what's needed to color the frame black.
Start of Frame Info
Jumping to the part of the title clip that is blackness with a little white lettering looks similar... and it should as the frames are mostly still black. 
Title Clip
The bridge clip is more complex... here's the end of one frame and the beginning of the next at about the mid-point of the scene that shows the Golden Gate. The only thing I understand when looking at the code this way is the line between frames... that's the place I used to cut at when using a razor blade to edit film. 
Bridge Clip
One more snapshot... what does the end of the file look like? It's an index to each of the frames (or half-frames as DV-AVI files are interlaced). 
When I get a DV-AVI file that has problems I check to see if the index section is there... if not, the file is incomplete and can't be used. The decompressor has to use the index to recreate the file. A file missing an index can't be played.
VirtualDub has a feature to rebuild the index of an AVI file with missing frames or index. Movie Maker doesn't have such a feature.
That's a peek into the code of this 5 second DV-AVI file.

a WMV file in Notepad
Different file types and codecs use different code... the best WMV choice for my computer opens with this code... no RIFF up front and no index at the end. It's different coding.
Here's the header of the uncompressed WMV file... in case you want to compare it to the compressed one.
Uncompressed WMV file... header

Conclusion and Closing... and What's Next?
Most users don't care why or how codecs work. They just want to easily make, edit and watch videos. When they run into an issue related to codecs, someone else can and will resolve it for them. If not, then it's time to make some popcorn and turn on the TV.
I'm glad my subscriber base is mostly of experienced users.
I thought that by keeping things on the surfacy level, I'd have room to get into at least an introduction to lossy compression, but I didn't make it. When exploring the nooks and crannies of video I always end up with two more questions for each one answered.
A couple new questions are...
  • why is an uncompressed AVI file just about exactly double the file size of uncompressed WMV? Is it because I started with DV-AVI which is interlaced, which means it is two half-frames for each frame, while WMV files are deinterlaced?
  • what happened in Vista so the uncompressed WMV file plays in the same version of WMP as on my XP system, and imports into Movie Maker 6?
Have a great week....