Filters current Version:
Before we start, lets clear up the field a bit.
You DO NOT need any of the two filters (telecide and decimate) if you are working with "pure interlaced data" as opposed to "artificially interlaced data". In plain terms: You don't need these two filters AND YOU SHOULD NOT USE THEM if your source data are coming from:
Now that we've thrown away 90% of the readers, its time to describe what is this artificial interlacing we (might) meet in an NTSC DVD and why it requires special care.
As one might guess, American engineers had to interpolate. They also had to cope with the fact that TV isn't actually showing 29.97 frames per sec, but 2 x 29.97 fields per second. What are fields, you ask? Well, check this ASCII art:
scanline 0 --------------------------------- Field 0, 1st line scanline 1 +++++++++++++++++++++++++++++++++ Field 1, 1st line scanline 2 --------------------------------- Field 0, 2nd line scanline 3 +++++++++++++++++++++++++++++++++ Field 1, 2nd line scanline 4 --------------------------------- Field 0, 3rd lineetc...
As you can see, each frame is composed from two fields. Each of the fields has 240 lines, thus we finally get 480 scanlines. So, to display film content, which is 24 frames per second, this is what American engineers came up with:
Frame 1 Frame 2 ======= ======= Top Field of Frame 1 (T1) Top Field of Frame 2 (T2) Bottom Field of Frame 1 (B1) Bottom Field of Frame 2 (B2)Now, if we had a 24fps Television set, we could see any film easily, if we sent it the following sequence:
T1 B1 T2 B2 T3 B3 T4 B4 T5 B5 T6 B6 ... ====== ====== ====== ====== ====== ====== Frame1 Frame2 Frame3 Frame4 Frame5 Frame6Unfortunately, we have a stupid 29.97 standard, so this is what we send:
T1 B1 T2 B2 T2 B3 T3 B4 T4 B4 ... ===== ===== ===== ===== ===== N N A A NAs you can see, we have used fields from 4 film frames, but we have sent them in a way that produces 5 NTSC 'frames': 3 Normal (N) ones, and two Artificial (A) ones. The displaying is also slowed down, from 30 'frames' per sec to 29.97 fps.
You see it? These Artificial frames are horribly interlaced! And this interlacing has nothing to do with the normal interlacing found in PAL and NTSC cameras... This is a different monster.
Note that if you use one of transcode's deinterlacing filters with such a sequence, you'll probably get something like this:
T1 B1 T2 B2 T3 B3 T4 B4 T4 B4 ... ===== ===== ===== ===== =====... that is, two completely identical frames (IF the deinterlacing algorithm is good enough). And yes, when you encode your sequence to MPEG4 or whatever, you waste bandwidth for these extra frames. Not to mention, that a skilled eye will notice that the film is not natural - any motion will appear jerky, because of the duplicate frames.
Did I mention that this pattern shifts and jumps throughout the video? In other words, this scheme is not constant; Video editing is performed on fields, and if the DVD authoring studio deletes a series of fields in the middle of the film, the eventual field order is impossible to predict...
The recovery process (called IVTC - inverse telecine) is done in two steps, from two filters. The first one, called 'ivtc', tries to recreate the original film frames from the available fields. It doesn't remove the duplicate frames; this is done from the next filter, the 'decimate' one.
The algorithms used in these filters are the basic ones used in the 'Decomb' package (made by Donald A. Graft and available - unfortunately - only under Windows). Thanks for opening up the source, Donald!
First pass: transcode -M 0 -f 23.976 -i dolby-city.vob -x vob \ -y xvid,null \ -w 740 -J ivtc,decimate -V -o /dev/null -R 1 -B 6,13,16 Second pass: transcode -M 0 -f 23.976 -b 64 -i dolby-city.vob -x vob \ -y xvid,ogg \ -w 740 -J ivtc,decimate -V -o test.avi -R 2 -m test.ogg \ -B 6,13,16Adding video and audio together in an Ogg stream (you'll need ogmtools):
ogmmerge -o dolby-city.ogm test.avi test.oggSome explaining:
-w 740 Target video bitrate is 740000 bits per second -B 6,13,16 Resize from NTSC 720x480 to 512x384 (4:3 aspect) -M 0 -f 23.976 it means that the demux must not drop frames on its own; the filters will do that, producing a 23.976 frames per sec result. -J ivtc,decimate Always use them in this order, and with no other filter before them - especially no deinterlacing and no resizing one!
Additionally, when the telecine pattern shifts (as a result of, maybe, field editing by the DVD authors) a couple of interlaced frames will pass through. These should be deinterlaced on their own. You shouldn't use global deinterlacing after ivtc - it would blur out the otherwise perfect progressive frames that get reconstructed from 'ivtc'. However, transcode's '32detect' filter comes to the rescue: It first checks whether the frame is interlaced, and only then it forces a frame deinterlacing. So, this is what I recommend for your sessions:
transcode -M 0 -f 23.976 \ -J ivtc,32detect=force_mode=3,decimate ...To put it simply, 'ivtc' will try to fix the paranoia of telecine. When the pattern shifts (or the algorithm fails) a couple of interlaced frames will slip-by, which are detected and deinterlaced by '32detect'. Finally, the 29.97 frames produced for every second of input are fed into 'decimate', which removes the extra frame.
Hope all this hasn't caused you a headache. If your NTSC DVD contains a film, chances are these filters will help.
Since they work perfectly for my NTSC DVDs, I probably won't
mess them up anymore.
Feel free to change them as you will, as they are available under the GPL.
Thanassis Tsiodras, Dr.-Ing.
|Back to index My CV About me||Last update on: Sat Mar 8 22:58:16 2014|