Links

Thursday, September 23, 2010

Automated HD Video Resizing Script

There are lot of steps involved in converting HD video to SD format for DVD authoring using freeware tools, check out my blog Converting High definition video to DVD compliant MPEG2 for the steps involved.

In order to simplify and make it a one step process, I have created a batch file which does the required job.

Requirements

  • You should have your video clip as a Mpeg 2 I-Frame only Hd 19200 x 1080 interlaced, square pixel m2v file
  • You should have AVISynth installed, you may get it from http://www.avisynth.org/

Instructions

  • Download the complete package containing all the required freeware tools from here: http://www.titasraha.com/tools/hd2sd/hd2sdtools.zip

  • Extract hd2sdtools.zip into a location of your choice

  • Go to the command window and CD to the directory where you have your HD m2v file. (make sure that the extension is m2v)

  • run the bactch file with your mpeg file as a parameter without the .mtv extension:

    drive:\path\hd2sd YourMpgFile

  • After all the encoding and conversions are complete, you will have a file named YourMpgFile_DVD.m2v

    This is the DVD compliant wide screen anamorphic mpeg2 file, ready to be authored as a DVD

Batch File code

@echo off
set RootPath=%~d0%~p0

SET CACHEDIR=%RootPath%cache
SET VDUBDIR=%RootPath%vdub
SET DGDIR=%RootPath%DG
SET HCDIR=%RootPath%HC023

%DGDIR%\DGIndex -IF=[%CD%\%1.m2v] -OF=[%CD%\%1] -exit

echo LoadPlugin("%DGDIR%\DGDecode.dll") > %1.avs
echo MPEG2Source("%1.d2v") >> %1.avs

%VDUBDIR%\vdub.exe /s %VDUBDIR%\HDToSd.vcf /p %CD%\%1.avs %CACHEDIR%\SD.AVI /r
echo avisource("%CACHEDIR%\SD.AVI").ConvertToYV12() > %CACHEDIR%\SD.AVS

echo *LOGFILE          %HCDIR%\HD2SD.log > %HCDIR%\HD2SD.ini
echo *BITRATE          7000 >> %HCDIR%\HD2SD.ini
echo *MAXBITRATE       8000 >> %HCDIR%\HD2SD.ini
echo *PROFILE          best >> %HCDIR%\HD2SD.ini
echo *AUTOGOP          18 >> %HCDIR%\HD2SD.ini
echo *DC_PREC          10 >> %HCDIR%\HD2SD.ini
echo *INTERLACED >> %HCDIR%\HD2SD.ini
echo *WAIT             0 >> %HCDIR%\HD2SD.ini
echo *MATRIX           mpeg >> %HCDIR%\HD2SD.ini

%HCDIR%\HCenc_023.exe -i %CACHEDIR%\SD.AVS -o %CD%\%1_DVD.m2v -ini %HCDIR%\HD2SD.ini

del %1.avs
del %1.d2v


Tuesday, September 21, 2010

Converting High definition video to DVD compliant MPEG2

I have tried using Vegas Pro and Adobe Premiere CS4 to convert my canon HF s100 1080i .mts files to mpeg2 for DVD authoring, in my opinion the conversions were horrible. There were lines (not interlace lines) which clearly looked like were due to resizing of the video.

I could not stand it so I looked for a solution over the internet, tried a lot of different tools and settings, nothing seems to work well, finally as it stands now I have come up with the following workflow which I think is the best so far.

[Here is an automated script to do all that.]

Tools Required
Adobe Premiere CS4 - This is for editing and exporting to an I-frame only MPEG2 file at highest possible quality, I downloaded the settings from here.

Free tools required (which does the real job)
AVISynth (at least ver 2.5) [link: www.avisynth.org/]
VirtualDub [link: http://www.virtualdub.org/]
DGMPGDec [link: http://neuron2.net/dgmpgdec/dgmpgdec.html]
HC Encoder [link: http://hank315.nl/]

I would like to give full credits to the respective authors of the tools, I can't believe that freeware tools like these does a better job than the ones that costs thousands of dollars.

  • Step 1: Export Clip to an I-frame only encoded MPEG2 file
    I followed the guide here to export my clip out of Adobe Premiere, look for the section "Exporting out of Premiere", lets call the exported clip mpgiframe.m2v

  • Step 2: Use DGIndex to index the MPEG2 file and save the project d2v file
    Run DGIndex.exe (you will have this file if you have downloaded DGMPGDec, see the link above) and open the "mpgiframe.m2v" file created in step 1, then save project giving it a name "mpgiframe", this will create a d2v (mpgiframe.d2v) file to be processed by DGMPG decoder in the later step.

  • Step 3: Create the AVI Synth file to be exported to Virtualdub
    Here is the AVS script which uses DGMPG decoder to decode the m2v file, which will eventually be served to Virtualdub.

    LoadPlugin("\pathtodll\DGDecode.dll")
    MPEG2Source("mpgiframe.d2v")


    open notepad and save the above code as mpgiframe.avs file

  • Step 4: Use Virtualdub to resize the AVS file and export it as AVI
    This is the critical step which most compressors fail to do properly. Run Virtualdub and open the mpgiframe.avs file, go to Video-> Filters->Add->resize.

    Aspect Ratio: Disabled
    New Size: Absolute 720 x 480
    Filter mode: Lanczos3 (this filter made my day)
    Interlaced checked

    Now select File->Save as AVI, (I am saving as an uncompressed AVI, I dont care about the size cause I have a ITB scratch disk to take care of that, the uncompressed AVI is the default VirtualDub settings you can find under Video->Compression)

  • Step 5: Use HC Encoder to encode the AVI file as a DVD compliant MPEG2
    Finally I convert the AVI file into DVD compliant MPEG2 file using the GUI version of the HC Encoder, just one problem with the AVI file is that the generated file color space is not compatible with HC Encoder we again create a AVS file with the following contents

    avisource("GenerartedAVI.avi").ConvertToYV12()

    Now just load this file in HC encoder and generate the DVD Compliant MPEG2 file for your DVD project