View Full Version : HD to SD using Avisynth and VDub
spyros78
25th March 2008, 14:20
Hi all,
we have used a Sony HDR-HC7 camcorder to capture HD using the camcorder's bundled software. The resultant file is an .m2t file. Using Media Player Classic I can play it fine. Going to properties I get the following specs:
Video: MPEG2 Video 1440x1080 (16:9) 25.00fps 25000Kbps
Audio: MPEG Audio 48000Hz stereo 384Kbps
What I need to do is resize it to SD PAL ideally keeping the correct aspect ratio.
Trying to do this with AVISynth using DirectShowSource fails (file is not supported). I installed Haali Media Splitter and ffdshow and get a different error (file too small for this resize
method - I'm using BicubicResize). Removing Resize won't do any good either. In Addition to that media player classic speeds up both the audio and the video once I installed ffdshow and Haali. Uninstalling them brings speed to normal.
I also tried DGAVCIndex.exe. I put the .dll in my system32 folder but once I tried to open my m2t file I get loads of error messages such as:
found NALU w/ forbidden_bit set, bit error? Let's try...
and
found NALU type 19, len 137 undefined, ignore NALU, moving on...
So my questions are the following:
1. Why my .m2t file is mpeg-2? I thought HD captured from the Sony HDR-HC7 camcorder should be AVC MPEG4. (Camcorder is not mine)
2. How come media classic play the file fine and AviSynth and vdub fail using DirectShowSource?
3. Why installing haali and ffdshow result in my file being played faster?
and obviously...
4. How can I process the file ideally as lossless as possible?
This is very confusing for me as I have never worked with HD before.
Any help?
Many thanks in advance
sp
Gannjunior
25th March 2008, 17:24
hi,
properties are correct. infact hc7 is an HDV camera. so it uses mpeg2 compression.
a possible "losless" way: why do you use directshowsource when you can use dgindex by neuron2?
so: dgindex->avisynth->virtualdub->mjpeg, huffyuv (or another losless or semilosless codec).
So you have big avi that you can import in you favourite editing software to cut, to add effects etc...
(of course, if you have only to cut some parts, it's enough trim in avisynth).
After everything you can choose a final re-compression in HDV.
the same commercial software, that usually are used for the editing, can be used also to jump dgindex and avisynth. I mean, for example, Pinnacle studio 11.1 or premiere CS3 3.1.1 that uses
NLE to get HDV o AVCHD source "on fly"...you can save time or you can use this way if you have not enough disk space, but of course this solution will give a "lower" quality and you can have problem to manage for example a rallenty editing that is not pretty digested by NLE software.
however the NLE hdv software are not perfect but for an editing not too much long or complex could be a very nice arrangement...
ciao!
spyros78
26th March 2008, 10:21
hi,
properties are correct. infact hc7 is an HDV camera. so it uses mpeg2 compression.
Sorry, trying to read my original thread now I realise how confused I was. I wasn't very clear. The footage was not shot on the HC7. We don't know how it was shot. We only used the HC7 to play the tapes so that we could capture the content using the bundled software. I wonder whether we should have used a different program to capture the material as the resultant files were mpeg-2.
a possible "losless" way: why do you use directshowsource when you can use dgindex by neuron2?
Can you please elaborate? What is the difference between directshowsource and dgindex? Using dgindex before avisynth adds up one step to the process right?
the same commercial software, that usually are used for the editing, can be used also to jump dgindex and avisynth.
Luckily I do not need to edit the content. Just trim.
Thanks for your speedy reply.
Gannjunior
26th March 2008, 15:43
...The footage was not shot on the HC7. We don't know how it was shot. We only used the HC7 to play the tapes...
ahh! ok. however this confirm that surely you have mpeg2 source and not avchd (since avchd consumer camera record on solid memory, hard disk or 8mm dvd...).
dgindex is exactly the same thing of dgavcindex/that you quoted before), but it is dedicated to mpeg2. (neuron2 ispirated his dgavcindex to dgindex!). so no lossy passage. only a little file (you have .dga in dgavc... and .d2v in dgindex) that permits you to put in communication vob and avisynth, so that avisynth could frameserves vob to virtualdub.
and the play is done!
So..if you have only to trim your source, you could do:
1.dgindex your source
2.prepare your avisynth script - using ' mpeg2source("c:\mpeg2.d2v") ' to import your camera file (of course you need a dgdecode.dll to let mpeg2source to work...same thing as dgavcdec.dll...)...in your script. afer you can trim, you can resize (and off course you'll have to resize to 720x576 since in your title you speak about HD->SD...), you can filter, you can do everything you need...
3a.you can compress by xvid or divx dropping your avs script in virtualdub...or if you want better quality you can use megui to compress in x264 (mpeg4-AVC)..
3b.off course if you need an mpeg2 target you can load your avs script in a good mpeg2 encoder as for example CCE...
pls let me know if you other doubts.
ciao!
spyros78
26th March 2008, 18:31
Great!
Your comment about AVC being recorded on memory stick and hard drive was very helpful and cleared some of my misunderstandings.
I have managed to get the process in both ways using dgindex and directshowsource so I'm very close to finalising it however, I still do not understand the difference between DirectShow and dgindex. I am concerned I am adding one more step to the process by using dgindex as I can create a script in avisynth to open the .m2t file without converting it to a d2v project.
Thanks for your great help.
sp.
Guest
26th March 2008, 18:42
DirectShowSource() will not allow correct seeking (random access). DGIndex makes an index file (d2v) that allows MPEG2Source() to support random access. You need random access to do correct trims in your script or to jump around on the timeline in VirtualDub.
There are other cool things you can do with MPEG2Source() also. See the manual for details.
scharfis_brain
26th March 2008, 18:52
a quick and okay quality script like this is a good point to start with:
LoadPlugin("DgDecode.dll")
LoadPlugin("YadifMod.dll")
Mpeg2Source("video.d2v")
Bicubicresize(704, Last.Height)
YadifMod(Mode = 1, EDeint = Bob(0, 1))
BicubicResize(Last.Width, 576)
SeparateFields().SelectEvery(4, 0, 3).Weave()
halsboss
27th March 2008, 13:09
Not sure if this does any better than okay... http://forum.doom9.org/showthread.php?p=1115201#post1115201
it'd certainly be slower
spyros78
27th March 2008, 17:35
DirectShowSource() will not allow correct seeking (random access). DGIndex makes an index file (d2v) that allows MPEG2Source() to support random access. You need random access to do correct trims in your script or to jump around on the timeline in VirtualDub.
Great! thanks.
In regards with the suggested code (scharfis_brain). I do not need to DeInterlace. The videos will be encoded at 50Mb/s MPEG-2 full frame. GOP structure will only contain I frames as we need to edit the material in Avid. But apart from DeInterlace I do not understand what else the script does. If you have any other suggestions or advice please shout.
Thanks for all your time and help
sp.
scharfis_brain
27th March 2008, 17:56
if you want to convert a interlaced video into something else (like SD), you NEED to deinterlace.
but the script also does re-interlacing.
This means the final output is interlaced.
spyros78
28th March 2008, 10:44
if you want to convert a interlaced video into something else (like SD), you NEED to deinterlace.
but the script also does re-interlacing.
This means the final output is interlaced.
Scharfis_brain, I trust you know more on the subject than I do however, if this isn't a huge thing I'm asking, could you please explain me why I need to deInt and reInt? My understanding is that I need to keep Interlacing as this material is our master copy which will be used for editing in Avid. I would deInt only at the very end of the procedure and only if the material was to be played at a desktop monitor.
thanks.
Gannjunior
28th March 2008, 13:30
if you need to edit in AVID off course you have to keep it as more as 'intac' as possible, so...yes, do not deinterlace before to import in AVID (or, better, you can manage separately each field by avisynth)
...about this: why using mpeg2 i-frame only since there are intermediate codecs dedicated as, for example mpjepg, huffyuv (this is completely lossy) or DV (in this case only spatial compression)...?
mpeg2 borns to be used with its complete GOP (with P and B) it works fine to get a really lossy compression, so even if exists the on ly iframe version, i think there are better solution...
at last: i don't know if avid could read avs script natively or if there is any plugin... but, if it was possible, you should use that path...
ciao!
scharfis_brain
28th March 2008, 15:20
if you want to convert interlaced HD to interlaced SD you have to deinterlace - resize - reinterlace. Period.
spyros78
28th March 2008, 16:04
if you want to convert interlaced HD to interlaced SD you have to deinterlace - resize - reinterlace. Period.
Question remains: why?
scharfis_brain
28th March 2008, 16:08
the process is:
1080i50 -> 1080p50 -> 576p50 -> 576i50
you COULD do it per-field wise. but you'll gain much better quality (especially in static scenes / areas of the image) if you deinterlace the interlaced video, resample it and then reinterlace it.
if you want to resample a interlaced video, I strongly suggest always to use the de/re-interlace approach.
manono
28th March 2008, 16:10
What I need to do is resize it to SD PAL ideally keeping the correct aspect ratio.
If you're resizing an interlaced Hi-Def source to Standard-Def for DVD, then you most certainly do need to deinterlace before resizing, followed by reinterlacing. Not doing so will destroy the field structure and completely ruin your video.
Gannjunior
28th March 2008, 16:26
if you want to convert interlaced HD to interlaced SD you have to deinterlace - resize - reinterlace. Period.
off course. but he said he needed to edit its video in AVID...so when you have to edit something the best way is to edit your "raw" file avoiding if possible every kind of compression or resize...only after all you will deinterlace, resize etc to SD...if not...is a nosense to do something like: "raw" HD-> mpeg2 SD -> AVID (editing, adding effect etc)-> new mpeg2 SD compression...
manono
28th March 2008, 16:37
If he plans to do the editing on the original source 1440x1080 video, nothing that scharfi (or I) said contradicts his intentions. The sample script was for the downsize, at whatever stage that occurs.
halsboss
29th March 2008, 01:21
the process is:
1080i50 -> 1080p50 -> 576p50 -> 576i50
May I ask if that's 1080i50 -> 1080p100 -> 576p100 -> 576i50 per http://forum.doom9.org/showthread.php?p=1110710#post1110710 ?
scharfis_brain
29th March 2008, 04:11
huh. no!
it is, what I wrote!
1080lines 50 fields/sec -> 1080lines 50 frames/sec -> 576 lines 50 frames/sec -> 576 lines 50 fields/sec
what's so unclear about that?
halsboss
29th March 2008, 11:03
Oh, I'd thought the link indicated a double-framerate deinterlace and interpreted IanB's deinterlace reinterlace thing as double-framerate...
1. E.g. Take a TFF source :-
[TB],[TB],[TB],...
Bob it
[Tb],[tB],[Tb],[tB],[Tb],[tB],... - Lowercase is interpolated fields
4,0,3 selects
[TB],[TB],[TB],...
scharfis_brain
29th March 2008, 14:19
I don't want do discuss this right now.
halsboss
29th March 2008, 23:31
OK.
Having engaged a brain cell, you were right (of course). The "50's" (and medication) threw me and I should have looked more closely at the FIELDS and FRAMES words. The 100 I said is nonsensical anyway (was thinking of my new TV).
For clarification for dummies like me, I think it goes :-
1080lines 50 fields/sec (25 frames/sec equiv) -> 1080lines 50 frames/sec -> 576 lines 50 frames/sec -> 576 lines 50 fields/sec (25 frames/sec equiv) ... it is doiuble framerate deinterlacing like scharfis_brain said.
spyros78
31st March 2008, 09:16
scharfis,
I understand now. you are right.
Many thanks all!
spyros78
31st March 2008, 12:46
a quick and okay quality script like this is a good point to start with:
LoadPlugin("DgDecode.dll")
LoadPlugin("YadifMod.dll")
Mpeg2Source("video.d2v")
Bicubicresize(704, Last.Height)
YadifMod(Mode = 1, EDeint = Bob(0, 1))
BicubicResize(Last.Width, 576)
SeparateFields().SelectEvery(4, 0, 3).Weave()
Ok, I went through line by line and more or less understand what the script does. In fact it was very helpfull as I now understand more about interlacing and avisynth scripting however, I have a couple of questions if its ok to ask.
1. Why resize width -> DeInterlace -> Resize Height and not DeInterlace -> Resize width & height?
2. Why SeparateFields and SelectEvery and create 100fps and then go back to 50fps? What do you achiece with SelectEvery? I do not understand the arguements.
Thanks in advance!
scharfis_brain
31st March 2008, 16:05
1) because it is faster without quality loss.
I also could resize horizontally after deinterlac, but then the deinterlacer would have to process all the pixels instead of only the shrunken mount.
Vertical resizing takes place after deinterlace, because on cannot scale interlaced contents vertically without proper deinterlacing.
2)have a look at the thread that halsboss linked to some post earlier.
spyros78
1st April 2008, 09:40
you're a star.
i'm now making a statue with your name on it.
sp.
scharfis_brain
1st April 2008, 10:56
huh ?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.