Log in

View Full Version : Bad Frames from TDeint or AVISynth?


vignes
9th June 2005, 13:59
I'm new to these forums, but have been reading quite a few threads with great interest. So here's my first post.

I've found that occasional corrupted frames are introduced by a process I am using to produce a video of a lecture I filmed. I have experimented a bit and am quite sure that either AVISynth, or the .avs script I am using, or the de-interlace filter TDeint.dll is to blame. Before I go to the laborious process of changing all the various factors one by one and testing the ouput, I thought someone here might be able to give some advice where best to look for the problem.

My workflow on this project was to assemble and edit HUFFY compressed YUY2 analogue video mixed with still images in Premiere 6.02 (capturing video was via SVideo to Radeon AIW using latest VDub), frameserve the entire edited video to a HUFFY .avi file, then process this .avi file with AVISynth to deinterlace it, limit colour range, add a border to correct for overscan, and convert to RGB24 for compression to DVD-compliant mpeg2 in TMPG Express (where I also did some colour correction and use of the sharpen filter).

The script I used is:

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
AVISource("g:\FS Premiere to Huffy.avi")
TDeint()
Limiter(16,235,16,240)
crop(8,2,700,572)
AddBorders(35,22,35,22)
BicubicResize(720,576,0,0.5)
ConvertToRGB24(interlaced=false)

#the three lines "crop" and "add borders" and "BicubicResize" crop garbage lines speific to my capture card/process, add borders, and resize so that overscan is eliminated but AR kept accurate for most TVs and projectors that wd be used to show this video.

Looking closely at the first HUFFY .avi shows that all frames are as shd be. But viewing the final mpeg2 shows occasional corrupted frames (I can post small jpeg's of these if anyone needs a look). Inspecting the second .avi, the one that is processed by the script above, reveals that the corrupted frames are here, so it is the processing from the first .avi to the deinterlaced, overscan-corrected file that is generating these bad frames. For an hour of video, there are quite a few corrupted frames, perhaps 20 or 30 or so, irregularly spaced. Some occur on the video shots, some others on the stills. Of course, by re-editing the second .avi in Premiere, and simply cutting out the offending video frames, I can correct the problem, but this is tedious and shdnt be necessary.

So, does anyone have some advice on how to correct the problem? Shd I try an alternative deinterlace filter? From the forum on TDeint it seemd that this one was the best so far.

Note that my method for correcting overscan seems to be quite a good idea for such a project, as it makes filming easier (you get to see the whole picture you have filmed without having to calcualte title-safe or action-safe borders), and in addition, you dont have to prepare all the still images to be used with various-sized borders to prevent something important not appearing in the final show. If a given TV or projector has less overscan than average, still no problem as you just see a thjin black border around the image - you dont even notice it. I'd make tis correction routinely to all the movies I capture on the satellite, except for the extra processing time.

Any advice from forum experts on how to correct the problem, or on better ways to achieve the result Im after with this method, wd be most welcome!

Guest
9th June 2005, 14:04
Please post a full-sized screenshot of the "corruption".

vignes
9th June 2005, 14:13
Here is a .jpg of the captured .bmp of one of theworst examples. Other corrupted frames are mostly less severe. This one was of a still image contained in the video.

Guest
9th June 2005, 16:50
I never saw anything like that.

Add the filters one at a time and serve into VirtualDub to view. Find out which filter causes the problem and report back here.

vignes
9th June 2005, 19:18
OK, I'll run some tests as you recommend. It will likely take a day or two as I'm quite busy with other things and since only the occasional frame gets corrupted I'll probably need to let things run a bit. By the way, another corrupted frame, also from a still, is even weirder, and completely different: the top 3/4 is normal, and the bottom 1/4, where there should be just a dark background, has large variegated coloured patches - looks lile someone's idea of digital art.

scharfis_brain
9th June 2005, 19:54
Some time ago, I had these errors, too.
I don't know exactly, what caused them to disappear.

Check/change the following:

1) HuffYUV - Version
2) IDE-Controller Drivers
3) IDE Cables
4) System memory
5) Clock rates and timing settings

Seed
9th June 2005, 20:22
Another quick thought, if you use P4, disable hyperthreading, which in my experience has caused some scattered problems in Avisynth/video editing.

vignes
9th June 2005, 22:33
OK, thanks for these tips, I'll be trying some various possible solutions in the next few days and will report back. I run Win2K Pro with a P4 1.8G so no hyperthreading. The effect is so random that I suspect it will be difficult to pin down, but hopefully will disappear with a change in the steps or software I use at each phase. By the way, to make the processed HUFFY avi, I was specifying the original (Premiere edited) .avi via the AVISynth script, and then loading this .avs in TPGEnc Express and saving to HUFFY .avi, so perhaps there is a problem with HUFFY in that it has to decompress and then recompress all in the same go?

Mug Funky
10th June 2005, 02:13
sort of OT, but if it's just a videoed lecture going to DVD, then there's no reason to deinterlace. just make sure your field-order is correct and encode interlaced - TMPG should be able to handle it pretty well, so long as your bitrate isn't impossibly low (where it'd probably fail on progressive as well). talking heads are the easiest thing in the world for mpeg-2, interlaced or not.

vignes
10th June 2005, 11:20
Tis true. I already made an interlaced version and have distributed a number of copies to colleageus. It looks fine on TV, except for the overscan problem I mentioned. So one of the objects of deinterlacing was to apply the borders and resize so that overscan was corrected. It seemed a lot easier to do this in one go for the video and the still images, after-the-fact, rather than to hassle making all the images with just the right border, and framing the video just right as well. For example, if I want to use a still image in its entirety, I can just crop it to 720x576, period. (Of course, I also resize to produce 1.067 pixels)

A second goal was that when the interlaced version was shown on a projector - a DLP Mitsubishi - interlacing artifacts were plainly seen in the moving lips, and since for a lecture everybody is watching this part of the image, it made for rather poor effect. The deinterlaced version looks much better in this respect, and in fact the still images, especially those with text on them like the corrupted one posted above, also looked better in deinterlaced. Some other still images with fine patterns that caused scintillation also looked better deinterlaced on the projector.

I'm trying today a repeat of the same process, but this time I'll do the audio and video separately, so that the stage - Premiere edited .avi to AVISynth processed .avi - is done just with the video stream. If the problem is one of system resources, perhaps this will correct the problem. I'll keep you posted on progress. Thanks again for your input, much appreciated!

scharfis_brain
10th June 2005, 11:38
I never correct any overscan, because it is simply normal on TV.

Correcting overscan (meanig resizing) with interlaced sources will badly affect video quality and maybe also hurt compressibility.

To avoid interlacing on the PC / Beamer, simply enable the deinterlacing of your MPEG-decoder.

vignes
10th June 2005, 12:06
I never correct any overscan, because it is simply normal on TV.
...
.

From an artistic standpoint, I'd overscan-correct all the movies I capture on the satellite, if it didn't involve so much extra hassle and processing time. After all, at least in a GREAT movie, the director takes great pains to frame each scene with exactly the background he feels makes the best impact. And then your TV or projector unceremoniously lops off a SIGNIFICANT border of it all. Primitive. Insulting to the art!

If I deinterlace with TDeint before correcting for overscan, should be no degradation, correct? I read some recommendations about mpeg and other lossy compressors having trouble with odd-sized borders, but I havent noticed any problem using TMPG Express on my overscan-corrected video (for the cropping and border dimesnions I used, see the script in the original post, above).

The de-inetrlacing of the beamer doesnt seem to give the best result, by the way. The TDeint deinterlaced video was the best-looking, except for the 30 or so corrupted frames per hour as above. Stills with text came out crystal clear whereas on my wide TV the text was less legible, with some odd shadowing.

vignes
12th June 2005, 11:47
A Result

I havent yet tried to localise which AVISynth filter might be doing the dirt on my video as requested by neuron2, but I've discovered a workaround. Apparently, the corrupted frames only occur when AVISynth operates on an audio/video .avi file (as opposed to a video only file). This I must conclude, since the following workflow produces a perfect video - compare it with the one in my original post:

Export edited video only from Premiere via framserver to HUFFY .avi - I used TMPGExpress, loading the signpost file for the video and no audio.

Export audio as .wav

Load the .avs script in TMPG Express directly and encode the HUFFY .avi to DVD-compliant .m2v file. I also used a couple of theTMPGExpress filters here to colour correct and sharpen.

Encode the audio .wav to .ac3 in AC3Machine

Author the DVD directly using the .m2v and .ac3 files - I used TMP DVD Author.

This produces an error-free DVD. Interestingly, I think the AVISynth is still producing a not-quite-totally-legit .m2v file, since if I try to mux it with the .ac3 file or an equivalent .mp2 file made either from AC3Machine, BeSWeet, or demuxed from a previous DVD of exactly the same length, TMPG Tools (simple multiplex) produces the error message: "388900s packets cause buffer underflow the mpg file might cause error when it played" (sic). In addition, the produced .mpg refuses to be authored into a DVD.

Sergei_Esenin
16th June 2005, 06:54
From an artistic standpoint, I'd overscan-correct all the movies I capture on the satellite, if it didn't involve so much extra hassle and processing time. After all, at least in a GREAT movie, the director takes great pains to frame each scene with exactly the background he feels makes the best impact. And then your TV or projector unceremoniously lops off a SIGNIFICANT border of it all. Primitive. Insulting to the art!

I solved that problem the best way--by using a display with no overscan. Display devices with no overscan are the future; so, why target platforms which are increasingly obsolete and are already being replaced on the high end and even the upper midrange? *That* is primitive. This is especially true since almost any method of compensating for overscan results in lowered resolution. Adding overscan borders within a fixed frame means you're decreasing the resolution of your image area--i.e., losing detail and assigning fewer bits to your real image.

Personally, the only time I place black borders in an encode is when they're needed to maintain AR or needed to pad to a "legal" resolution. If I were targeting other people I might make allowance for overscan *if* it would destroy the image to have too much of it hidden in overscan; otherwise, no way, and never on encodes meant for my archives. It's a loss of resolution and/or encoding bits which I find unwelcome.

If I deinterlace with TDeint before correcting for overscan, should be no degradation, correct?

Remember that if your video is truly interlaced (not progressive with pulldown applied to make it interlaced), you're throwing away half your temporal resolution when you deinterlace. Sure, motion-compensated deinterlacers ameliorate the effects, but temporal data is still not 100% intact and impinges on spatial details instead. Personally, I wish I hadn't deinterlaced my older truly interlaced material, since it's easy to deinterlace on playback (to double framerate, which doesn't lose temporal data). All my newer truly interlaced encodes are either left interlaced or deinterlaced to double framerate. Smoother motion, fewer jaggies/stairsteps. But then I'm a weird perfectionist with my personal encodes... :sly:

BTW, your image corruption is similar to something I once had back when I used to use TMPGenc, so I'd lean towards that not liking something as the likely culprit. But I haven't used it or any of its offshoots for a long time, so who knows.

2Bdecided
16th June 2005, 13:47
Remember that if your video is truly interlaced (not progressive with pulldown applied to make it interlaced), you're throwing away half your temporal resolution when you deinterlace.


Not if you use a (smart)bob to deinterlace, do the processing at 50p (or 60p) and then re-interlace. Almost all the AVIsynth deinterlacers (or a close relative of each deinterlacer) can output 25p or 50p as required. I forget if Tdeint is the exception!

Sure, motion-compensated deinterlacers ameliorate the effects, but temporal data is still not 100% intact and impinges on spatial details instead.


The spatial and temporal details are confused by the original interlacing process. That's the nature of interlacing - you introduce a fundamental uncertainty between high frequency spatial components and temporal motion - at the limit, the two domains become confused.

Even a perfect deinterlacer can't replace this lost information. The motion-compensation used in the best deinterlacing is nothing to do with maintaining temporal resolution or smooth movement - it's about tracking objects to make the best guess at what should go into the missing lines, and where (if anywhere) the "missing" information can be found, or estimated from.

I agree that it makes little sense to compensate for overscan normally - for one thing, film has a similar region beyond that you usually see which is exposed in the camera, but hidden by the gate of the projector. Good telecine machines allow you to scan this area, and it's to be hoped (though not assumed) that good transfers would read this area to fill the 10% overscan region, meaning that what you see on a standard TV is exactly what you should see, while what you can see in that extra 10% would never have been seen in a cinema anyway.

In the real world, I suspect it's only DVD menus and titles which take account of overscan (you can't put a button or text in that 10%!), while the transfers themselves probably cause us to lose 10% of the wanted picture. As you point out though, shrinking the picture is a lossy process - if you must do it to see everything on a CRT, you should only do it on temporary copies - the results will look silly on any display which allows the borders to be seen.

The times I have accounted for overscan and shrunk the image by 10% leaving black borders on all sides is where the resolution of the original is very limited, or where the subject has been framed without overscan in mind. In both these circumstances, it made sense to make sure most viewers (watching on normal overscanned TVs) got to see as much of the picture as possible.

The problem is that every CRT TV has a different amount of overscan - you're bound to see black borders on some - and usually annoyingly unequal black borders at that! For the low res / badly framed material I was working with, this was preferable to leaving the image 10% bigger, 10% fuzzier, and losing important parts of it!

Cheers,
David.

vignes
17th June 2005, 12:24
All,
Thanks for your interesting comments. Here's a few thoughts in reply:

I'd think that the mid-to-high end display device with no overscan will still be a minority of displays for quite some time yet. Even my very recent Mitsubishi DLP beamer has significant overscan. And even though overscan is variable, one could correct for a minimal amount so that resolution reduction and possible visible borders are also minimal. For the films I capture, I don't bother (I was being a bit facetious in my post you quoted!) and after the satellite compression it's best not to do any tricks at all since they are already of just passable quality compred to a DVD. And I'm not bothered too much because at least the medium itself - the DVD made from the captured movie - has the entire signal.

But for the lectures I'm filming, which have many still images and some film clips too, and where the reduced resolution is not a factor since I either film the talking heads with more border and add more border around all the stills and clips individually, OR, do this all in one go after the fact via the resize>add borders script, with the final visible image being essentially the same size by either method. The latter solution is by far the easiest so as to be sure that when the program is viewed on whatever TV or projector, I won't find that overscan has clipped something important. These programs are viewed by people who have everything from a small TV to having the shows projected for a roomfull audience, so I have to allow for THEIR equipments and not the ideal, or even my own setup.

So, the only question is how best to do the correction. For instance, whether to deinterlace, crop, add borders and resize, and RE-interlace, or leave progressive (remember it is nearly all talking head stuff and still images) and then what is the best way to accomplish this, i.e., which deinterlacer, how much to crop, etc. I did notice that on my projector, despite the supposedly great Faruda technology, that in the interlaced version one could notice some interlace artifacts in the moving lips of the speaker - fine combing and blurring - and that the progressive version was definitely an improvement on this.

Sergei_Esenin :
Remember that if your video is truly interlaced (not progressive with pulldown applied to make it interlaced), you're throwing away half your temporal resolution when you deinterlace.

But 2Bdecided added:
Not if you use a (smart)bob to deinterlace, do the processing at 50p (or 60p) and then re-interlace. Almost all the AVIsynth deinterlacers (or a close relative of each deinterlacer) can output 25p or 50p as required. I forget if Tdeint is the exception!

From your extensive comments I can only conclude that theory is fine as far as it goes, but getting the best end result is still more a matter of trying various tricks of the trade and seeing what looks best - and often the end result of different trials seems to be so close that it becomes a matter of opinion as to which looks best.

And I suppose that is why I am asking questions here of those with more expertise than I! So if anyone would like to comment on method: which de-interlacer with which arguments, pros and cons of odd-sized borders, best resizing to use (lanczos seems to be in these days) whatever, I'd be glad to do some further trials on my lecture videos. But since I am not the expert here, if I were to just start doing trials myself, I'm sure I could waste a lot of time trying things that are obviously not the way those more familiar with these matters would go. For instance, I've seen all sorts of complicated scripts on the various forums for the "best" way to do tricks to interlaced material (such as resizing it and re-interlacing) but there seems no good consensus on this. Might we come up with a (at least provisional) script that we can generally agree gives excellent results for this deinterlace>various operations such as those I need>reinterlace procedure? For newbies, or those like myself who need good results but don't have the time or special motivation to make an extensive stuedy of these matters, a "completely-spelled-out" .avs script for this and other often-needed video transformations would be most welcome.

For instance, 2Bdecided's idea: use a (smart)bob to deinterlace, do the processing at 50p (or 60p) and then re-interlace - sounded interesting.

Sergei_Esenin :
BTW, your image corruption is similar to something I once had back when I used to use TMPGenc, so I'd lean towards that not liking something as the likely culprit. But I haven't used it or any of its offshoots for a long time, so who knows.

What encoder are you using these days, then? I've been using theTMPG Express with quite satisfactory results EXCEPT in this one instance of loading it with the .avs script - but ONLY when the .avi referred to by the script is interleaved audio and video. The problem disappears when treating a video-only .avi file, as I mention above. This seems a curious result to me, but I'm not really prepared to spend much time exploring whys and wherefores as my object was to get a satisfactory final result that made the entire process of producing one of my "talking-head lectures" easier and better suited to the range of displays the programs will be viewed on. So the overscan-correction script served the purpose well - now I can use still images and other material without having to calculate and add for each one a border, and I can film using (nearly) the entire frame, and then correct everything in one go at the final stage as I encode to mpeg2. The question that remains is therefore how I can improve on the original script:

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
AVISource("g:\FS Premiere to Huffy.avi")
TDeint()
Limiter(16,235,16,240)
crop(8,2,700,572)
AddBorders(35,22,35,22)
BicubicResize(720,576,0,0.5)
ConvertToRGB24(interlaced=false)

Sergei_Esenin
18th June 2005, 01:23
What encoder are you using these days, then?

I don't really encode to MPEG-2 at all anymore. DVDs are so 1999. :sly: Since I encode for my media collection and not for DVD distribution, I do all my archival encoding to high-res MPEG-4 ASP or MPEG-4 AVC, and on the rare occasions when someone else needs a copy on DVD I just whip 'em off using NeroVision Express. NVE's DVD quality is only mediocre compared to CCE or TMPG, but again I only rarely make DVDs for others--it's my carefully encoded MPEG-4 "masters" I care about. :)

Poutnik
18th June 2005, 08:49
.....The times I have accounted for overscan and shrunk the image by 10% leaving black borders on all sides is where the resolution of the original is very limited, or where the subject has been framed without overscan in mind. In both these circumstances, it made sense to make sure most viewers (watching on normal overscanned TVs) got to see as much of the picture as possible.............Similar or related to SLR cameras field. Only very high tech pro cameras have viewfinder picture equal to taken one. Others have in viewfinder only slightly above 90 % of take picture.

vignes
18th June 2005, 12:04
[QUOTE=Sergei_Esenin]I don't really encode to MPEG-2 at all anymore. DVDs are so 1999. :sly: Since I encode for my media collection and not for DVD distribution, I do all my archival encoding to high-res MPEG-4 ASP or MPEG-4 AVC,

But what source is your archival material? Surely not DV broadcast which is already way degraded, or commercial DVDs... I was considering going beyond mpeg2 but like the situation long ago when VHS came to predominate over Betamax, due to the heavy investment and promotion of mpeg2 in commercial DVDs and in broadcast, it looks like we're stuck with it until the next paradigm shift.