Hi. I wanted to convert from interlaced HD (HDV) to interlaced SD (DVD) with best possible quality, so I researched the net a lot and ended up with this AVISynth script, in case others want to do the same:
------------------------------------------------------------------------------------------------------------------
#You need to download these three external filters
#and place them in the same folder as the script:
LoadPlugin ("MSharpen.dll")
LoadPlugin ("SmoothDeinterlacer.dll")
LoadPlugin ("ColorMatrix.dll")
#Change XXXX with the filename of your HD-video:
avisource ("XXXX.avi")
#Change colorspace from ITU.709 (HD) to ITU.601 (SD):
ColorMatrix ()
#Change from 25/30 interlaced fps to 50/60 progressive fps preserving
#full vertical resolution for non-moving objects in picture:
SmoothDeinterlace(lacethresh=10, tff=true, doublerate=true)
#Sharpen the image BEFORE scaling it down (for best quality).
#I found MSharpen to do a good job. Maybe it's not the best.
#See if you can find a better if you like:
MSharpen ()
#Resize to PAL:
LanczosResize (720, 576)
#Or resize to NTSC:
#LanczosResize (720, 480)
#Cut away the first field to get clean cuts (from one scene to another inside the video):
Trim (1,0)
#Interlace it back to 25/30 interlaced again:
SeparateFields
SelectEvery (4,0,3)
Weave
-----------------------------------------------------------------------------------------------
These are the issues I had to solve:
1. The camera "sees" in RGB (red, green blue) and your TV displays in RGB, but the video on tape in between is YUV (luminance Y, and two color channels U and V). And of course: conversion between the two does not involve just ONE standard, oh no. HD uses one standard called ITU.709 and SD uses another: ITU.601. There isn't a huge difference, but if you want perfect quality, you have to convert from 709 to 601. And this is what ColorMatrix does.
2. Resizing interlaced video is not easy if you want perfect quality. Simply separate the fields, resize each, and then combine them together again is not ideal because if some objects in the picture doesn't move (for instance graphics or maybe you have used a tripod), these objects use both fields to build up their full resolution. In such cases you do not want to deinterlace before resizing to keep quality. But for objects that do move, you HAVE to deinterlace unless you want ugly horizontal lines. That's why I chose the SmoothDeinterlacer. It analyzes each frame to see what moves and what does not and then separates each field into two full size frames with full resolution for non-moving objects and half (interpolated) resolution for moving objects.
3. Each time the video cuts from one scene to another, the first frame of each new scene contains the last field of the "old" scene and the first field of the new - for some reason... With the Trim-function I offset the whole video with one field to avoid this, before interlacing.
4. If you convert to DV, you have to switch the field order, because DV is bottom field first while HD and DVD is top field first. If you don't change this, all moving objects will shake horribly. I haven't thought out how yet. Anyways: This script will work for conversion to DVD.
Use VirtualDub to make a new AVI-file, or open the avs-script directly in your DVD-encoder software. The script works very slowly, so if you plan to use 2 pass VBR in your DVD encoder, I recommend making a (nearly) uncompressed avi first, or else the encoder will do the slow script process twice. If you use VirtualDub: Make sure you don't add any filters, because then VirtualDub will convert from YUV to RGB and you loose some quality, but the worst is: you don't know if your video will end up with the correct YUV color space (601 vs. 709). Set VirtualDub to "Direct Stream Copy" if you want uncompressed YUV output or "Fast recompress" if you want to set your own YUV codec (for instance DV). The point is: You want to be sure that you feed your DVD encoder or DV-tape with ITU.601 YUV signals.
Good luck, and please do ask if something is unclear. Please also suggest an adjusted script if you find an even better downsizing method, or you find that I have done anything wrong.
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 20 of 20
Thread
-
-
http://forum.doom9.org/showthread.php?t=136109 has info on this topic !!
Not sure your Selectevery is right ... there's instructions here http://forum.doom9.org/showthread.php?p=1110741#post1110741
Originally Posted by jorbje
When you downsize, why sharpen ? The act of downsizing increases perceived sharpening, doesn't it ? -
There's also these links which show other methods...
https://forum.videohelp.com/topic337231.html
https://forum.videohelp.com/topic346088.html
https://forum.videohelp.com/topic309286-30.html#1754722
and this which talks about denoising and converting an SD DV camera capture to a DVD ...
https://forum.videohelp.com/topic348133.html#1827995 -
Originally Posted by halsboss
-
Originally Posted by halsboss
Also 'interlaced=true' is needed for ColorMatrix used with its position in script (or it could be used after bob-deinterlacer). -
A good encoding engine should set the BFF flag for you eg, the HC encoder input to DVDlab, the VideoReDo TV Suite editor/encoder/author program. Even ffmpeg produces a video stream with the flag set properly, so I'd quiery the DVD authoring program if the result isn't going well.
Re selectevery, the link supplied indicates
Code:AssumeTFF().SeparateFields().SelectEvery(4, 0, 3).Weave() -> TFF AssumeBFF().SeparateFields().SelectEvery(4, 0, 3).Weave() -> BFF *** AssumeTFF().SeparateFields().SelectEvery(4, 1, 2).Weave() -> BFF AssumeBFF().SeparateFields().SelectEvery(4, 1, 2).Weave() -> TFF
-
... and it's easier (for remembering) to always use (4,0,3) numbers because the field order you assume becomes the output field order in this case.
-
Too right. Seen a lot of examples in this place and on Doom9 where they're mixed and matched out of context and sometimes plain wrong.
-
Originally Posted by Alex_ander
-
Originally Posted by manono
-
Hello Alex_ander-
I'm assuming he's used this script himself before with good results - no obvious jerkiness - so it must be good. Maybe the TFF setting in SmoothDeinterlacer plays a part in setting the field order (incorrectly, I think), so that when he removes that first bobbed field, combined with the SelectEvery (4,0,3) line, it becomes true TFF again.
Maybe jorbje will come back again soon and elaborate. I'm counting on you, jorbje. Don't let me down. -
Thanks a lot guys for your comments
Originally Posted by halsboss
Are you talking about a HD clip from a DV camera per chance as your comment seems a bit confusing - DV vs HD vs HDTV vs DVD
When you downsize, why sharpen ? The act of downsizing increases perceived sharpening, doesn't it ?
There's also these links which show other methods...
https://forum.videohelp.com/topic337231.html
https://forum.videohelp.com/topic346088.html
https://forum.videohelp.com/topic309286-30.html#1754722
Originally Posted by manono
1-2-3-4-5-6-7-8
You can then interlace them like this:
(1-2)-(3-4)-(5-6)-(7-8) (is this TFF?)
Or, if you switch field order, like this:
(2-1)-(4-3)-(6-5)-(8-7) (is this BFF?)
If the field order is TFF and the player assumes BFF (or vice versa), you will get very shaky movements.
What I did was skipping the first field:
2-3-4-5-6-7-8-9
which interlaced would be like this:
(2-3)-(4-5)-(6-7)-(8-9)
Now, this is important: Fields is dependent on two factors. And you can switch both independently:
1) Time: the second field is recorded 1/50 (PAL) second after the first, and therefore contains a different placement of a moving object. That means: If you put field 1 in the lines where field 2 should be and vice versa, moving objects will shake (two steps forward and one back, two forward and one back etc.).
2) Placement: Each field represent each half of a full resolution video frame. That means: If you put field 1 in the lines where field 2 should be and vice versa, non-moving objects will get jagged and ugly.
I guess there are AVISynth filters that will do this but I don't know AVISynth much yet. Anyways, this is the theory:
1) How to switch the fields in just time and not placement: Move the whole frame up or down exactly one line. Well, of course the fields are moved, but the point is: They are NOT moved relatively to each other. The whole picture is the same, but each field has still switched places and will be played back in opposite order in TIME. This is how you can repair shaky movements and still keep full vertical resolution.
2) How to switch the fields in just placement and not time: Switch field 1's lines with field 2's and then move the whole frame up or down exactly one line.
Why am I explaining this heavy theory in this thread? Because skipping the first field before interlacing does exactly the same thing as 2). But you don't want jagged output. Well, it is not that jagged after all since I downscale from HD to SD, but I will still lose some quality. That is one reason it is so important to have as close to FULL vertical resolution as possible in each picture before downscaling and weaving them together again. And SmoothDeinterlacer makes sure you have that. Bob does not. -
I posted a guide for this about a year ago, I can't find it now.........
Anyway, Yes a DVD can be BFF, TFF or Progressive. Mini-DV codec can support BFF, TFF and Progressive. All Mini-DV camcorders record as BFF for simplicity sake. Just as al HD cameras record TFF...............
Your method works, but it is redundant and too slow for my tastes. I'd rather go with this:
Code:LoadPlugin("MSharpen.dll") MPEG2Source("Test.d2v", cpu=0) assumetff().Bob(height=480) LanczosResize(720,480) assumetff().separateFields() SelectEvery(4,0,3) #TFF source - use (4,1,2) for BFF Weave() MSharpen(15,53,false,false,false)
Got my retirement plans all set. Looks like I only have to work another 5 years after I die........ -
Originally Posted by manono
P.S. In the last case trim operation also mixes fields up in a strange way by the end of the script (my next post). -
Originally Posted by jorbje
Originally Posted by jorbje
Originally Posted by jorbje
Originally Posted by jorbje
Originally Posted by jorbje
Originally Posted by jorbje
Originally Posted by racer-x -
Originally Posted by racer-x
If the OP is deinterlacing and then reinterlacing ... just a thought, leave it progressive ? Depends on the OP's clip features I guess. I have gear which is turned progressive and left that way - the clip features are such that it appears OK. -
Originally Posted by halsboss
Have a poke around at the doom9 forums avisynth usage, they have literally hundreds of pages dedicated to this sort of thing including the inimitable Limitedsharpenfaster function and Soothe etc etc ... been using them for years with fantastic results. I have a view that sharpening before downsizing adds cpu cycles unnecessarily unless the clip has some poor characteristics... denoising HDV I can understand, and maybe the methods you use could introduce softening or something which makes sharpening necessary ?
be very careful with swapping with field orders willy nilly, suggest have a look at "ReverseFieldDominance" (eg there's a plugin) etc over at doom9 and the discussions pertaining to changing field orders... really odd stuff can happen that you wouldn't necessarily think of, if you do it.
Originally Posted by jorbje
Thanks for the alternatives to SmoothDeinterlacer. I'll try them out. -
Originally Posted by jorbje
Then it's not a field, it's a frame skipped and this will not change field order at re-interlacing. What we have before SeparateFields() is a frame-based progressive video (its field-processing history is already lost):
(2t+2b)-(3t+3b)-(4t+4b)-(5t+5b)....
Since each pair of fields here belongs to its own moment (progressive frame) you can further separate fields in either order (you have double set of frames for this due to double framerate). If you don't set this order (=use AviSynth default) or (the same) use AssumeBFF() before separation, you'd get:
2b-2t-3b-3t-4b-4t-5b-5t....
After Select(4,0,3) you leave 2 of each 4 fields:
2b-3t-4b-5t....
Weave():
(2b-3t)-(4b-5t)...
since numbers 2,3,4... correspond to motion phases, it's BFF (if you want a different field order from the script, you can simply use AssumeTFF before SeparateFields).
Now if you don't skip the first frame and still separate with BFF (or leave default field order):
(1t+1b)-(2t+2b)-(3t+3b)-(4t+4b)-(5t+5b)....
AssumeBFF().SeparateFields():
1b-1t-2b-2t-3b-3t-4b-4t-5b-5t....
1b-2t-3b-4t...
(1b-2t)-(3b-4t)...
- it is also BFF (same as with Trim)
The only case Trim (1,0) changes things by the end of the script is in case the input for bob-deinterlacer is BFF but it has the wrongly set parameter TFF=true. Not 100% sure of SmoothDeinterlacer behaviour in this situation but LeakKernelBob (with order=1) would produce something like this:
(2t+2b)-(1t+1b)-(4t+4b)-(3t+3b)...*
without Trim(1,0):
(separated as BFF)
2b-2t-1b-1t-4b-4t-3b-3t....
selected/weaved:
(1t-2b)-(3t-4b)... - true TFF
then trimming * to (1b+1t)-(4b+4t)-(3b+3t)...
gives (separated as BFF):
1b-1t-4b-4t-3b-3t-6b-6t-5b-5t....
selected:
1b-4t-3b-7t-5b...
(1b-4t)-(3b-7t)... - BFF, but the fields are completely mixed up -> the Trim() line can be dangerous in some cases, while the script without it still works in case of field order mistake in the beginning (only field order changes). -
Originally Posted by Alex_ander
...and this will not change field order at re-interlacing
Thanks for clearing up the Trim(1,0)-issue. I see there can be heavy field problems using it in the wrong place. But still: In my case I can't find any other way to get clean cuts. My source is TFF, I know that for sure, and I want my output also to be TFF. And even if I set AssumeTFF all over my script, my cuts will only get clean if I trim out the first deinterlaced frame (now, that was a better word for it?). I guess there is something faulty with SmoothDeinterlacer.... Anyways, it works perfectly fine.
Originally Posted by racer-x
http://spokke.com/bob.tif -> your script
http://spokke.com/smooth.tif -> my script
(I have deleted the 709-601 conversion in these examples)
Compare the superimposed text in the top right, the phone cord in the logo (down, left), the text on the food, and even the eyes of the boy. It is clear to me that simply "bobing" is way faster, yes, but with a cost of a little bit less quality. -
The differences could just be that you're using more sharpening. I don't like to sharpen interlaced video too much, it usually leads to flickering on the TV. If the differences are enough to convince you to keep using your script, then that's your choice and you should do what you feel is best for you. As for me, there's not enough difference to justify the extra processing time required. We are after all talking about video (moving pictures not still) and I doubt anyone can tell the difference watching it on TV.........
It was good that you posted your method, as it gave me a reason to try new filters.Got my retirement plans all set. Looks like I only have to work another 5 years after I die........
Similar Threads
-
Can an interlaced file appear not to be interlaced on the monitor?
By rcavanah in forum Authoring (DVD)Replies: 5Last Post: 10th Sep 2011, 23:09 -
Converting DV to H.264 and comparing interlaced/de-interlaced
By amirh1 in forum Video ConversionReplies: 5Last Post: 23rd Jun 2010, 10:16 -
Interlaced YV12 chroma messes up between AviSynth and VirtualDub
By Neimo in forum Video ConversionReplies: 6Last Post: 21st Apr 2010, 20:30 -
Convert Interlaced video to Progressive?
By ziggy1971 in forum Newbie / General discussionsReplies: 21Last Post: 20th Sep 2008, 20:33 -
Converting 30fps Progressive to 25fps interlaced ? (Avisynth & VDub)
By blewyn in forum Video ConversionReplies: 6Last Post: 12th Jun 2008, 18:51