PDA

View Full Version : Lossless Deinterlacing?


Seraphic-
27th July 2006, 07:50
Hi,

Is is possible to do lossless deinterlacing of video? Below is the code i'm using and below that are the result before and after. I'm not too happy with the results, however, as the original video is much crisper/cleaner. Any help would be great. Thanks!

LoadPlugin("C:\Documents and Settings\Desktop\VirtualDub-1.6.15\EEDI2.dll")
LoadPlugin("C:\Documents and Settings\Desktop\VirtualDub-1.6.15\TDeint.dll")
LoadPlugin("C:\Documents and Settings\Desktop\VirtualDub-1.6.15\LeakKernelDeint.dll")
avisource("C:\Documents and Settings\Desktop\Untitled.avi")
trim(2,0)
converttoyuy2(interlaced=true)
assumetff()
interp = separatefields().selecteven().EEDI2(field=1)
tdeint(order=1,field=1,edeint=interp)
leakkerneldeint(order=1,threshold=0,sharp=true)

EDIT: Links removed

foxyshadis
27th July 2006, 08:17
You mean something like Bob(0,0) where the original fields are untouched? (This is lossless.) Or do you just want a maximum-quality deinterlace? (This is not lossless.)

Wait, why are you using both tdeint and leakkerneldeint? You only need one. Maybe that's where the softening/artifacts comes from.

Seraphic-
27th July 2006, 08:44
Thanks for the reply.

I'm using both because I just haven't really had time to learn how to use Avisynth correctly. :p

How does it work when the original fields are untouched? It's adds another video field? Also, how does maximum-quality deinterlace look vs original fields are untouched?

Basically, I wanted to know if it's possible to deinterlace a video and have it the same quality as the uncompressed original.

check
27th July 2006, 09:04
If you are gunning for a high quality deinterlace I can suggest mvbob - personally I find its output outstanding. You better take up a new hobby (such as watching paint peel) though, it's rather slow.

Seraphic-
27th July 2006, 09:16
Do you by chance have a link for mvbob and suggested script to go with it? And would any of my above code be needed with mvbob?

check
27th July 2006, 09:23
sorry, could find it with a cursory search of the forums, someone who has been here longer will surely point towards it. As to your earlier question, your capture is interlaced, and converting to progressive can be done simply by combining every two fields into one frame, but this isn't a very high quality method of doing it - better deinterlacers make use of all sorts of voodoo to get a higher quality result be reinterpolating in some areas and... well, you get the idea.

Seraphic-
27th July 2006, 09:27
I found it here: http://forum.doom9.org/showpost.php?p=606487&postcount=73

But I don't see a mvbob.dll in the rar

check
27th July 2006, 09:31
MVBob is actually an avisynth function, it's a script made in avs that calls real plugins in clever ways.

the .avs script should be placed into your avisynth plugins directory (and renamed to .avsi). Then you will be able to call any function you want from it without having to go through the tedious loadplugin() or import(). The same goes for your other filters by the way - stick them into avisynth\plugins and they are dynamically imported when you need.

Anyway, once you have the script loaded, just use mvbob() to use it. As I said above - it's slow. You might also want to take up watching grass grow.

Seraphic-
27th July 2006, 09:45
Is MVBob made just for deinterlacing?

check
27th July 2006, 09:57
the script has a bunch of other fucntions, but mvbob is simply a very good bob deinterlacer. It will also output a frame that is (probably) twice what you want, you'll have to decimate to reduce the framerate.

Seraphic-
27th July 2006, 09:58
I just did a test run using the script that came with the download. (Without making any edits other then adding "avisource("C:\Documents and Settings\Desktop\Untitled.avi")".

However, it didn't seem to deinterlace the video at all.

check
27th July 2006, 10:14
oh, you aren't meant to do that :p
copy the avs file into your avisynth plugin directory (without any modifications) and change the extension to avsi

Then use mvbob() in your original script to call mvbob.

Seraphic-
27th July 2006, 10:17
Ah, thanks. So I just need the below in my script? If yes, it comes back with an error.

avisource("C:\Documents and Settings\Desktop\Untitled.avi")
mvbob("C:\Documents and Settings\Desktop\VirtualDub-1.6.15\mvbob.avsi")

check
27th July 2006, 10:22
avisource("C:\Documents and Settings\Desktop\Untitled.avi")
mvbob()

assuming mvbob is in avisynth/plugins

Seraphic-
27th July 2006, 10:28
Ah, alright got it now. Going to run it and see how it looks. Thanks for the help! =D

Wow, 3hours for a 12min video... =(

check
27th July 2006, 10:31
don't forget to decimate!

Seraphic-
27th July 2006, 10:33
What do you mean?

check
27th July 2006, 10:47
mvbob will output double the framerate you are likely expecting. The two deinterlacers you use above turn (for example) 25i into 25p, mvbob turns 25i into 50p. You will need to remove 1 out of every two frames to get back to the original framerate (which helps keep size down and won't affect visual quality much at all).
TDecimate(mode=0,cycler=1,cycle=2)
will work as will any other decimate where you remove 1-in-2 frames.
You can get tdecimate as part of this package: http://bengal.missouri.edu/~kes25c/TIVTCv1RC5.zip

Seraphic-
27th July 2006, 10:50
Oh, well i'm not sure if I even need to do that. I mean, I don't mind if the file is 10, 20 or even 30 GB as I'm going to encode the video using RealVideo after I deinterlace

check
27th July 2006, 10:55
I'd advise you do it anyway, halving the framerate will cut required bitrate for the same quality by 30-50%ish (at least for my xvid tests - I'm using a similar script at the moment), and there is no way you will miss any motion.
ps, you probably have your reasons, but Real Video??

Seraphic-
27th July 2006, 10:56
I've come up with one issue. You see, when I capture a video using YUY2 it's upside down. So I open it using Adobe Premiere and it flips back over to how it should be, I then export full uncompressed. But the problem is this mvbob script seems to need YUY2, and huffyuv says that "convert to YUY2" is "slightly lossy". I wanted to do everything lossess.

check
27th July 2006, 10:59
YV12 -> YUY2 - dont even worry about if you are encoding to a lossy file.

Seraphic-
27th July 2006, 11:02
Aren't all video codecs lossy when you take a 10+gb file and get around a few 100MB or less?

But yeah, maybe I should stop using RealVideo. I just like how it can't easily be opened and edited. What do you recommend?

check
27th July 2006, 11:28
Firstly to address the idea of being edited - all anyone needs to do is directshowsource("file") in avisynth and practically any format will fall open at your feet. However that (and all the arguments that go along with it) are topics for another day (hopefully never, i'm sick to death of talking about DRM :P).
Personally I would go with x264+aac, which is nice and easy to do through MeGUI, or the CLI if you are feeling adventurous.
You said before you don't care about filesize, only quality, so try "Constant Quality" (not quantizer) 18-22. Lower quantizer = higher quality.
For aac use the free nero standalone CLI "Nero Digital"

foxyshadis
27th July 2006, 11:28
mvbob is yv12 or yuy2, in fact almost all digital video is, and it's conversions to rgb and back that actually cause more problems than conversion between yuv formats (except in the case of raw hd 4:4:4 and cg video captures).

RV, mpeg2, and mpeg4 will convert everything to yv12 anyway.

You can also do the FlipVertical in avisynth, so no need for all that export time and space just for one operation in premier, and you won't incur penalties for exporting to rgb and back to yuv.

Check, on videogame captures full-rate can make a very noticeable fluidity difference, and as long as it was captured cleanly, won't affect static scenes.

Seraphic-
27th July 2006, 11:36
Well, I don't care about file size until i'm ready to encode the final video. I'm trying to do about 10MB per minute. However, when using RealVideo, set to around 70% quality and 1500 max bit-rate, I tend to get 25MB or higher a minute. So I end up doing 65% or even 60% sometimes.

Also, how do I do a FlipVertical in avisynth? Could it be done at the same time as using mvbob to deinterlace?

check
27th July 2006, 11:36
hmmm, you're right, I forgot about lack of motion blur. I guess you could blend every two frames into one and see how that goes with convertfps() as an experiment, but I'm sure one of the avs scripters here have something a little more advanced cooked up.

edit: FlipVertical()

Seraphic-
27th July 2006, 11:56
Well, there does look to be an issue with frame rate. I captured the video at 30FPS, but maybe mvbob did add too many or too little. The final video is jumpy. Do you have a link for TDecimate and is it a .dll?

There also looks to be an issue with sharp horizontal lines. Do you think adding "leakkerneldeint(order=1,threshold=0,sharp=true)" to mvbob work you fix that issue? (worked with my old script)

check
27th July 2006, 12:07
Cut out a 5000 frame fragment with trim (it's an inbuilt function for avisynth so there are docs in the manual) and do you testing with that. I've not had enough experience with game footage (or mvbob) to suggest further.

Seraphic-
27th July 2006, 12:11
I just looked at a test video using mvbob. It took my 30FPS video and made it 60FPS. How does it do that?

Anyway, that is the issue right there. When I encoded the video I had it set to 30FPS. Thus, I lost half the frames and that was why it was jumpy.

Do you have a link for TDecimate and is it a .dll?

check
27th July 2006, 12:15
as said earlier:
mvbob will output double the framerate you are likely expecting. The two deinterlacers you use above turn (for example) 25i into 25p, mvbob turns 25i into 50p. You will need to remove 1 out of every two frames to get back to the original framerate (which helps keep size down and won't affect visual quality much at all).
TDecimate(mode=0,cycler=1,cycle=2)
will work as well any other decimate where you can remove 1-in-2 frames.
You can get tdecimate as part of this package: http://bengal.missouri.edu/~kes25c/TIVTCv1RC5.zip

Seraphic-
27th July 2006, 12:20
Sorry about that. I've been up all night working on this. Thanks a lot for all your help

Seraphic-
27th July 2006, 12:23
Wait, why are you using both tdeint and leakkerneldeint? You only need one.

I remember now. I was also using leakkerneldeint to fix an issue with sharp horizontal lines during deinterlacing. And that is the one issue i'm having now after using mvbob. But i'm not sure if adding "leakkerneldeint(order=1,threshold=0,sharp=true)" to the mvscript is the say to go to fix it.

Seraphic-
27th July 2006, 20:46
foxyshadis and check, thanks for suggesting mvbob. It worked wonders and looks fantastic!

It took about four hours (like you said it would check =D), but after the deinterlace was done the 12min video was 38GB. I then did a test encoding using RealVideo at 60FSP and the file came out as 668MB. Much too big. So, i'm going to have to try to bring it back down to 30FPS. However, i'm not sure if this would make the video jumpy. I would just leave it at 60FSP but the file size is too big (need around 150MB).

The only other issue is one small sharp horizontal line gets artifacts after deinterlacing (as seen below). The two larger ones look to be okay. I guess it isn't a major issue, but could anyone recommend a way to maybe correct this issue without affecting the rest of the video?

http://www.seraphicgate.com/1.jpg

Thanks

foxyshadis
27th July 2006, 21:33
Horizontal lines always mess up deinterlacers (some more, some less), because they look rather like interlacing lines; there's not a whole lot you can do about it sadly. If it's always in the same place, you could generate a mask over the area and merge in the original with mt_merge (make it in paint and import it through imagesource).

Oh, and you can call FlipVertical() right after the AVISource, it's built into avisynth.

Seraphic-
28th July 2006, 06:12
Damn, the video looks great other then that one issue. I'm open to suggestions if anyone has any.

Also, I found a post a few weeks back that talked about using your video card to deinterlace interlaced video captured from a capture card. Have you heard of that, if so, how does it work?

Thanks

Seraphic-
28th July 2006, 07:34
You mean something like Bob(0,0) where the original fields are untouched? (This is lossless.) Or do you just want a maximum-quality deinterlace? (This is not lossless.)

What was that maximum-quality deinterlace you were talking about? Would the issue be the about the same with horizontal lines when using that over mvbob?

Thanks

Trixter
31st July 2006, 02:43
@check: Realvideo will decimate on its own as RealVideo doesn't support anything beyond 30fps last I checked.

@Seraphic: If this is for RealVideo, why do you need to deinterlace? What's your output target, 320x240 web video? If so, just discard every other field (ie. discard every other line in the image). Not sure off the top of my head how to do that in avisynth, but VirtualDub has a Deinterlace filter that can discard every other line to bring a 720x480 source to 720x240, then you can add another filter to make it 320x240, then write out a new file and that's what you feed to Real's encoder.

actionman133
31st July 2006, 10:42
The script to do what Trixter is mentioning is the following:

AVISource ("clip.avi")
SeparateFields ().SelectEven ()
BilinearResize (320, 240)