Log in

View Full Version : encoding guide: Avisynth used in Encoding.


Jeremy Duncan
20th June 2009, 14:33
Youtube videos showing the guide

step 1 (http://www.youtube.com/watch?v=2AVjrBqWyDU&feature=channel_page)
step 2 (http://www.youtube.com/watch?v=cT6i0dWf73I&feature=channel_page)
step 3 (http://www.youtube.com/watch?v=VJNIxXIgH-w&feature=channel_page)
step 4 (http://www.youtube.com/watch?v=z7YENHanD3E)
Step 5 (http://www.youtube.com/watch?v=IsYeZ1BHCQw)

__________________________________________________________

Audio and Video samples for you to work with in your learning process.
They are from 2 HD trailers.

audio (http://www.mediafire.com/?lzgimajfomd)
video 1 (http://www.mediafire.com/?ywjmlttweuy)
video 2 (http://www.mediafire.com/?z2mmnmmjdjj)




__________________________________________________________

How to get NTSC Telecine (a.k.a. 3:2 Pulldown) dvd to 23.976 fps movie.
What is 3:2 pulldown? http://neuron2.net/LVG/telecining1.html

Software used:
__________________

Rippers:
anydvd (http://www.slysoft.com/en/anydvd.html)
dvd fab free (http://www.dvdfab.com/free.htm)

Demuxer:
tsmuxer (http://www.videohelp.com/tools/tsMuxeR)

Indexers:
mkvtoolnix (http://www.videohelp.com/tools/MKVtoolnix)
Graphedit (http://www.videohelp.com/tools/GraphEdit)
dgmpgdec (http://neuron2.net/dgmpgdec/dgmpgdec155.zip)
Haali media splitter (http://www.videohelp.com/tools/Haali_Media_Splitter)

Encoder:
me gui (http://sourceforge.net/project/downloading.php?group_id=156112&filename=megui-0_3_1_1028.exe&a=55118057)

Avisynth:
Avisynth (http://downloads.sourceforge.net/avisynth2/Avisynth_258.exe?use_mirror=voxel)
Microsoft Visual C++ 2005 Redistributable (http://www.microsoft.com/downloads/details.aspx?familyid=200B2FD9-AE1A-4A14-984D-389C36F85647&displaylang=en)
Microsoft Visual C++ 2008 Redistributable (http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en)
Plugins kit: all the plugins in one folder. (http://www.mediafire.com/?votrnvnmhjl)
NicAudio (http://nicaudio.codeplex.com/)
vsfilter (http://downloads.sourceforge.net/guliverkli/vsfilter_20051125.7z?use_mirror=hivelocity)



Step 1: Getting a encoding environment ready
_____________________________________________________________

Install the sw.

Software list:
mpc hc
ffdshow
dgindex
avisynth
Haali media splitter
mkvtoolnix
megui

- When you open the installed megui program the first time it will ask to update, choose yes and update everything in the list.
It might need to update again after the first update.

After the first update installs it will ask you which encoder settings to import.
I right click the list and select all and then press ok, I do this for all the lists and when it asks to overwrite previous scripts I select yes.

Install the avisynth plugins.

- Put these plugins into the avisynth plugins folder. The avisynth folder in the c:\, program files.
LimitedSharpenFaster.avsi
LimitedSupport_09Jan06B.dll
MT.dll
mt_masktools.dll
NicAudio.dll
RemoveGrainSSE3.dll
VSFilter.dll

- Put the avisynth.dll into the system32 folder, assuming you have a 32 bit windows operating system. Allow it to copy over the previous version.

Configure the sw

- software list:

ffdshow video decoder
Enable mpeg2 decoder
Set vc1 to wmv9
set output to yv12 when encoding

mpc hc
check all boxes in internal filters tab
set the ffdshow in external filters

dgindex
Videotab, idct algorithm, sse2
videotab, field operation, force film. This is what makes the film 23.976 .
videotab, yuv->rgb, tv scale

megui
Set the "video encoding, encoding settings" choose "x264:dxva hd HQ"
Click the "Config" tab and set the bitrate to 12000.

Make a txt file a avs file

Open notepad and save file to desktop.

Change the file extension on the file you just made from txt to avs.
Start, control panel, folder options, view, uncheck "Hide extensions".
On the notepad file you saved to desktop it will say "encode project.txt"
Delete "txt" and replace it with "avs".

- avs Script samples

# for hd like vc1 or avc
DirectShowSource("C:\Users\canteen\Desktop\Matrix1.grf",audio=false,fps=23.976)

# for sd dvd mpeg2
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
mpeg2Source("C:\Users\canteen\Desktop\Matrix1.d2v")

Make a timecode txt file

Open notepad and save txt file to desktop and call the file Timecode

Copy and paste this code into the Timecode file and save:
# timecode format v1
assume 23.976

Rip your movie.
If you use anydvd for high definition the files will be in the bdmv, stream folder.
Sometimes it's in one big file, but other times it's in many smaller files around 1 GB or more.
in the case it's split up and not one big file you need to open the files with a blu ray player to see which files you need to use with tsmuxer.

Demux video from audio
open tsmuxer and add your m2ts files then demux it.
if you highlight the hd audio it has a option to downgrade it to either dts or ac3.



Step 2: Index the video file
_______________________________________________________________

mpeg2

- dgmpgdec
It is different software than dvd fab free.
With it we will make the movie 23.976 fps. Here is how:

Double click the dgindex icon to open dgindex.

- File tab, open, dvdfab folder, Main movie, video ts.
Click number 1, then press add and get 2 and so on in numerical order till you got them all then press ok.

e.) click the file tab, Save project to desktop.


vc1

a.) mux the vc1 to mkv using mkvtoolnix.

Create a text file with this code and call the file Timecode.:
# timecode format v1
assume 23.976

- Open mkvtoolnix and add the file.
Click the video to highlight it then from the timecodes button add the timecodes file you made.
Click start muxing.

- use graphedit to build a grf file
Build grf : Haalimediasplitter-WMVideodecoderDMO

b.) Open Graphedit.

- Click the Graph button and the Insert filters button.

- From the list choose Directshow Filters and click "Haali Media Splitter", then click insert filter.
There will be a pop up asking you for a input file. Change "All Media Files" to "All Files (*.*)".
Then go to where you saved the file you made with mkvtoolnix and click that then click open and in graphedit you will see the mkv file.

- Now from the Same directshow filters list you chose Haali media splitter from, scroll to the bottom of that list and click "WMVideo Decoder DMO" and then "Insert Filter".
It will be the color Green.
Now Close the Insert filters list by pressing the red "x".

- In the graphedit you will see two boxes: ____.mkv, wmvideo decoder dmo.
These boxes have tiny squares on them. Join the boxes using the same method as drag and drop.

Click the tiny box in the mkv file and drap it to the wmvideo decoder where it says in0.
Once you join them the boxes will have color.

- Now save this work from the file tab.

avc

\\\\ index the avc video using mkvtoolnix, timecode text file, graphedit, ffdshow
- Load the demuxed avc video into mkvtoolnix
- click the video file to be able to load the timecode file.
Then, load the timecode file.
- choose the fps in the "format specific options" tab. In fps choose 24000/1001
- Click the start muxing tab.

\\\\ Graphedit
- Open graphedit, open the Graph, insert filters tab.
- Under directshow filters choose Haali media splitter.
it will ask for a video file, go to where you saved the mkv you made with mkvtoolnix and choose that.
In order to see the file you need to choose All files(".")
- Then from the insert filters tab, select ffdshow video decoder.
- In the graphedit box, Join the two filters together, joining the boxes that say "Video" and "In" by dragging and dropping one box on top of the other one.
When done successfully, the boxes will light up with color.
- Save the file and then link to the grf file graphedit made in your avs file.



Step 3: Crop your video using megui avs script creator
_______________________________________________________________


Initializing the avs script editor to then use either method 1 or method 2

- From the megui tool tab, click avs script creator.

- Open the avs script creator and load your avs file. Your avs file should look like this. Notice nor resizing or cropping in the code:

directshowSource("C:\Users\red\Desktop\Blade Runner.GRF",audio=false,fps=23.976)

- From the Input Dar, go to "Select AR".
If the dvd box says 2.35:1, then type in 2.35
If the dvd box says the aspect ratio is 1.78:1, then type in 1.78
Then press ok.

Method 1

- Check the "Resize", "Suggested resolution mod16", "Crop" boxes.

- Assuming your source resolution is 720, 480 or 720, 576 Widescreen, And there is 8 pixel black bars on the left and right side of the video, change the 720 to 704 using the down arrow to the left of 720. Pressing it once will change the resolution to 704.

- Assuming the video is 720, 480 or 720, 576 Widescreen and there is no 8 pixel black bars on the left and right side, then keep the resolution to 720.

- Click the "Clever anamorphic encoding"box.

- You can now save the file.
Open the saved file and copy and paste the code you need to the avs you opened in the avs script creator process.

I needed to get 1.78:1 and after doing this my created avs looked like this:
# Set DAR in encoder to 16 : 9. The following line is for automatic signalling
global MeGUI_darx = 16
global MeGUI_dary = 9
Import("C:\Users\canteen\Desktop\test run2.avs")
#deinterlace
crop( 0, 0, 0, 0)

LanczosResize(704,464) # Lanczos (Sharp)
#denoise

And my working avs looked ike this after all this work was done and I'm ready to start encoding:

mpeg2source("C:\Users\canteen\Desktop\afro.d2v")
global MeGUI_darx = 16
global MeGUI_dary = 9
LanczosResize(704,464)

Method 2

- Assuming your source resolution is 1920x 1080 High Definition.

- Check these boxes:
Resize, Suggested resolution mod 16.
This will change the resolution of the 1920, 1080.

- Uncheck Suggested resolution mod 16.

- Check the crop box.

- Click Auto crop.

- Save the file.

- Copy and paste the results into your working avs file as done in method 1.

______________________________________________________


This picture shows how to initialize avs script creator to then do either of the two methods below

http://thumbnails17.imagebam.com/4044/b1793440437963.gif (http://www.imagebam.com/image/b1793440437963)

Method 1
http://thumbnails15.imagebam.com/4044/dd503840437964.gif (http://www.imagebam.com/image/dd503840437964)

method 2
http://thumbnails.imagebam.com/4044/74622840437966.gif (http://www.imagebam.com/image/74622840437966)

- You may be asking which method is the best one?
There is no Best method is the answer. Try a method. When have a finished avs with the values you got from the avs script editor, open the avs with megui, and there will be a picture pop up and it will show the aspect ratio of that picture.

If you do not think the aspect ratio shown in the picture is good enough, then try the other method. Simple as that. :)



Step 4: Encode the video using the Avs file, then Mux the audio in
_______________________________________________________________

- Open the me gui program and in the input tab there is a "avisynth script tab". Open this and then select the avs file you made earlier.

File format is mp4 at default and I do not change this.
In the video output tab I can choose a location where to save the file.
I then click the "Enqueue" tab and the choose the "Queue" tab and then press the start button.

Wait for it to encode your movie.

Mux the audio into the encoded video


4.) Add the audio into the file megui made

Method 1.) using tsmuxer
a.) select add: This would be the file you made with me gui.
b.) select add again: This would be the ac3 made with dgindex.
c.) Click the ac3 audio and set the delay shown in the ac3 file name. Example -255
If the ac3 dgindex made has a minus sign, do not forget to add this to the audio delay box in tsmuxer.
d.) Select output path. Where you will save the file
e.) I save as ts muxing
f.) Click start muxing and it is made and you are done.
Now you have a 23.976 fps video.

Method 2.) using Megui
a.) From the Megui Tools tab, select Muxer
b.) Select Adaptive muxer
c.) Video input is the mp4 you encoded
d.) Audio input is the audio dgindex made. Add the delay the same way as done with tsmuxer, if the audio file shows a delay number then don't forget to add the minus sign when you type the delay number in.
e.) Muxed output is what the file will be called and where it will be put once the muxing is done
f.) Click the Queue button
g.) Now from the Queue tab click the Start button and it will add the audio to your video file

Play the video in cyberlink powerdvd for dxva acceleration
Assuming you used method two of muxing in the audio. You now have a mkv file. but powerdvd won't play the mkv.
Change the mkv extension to mpg
Then powerdvd ultra will play your hd encoded movie.

Step 5: Encode the HD Mpeg2 video
_______________________________________________________________


DGindex.
Open the HD Mpeg2 and set videotab, field operation, "Honor Pulldown Flags".

AVS file format:

loadplugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
mpeg2source("C:\Documents and Settings\megatron\Desktop\Yows MPEG2.d2v")
assumefps(24000,1001)

Notice i set assumefps. This is because the d2v dgindex made is in fact 23.976 fps.
Setting assumefps makes the video smooth.

Cropping with avs script creator.
Since I didn't know the aspect ratio of the trailer I open the avs I made with avs script creator and left the acpect ratio it showed, then I ran through method 2 of the cropping section.

Gavino
20th June 2009, 15:45
Jeremy,

The script you give at 3(a) requires the special MT avisynth.dll, and also several plugins not in your initial list. Are these really necessary for a straight encode?

Jeremy Duncan
23rd June 2009, 07:27
Add subtitles
_______________________________________________________________


Subtitles

a.) Starting from step 3(b) from above.
You add this as your avs file instead of the other one:

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\VSFilter.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\nicaudio.dll")

video=mpeg2Source("C:\Documents and Settings\Home\Desktop\3.d2v")
audio=NicAC3Source("C:\Documents and Settings\Home\Desktop\3 T80 3_2ch 448Kbps DELAY 0ms.ac3")
AudioDub(video,audio)
textsub("C:\Documents and Settings\Home\Desktop\srt file.srt")

LanczosResize(848,480)

converttoyv12()

b.) Now you need to make a .srt file. You will use the program called "SubRip".

Open subrip, if you already saved the previous character matrix then open that from the character matrix tab.

click file, open vobs, open ifo. Go to the folder you ripped the movie too and open the VTS_01_0.BUP file. Click start.

You will see a blue colored letter. The subrip program does not know what letter this is and needs you to type what letter it is.
Once you have typed what letter it is press the ok button and the next letter.
This is why it's important to save the character matrix, so it's easier each time and less blue letters to fix.

When you are done, click the subtiles file tab and click save as. Save the srt where you want.
In the subrip window, click character matrix and save character matrix file.

Put the vsfilter.dll, nicaudio.dll into the avisynth plugins folder.

Now from the guide carry on to step 3 (d).

How to split a vc1 section from a movie

__________________

- You first demuxed the vc1 using tsmuxer.
- Split only 1 chunk from the vc1. If you split more than one chunk the second and consecutive chunks don't work properly.
Only the first chunk works properly, so make it a large enough size: 500MB or 1GB.
- Use the program mkvtoolnix and the Timecode and mux the vc1 to mkv.
- Make the graph in graphedit and directshowsource uses the grf as a video vile.

- if you make the whole movie a mkv then use dgsplit and take a chunk of the mkv.
Then run the chunk you split through mkvtoolnix again with the timecode file,
the video will be all jerky for some reason.
So doing this isn't as good as taking the chunk from the source vc1.

- Taking a chunk is good for encoding tests as it's faster than encoding the whole movie which can take a day or more.

Notes
_____________________________

\\\\ Method 2 of adding the audio is for when using tsmuxer doesn't work.

\\\\ The large avs script in the guide is for 60hz monitors.

As such if you use pal and have a 50 Hz monitor, then you do not need the code called "changefps(60".
I'm assuming your video frame rate is 25fps so then deleting that bit of code with double your frame rate to 50fps.

\\\\\ It's crashing on me.
Install the "Microsoft Visual C++ 2008 Redistributable"

\\\\\ It's crashing on me and I'm using a windows 32 bit os.
In the system32 folder is there the msvcp71 and msvcr71.dll?

\\\\\ It's crashing on me and I'm using a windows 64 bit os.
In the syswow64 folder is there the msvcp71 and msvcr71.dll?
In the syswow64folder is there a avisynth.dll?

\\\\\ It's best not to do this with movies that have subtitles because getting the subs to then encode them in is difficult.

\\\\\ It's best not to do this stuff with movies that have a sub root menu offering a regular version and extended version as ripping the version you want is confusing. I don't think dvdfab free or slysoft anydvd offer to rip the extended vs regular version and just jumble everything together.

\\\\\ Mainly this guide is to get a idea of how to encode and get up and going. It's used by me and I decided to share it with you. :)

\\\\\ If you add subtitles you can't turn them off. They're burned in.

\\\\\ There is no chapters. it's all one big file that can be skipped through by clicking the skip bar with your mouse.

\\\\ HC Enc is much faster encoder than Megui is if both use the settings in this guide.
I used hcenc version 22 and found it works with the ans script in the guide, so i linked to that version of hcenc.
The newest hcenc may also work but I have not verified this. :)

\\\\ How do I play the mkv I make in cyberlink powerdvd so I can get videocard hw acceleration?
You rename the file extension from mkv to mpg

\\\\ About cropping. If you select a video using your avs, and when the video screen pops up,and that video has a miniature video picture on the screen that is not what the rest of the movie resolution is.
Then when you crop using the avs script creator it will crop out the black border surrounding that miniature picture.
So you need to have a picture the size of the main movie in the pop up box when you start the avs script creator.

\\\ The subtitles portion of the guide is old, and I think you may be able to add the srt file in using the megui audio muxer as it has a spot to add a srt file.

\\\\ Why are some mpeg2 videos 23.976 fps and use homor pulldown, and some use force film?
The ones that use honor pulldown re from hd videos that don't need force film. The ones that use force film are from sd dvd ntsc dvd's.

Jeremy Duncan
29th June 2009, 08:42
I have updated the guide and added 4 youtube videos showing how the good works.

nordmariner
17th July 2009, 05:06
Thanx a lot mate...