http://www.dogphilosophy.net/SECTION-Technical_Stuff/linuxvid.html
Some time ago, I discovered VCD's. These are, essentially, VHS-resolution DVD disks that use plain old CD media. While they ARE lower resolution than DVD's, and the CD media limits the amount of video that will fit on one disk (about 70-80 minutes), VCD's seem to have a lot to recommend them. For one thing - the MPAA isn't likely to try to have me thrown in jail for daring to watch them on an "unsanctioned" player (though nearly all of their "sanctioned" standalone DVD players will, on the other hand, play VCD's as well). For another, I can make them myself, giving me a sturdier standard media format to store home videos or "space-shifted" (the - completely legal! - act of transferring a legal copy of something to another media for personal use, such as making a cassette recording of a CD you've purchased) or "time-shifted" (the - completely legal! - act of having your VCR or whatever record a show for you to watch later) legal copies of commercial VHS tapes that I've purchased. Since nearly all DVD players can handle VCD's, this makes a convenient format to inflict "home movies" and such on friends with, who need not have a computer to view them.
But enough ranting for the moment. I attempted to find out how to make VCD's on my Linux box. Unfortunately, while I did find some documentation describing the process, said documentation tended to remind me of Steve Martin's old "How to be a millionaire and never pay taxes" skit on Saturday Night Live ("First, get a million dollars. THen…") - in other words, the documentation covered the easy part - taking an already-vcd-formatted mpg file and making a physical vcd out of it. I had little luck finding documentation on how to produce VCD-formatted video files in the first place, so other than being able to back up the handful of commercial VCD's I'd purchased, there wasn't much else I could do with it.
Time passed. After a fair bit of experimentation, I finally have a working start-to-finish procedure for generating useable video files and VCD's on Linux, so I thought I'd share with the rest of the interested world (all 3 of you.) In the process, I'll also try to describe how to generate even lower bitrate (but still watchable) video files which might be carried on data CD's for personal viewing on, say, a laptop computer while on vacation or a business trip.
Ingredients:
To make your videos on Linux, you'll need the following materials:
Getting video data to work with
There are, basically, three sources of video to work with:
Existing video files
There are a number of video file formats and codecs that can be dealt with using Linux-based tools. File formats include (but are not necessarily limited to):
Codecs for video are fairly numerous, but the primary ones I've played with are:
A brief digression on MPEG4 as I understand it:
There are a few variations of "mpeg4" floating around. There is Microsofts particular version, there is a "hacked up" form of this called "Divx ;)" for non-microsoft platforms, there is an "OpenDivx" (which actually isn't all that open but is available for most platforms free of charge), and there is a reimplementation of OpenDivx in ffmpeg. I've not experimented to find out how interoperable or compatible they are. Note "Divx;)" is not to be confused with the pathetic failure known as "DIVX", which was a scheme by several corporations to push a restrictive "pay-per-view" rental format on consumers, which rapidly bombed.
Effectively, the differences between the video codecs are tradeoffs between picture quality, CPU-intensiveness, and compression. Any compression done by the video codec will (generally) result in a loss of picture quality and detail to some degree. More processor-intensive codecs tend to lose less detail for the same amount of compression.
Mpeg1 is the older mpeg video codec. It is also the format expected by vcd's (at a specific size and bitrate.).
Mpeg2 is a somewhat more recent successor. DVD video data is Mpeg2, encrypted so that you can't play it on a video player that the MPAA doesn't want you to, and so that they can sell the same video separately in different "regions" (i.e. so that Australians can't mail-order DVD's from the US, and instead end up paying more for the "Australian region" version.).
mjpeg, as I understand it, is just a series of jpeg images, each representing a frame. Flavors of mpeg generally have frames inserted that are generated by a "motion estimation" algorithm, which smooths the transitions between individual frames, but doing motion estimation takes additional cpu power. It is probably not TOO innaccurate to think of mjpeg as being more-or-less "mpeg without motion estimation". (More details on the differences as I figure them out later…)
RealVideo actually comes in a number of versions, but the only RealVideo-generating tool I've worked with (ffmpeg) only deals with version 1. RealVideo is often regarded as low quality, but then, it's also frequently used to generate very-low-bitrate video (for downloading or watching over modems, etc.), which will NECESSARILY result in low quality. Rumor has it that flavors of mpeg4 are better for low bitrate video now, though.
"Raw" video just refers to unprocessed, uncompressed video frames. As one might imagine, such a video format takes up a HUGE amount of space, but requires the least CPU power to handle. On the other hand, the amount of data being written like this can actually be generated faster than the hard drive can write it!
For my purposes, I generally do one of two things: I either capture directly to mpeg1 VCD (when I'm feeling impatient and don't want to reprocess later) or I capture as an mjpeg avi file and re-encode it into whatever formats I want later.
Direct Capture: Direct capture, using a video capture card, is the most versatile option. Consumer-grade video-capture cards are relatively inexpensive. I'm using one of the ironically-named "WinTV" cards from Hauppage for my video capture. At the base, though, direct capture is fundamentally just a way of obtaining "An already-existing video file in a useable format"
Direct capture does present a few additional technical hurdles to overcome, but they're not too difficult. Activating direct capture capability just requires a few additional kernel drivers to support. You need:
The main software tools I use for video watching and/or capture are the XawTV package and ffmpeg. XawTV includes X11-based software for "watching tv" (i.e. the input from the capture card in realtime) as well as capturing, and a program named "streamer" which is a command-line tool for video capture.
FFMPEG is still "beta" quality, but quite usable. It is used to convert video from one format (including direct capture from the video capture device) to another. It can handle a number of different file formats and codecs and convert between them.
It is possible to directly capture to the final format you want, but this will generally require a high-powered CPU. On my current system, an AMD "Thunderbird" 1.2Ghz, I am able to capture directly to VCD-style MPEG1 files in realtime, with "moderate" motion estimation.
The summary of the process I use to create video is:
The frame rate (29.97 in this example) and the image size (352x240 in this example) may vary depending on the type of video you are trying to create. The size and frame rate in the example above is specifically for NTSC (North America) VCD. PAL (European) is 25 frames/second at 352x288.
If you are generating video for "computer" consumption and don't care about being able to play the videos on a standalone DVD player, your options for size, frame rate, and bitrate vary considerably.
Bitrate is the sole factor in determining file size (and, consequently, how fast your internet connection has to be to view the file in "real time"). You could, quite likely, take a 720x480x29.97fps (DVD quality - up to 9600k/s!) video and try to recode it at the same size and framerate to, say, 40k for viewing over a 56k modem link, but you'd just end up with an unrecognizable changing multicolored blotch for video because the encoder would have to throw out so much data to fit that much video into that small size. In short, there are three things you can "throw out" to reduce the amount of data lost in the encoding step.
If you want to fit a certain amount of video onto a certain amount of media space, just calculate what bitrate you need to be constrained to in order ot fit. On ordinary (640MB) CD-R: ~4200 seconds * (1150k/s+224k/s) = 5770800 kb. (that's video plus audio - VCD audio is 224k/s mp2.) So to fit, say, a regular 90-minute video onto a single CDR as a video data file will require a combined bitrate of: 5770800 / (90*60) = about 1068k/s between both the audio and video. Note that despite the hype of promotors and the rabid fear of MPAA lawyers, transcoding DVD video to a smaller format to fit on a single CD-R WILL result in a noticeable loss of quality - Mpeg4 may not be as bad as "1/9th" the detail in the 9600k mpeg2 DVD video, but there is absolutely no physical way to compress data that much without noticeable loss of quality. Of course, if you just want a backup copy of a favorite movie to watch while travelling, the loss of quality may not be an issue (certainly it IS possible to produce "watchable" video at these bitrates.)