TELECINE, INTERLACING, AND MENCODER HOWTO Initial (DRAFT 1) version by Corey Hickey, 2004-01-03. Missing stuff: 1. How to use -vf filmdint (I haven't used it yet, and don't describe it). 2. When (if) detc is more suitable than ivtc. 3. How to deal with non-standard telecine that doesn't follow PPPII,PPPII,... 4. The option of using -vf tfields for interlaced video. I can't make it work. 5. Pros/cons of each deinterlacing filter. Notes: 1. Right now this document only applies to NTSC DVDs, and not PAL. 2. The example mencoder lines throughout the document are NOT intended for actual use. They are simply the bare minimum required to encode the pertaining video category. How to make good DVD rips or fine-tune lavc for maximum quality is not within the scope of this document. *******************************Introduction********************************* I suggest you visit this page if you don't understand much of what is written in this document: http://www.divx.com/support/guides/guide.php?gid=10 The above URL links to an understandable and reasonably comprehensive description of what telecine is. For technical reasons pertaining to the limitations of early television hardware, all video intended to be displayed on an NTSC television set must be 59.94 fields per second. Made-for-TV movies and shows are often filmed directly at 59.94 fields per second, but the majority of cinema is filmed at 24 or 23.976 frames per second. When cinematic movie DVDs are mastered, the video is then converted for television using a process called telecine. On a DVD, the video is never actually stored as 59.94 fields per second. For video that was originally 59.94, each pair of fields is combined to form a frame, resulting in 29.97 frames per second. Hardware DVD players then read a flag embedded in the video stream to determine whether the odd- or even-numbered lines should form the first field. Usually, 23.976 frames per second content stays as it is when encoded for a DVD, and the DVD player must perform telecining on-the-fly. Sometimes, however, the video is telecined _before_ being stored on the DVD; even though it was originally 23.976 frames per second, it becomes 59.94 fields per second, and is stored on the disk as 29.97 frames per second. When looking at individual frames formed from 59.94 fields per second video, telecined or otherwise, interlacing is clearly visible wherever there is any motion, because one field (say, the even-numbered lines) represents a moment in time 1/59.94th of a second later than the other. Playing interlaced video on a computer looks ugly both because the monitor is higher resolution and because the video is shown frame-after-frame instead of field-after-field. ********************How to tell what type of video you have******************** --Progressive-- Progressive video was originally filmed at 23.976 fps, and stored on the DVD in the same way. When you play a progressive DVD in mplayer, mplayer will print the following line as soon as the movie begins to play: demux_mpg: 24fps progressive NTSC content detected, switching framerate. >From this point forward, demux_mpg should never say it finds "30fps NTSC content." When you watch progressive video, you should never see any interlacing. Sometimes progressive video is referred to as "soft-telecine" because it is intended to be telecined by the DVD player. --Telecined-- Telecined video was originally filmed at 23.976, but was telecined _before_ it was written to the DVD. Mplayer does not (ever) report any framerate changes when it plays telecined video. Watching a telecined video, you will see interlacing artifacts that seem to "blink": they repeatedly appear and disappear. You can look closely at this by (a) running `mplayer dvd://1 -speed 0.1' (b) seeking to a part with motion (c) looking at the pattern of interlaced-looking and progressive-looking frames. If the pattern you see is PPPII,PPPII,PPPII,... then the video is telecined. If you see some other pattern, then the video may have been telecined using some non-standard method and mencoder cannot losslessly convert it to progressive. If you don't see any pattern at all, then it is most likely interlaced. Sometimes telecined video is referred to as "hard-telecine". --Interlaced-- Interlaced video was originally filmed at 59.94 fields per second, and stored on the DVD as 29.97 frames per second. The interlacing is a result of combining pairs of fields into frames, because within each frame, each field is 1/59.94 seconds apart. As with telecined video, mplayer should not ever report any framerate changes when playing interlaced content. When you view an interlaced video closely with `mplayer dvd://1 -speed 0.1', you will see that every single frame is interlaced. --Mixed progressive and telecine-- All of a "mixed progressive and telecine" video was originally 23.976 frames per second, but some parts of it ended up being telecined. When mplayer plays this category, it will (often repeatedly) switch back and forth between "30fps NTSC" and "24fps progressive NTSC". Watch the bottom of mplayer's output to see these messages. You should check the "30fps NTSC" sections to make sure they are actually telecine, and not just interlaced. --Mixed progressive and interlaced-- In "mixed progressive and interlaced" content, progressive and interlaced video have been have been spliced together. This category looks just like "mixed progressive and telecine", until you examine the "30fps" sections and see that they don't have the telecine pattern. ************************How to encode each category************************* As I mentioned in the beginning, example mencoder lines below are NOT meant to actually be used; they only demonstrate the minimum parameters to properly encode each category. ---Progressive--- Progressive video requires no special filtering to encode. The only parameter you need to be sure to use is -ofps 23.976. Otherwise, mencoder will try to encode at 29.97 fps, and duplicate frames. $ mencoder dvd://1 -nosound -ovc lavc -ofps 23.976 --Telecined-- Telecine can be reversed to retrieve the original 23.976 content, using a process called inverse-telecine. Mplayer contains two filters to accomplish this: detc and ivtc. You can read the manual page to see their differences, but for DVDs I've never had a problem with ivtc. Note that you should _always_ inverse-telecine before any rescaling; unless you really know what you're doing, inverse-telecine before cropping, too. Again, -ofps 23.976 is needed too. $ mencoder dvd://1 -nosound -vf ivtc=1 -ovc lavc -ofps 23.976 --Interlaced-- It is not possible to retrieve a complete progressive video from interlaced content without losing half of the vertical resolution. Unless you are downscaling to smaller than 1/2 of the original size, you have two choices: 1. Encode the video in interlaced form. Normally, interlacing wreaks havoc with the encoder's ability to compress well, but lavc has an ildct parameter for dealing with storing interlaced video a bit better. Note that -ofps is NOT needed here. $ mencoder dvd://1 -nosound -ovc lavc -lavcopts ildct 2. Use a deinterlacing filter before encoding. There are several of these filters available to choose from, each with its own advantages and disadvantages. Consult mplayer -pphelp to see what's available (grep for "deint"), and search the mplayer mailing lists to find many discussions about the various filters. Again, the framerate is not changing, so no -ofps. Also, postprocessing should be done after cropping and before scaling. $ mencoder dvd://1 -nosound -vf pp=lb -ovc lavc -- If, however, you plan on downscaling dramatically, you can use the il filter to separate the two fields, and only encode one. Of course, you'll lose half the vertical resolution, but if you plan on downscaling to at most 1/2 of the original, the loss won't matter much. The result will be a progressive 29.97 frames per second file. Here's the procedure. You can apply each filter with mplayer first to test, before encoding. 1. Use il=d:d to separate the two fields. 2. Use -vf crop to extract either field (without any surrounding black bars, of course). 3. Scale appropriately. First divide the cropped horizontal resolution by two, and then adjust the scaling parameters to maintain the original aspect ratio and to make the resolutions divisible by 16. How to do the latter part is described in other documents. $ mencoder dvd://1 -nosound -vf il=d:d,crop=718,180:0:30,scale=308:180 -ovc lavc ---Mixed progressive and telecine--- In order to turn mixed progressive and telecine video into entirely progressive video, the telecined parts have to be inverse-telecined. There are two filters that accomplish this natively: pullup and filmdint. Pullup doesn't really work well with the current mencoder, and is intended for use with mencoder G2 (whenever it's ready). Filmdint TODO: DESCRIBE FILMDINT (I haven't used filmdint yet, but it ought to be good) Another, currently very reliable, method is to, rather than inverse-telecine the telecined parts, telecine the non-telecined parts and the inverse-telecine the whole video. Sound confusing? softpulldown is a filter that goes through a video and makes the entire file telecined. If we follow softpulldown with either detc or ivtc, the final result will be entirely progressive. Cropping and scaling should be done after the inverse-telecine operations, and -ofps 23.976 is needed. $ mencoder dvd://1 -nosound -vf softpulldown,ivtc=1 -ovc lavc -ofps 23.976 --Mixed progressive and interlaced-- There are two options for dealing with this category, each of which is a compromise. You should decide based on the duration/location of each type. 1. Treat it as progressive. The interlaced parts will look interlaced, and some of the interlaced frames will have to be dropped, resulting in a bit of uneven jumpiness. You can use a postprocessing filter if you want to, but it may adversely affect the progressive parts. 2. Treat it as interlaced. Some frames of the progressive parts will need to be duplicated, resulting in uneven jumpiness. Again, deinterlacing filters may degrade the progressive parts. END OF FILE