• Most new users don't bother reading our rules. Here's the one that is ignored almost immediately upon signup: DO NOT ASK FOR FANEDIT LINKS PUBLICLY. First, read the FAQ. Seriously. What you want is there. You can also send a message to the editor. If that doesn't work THEN post in the Trade & Request forum. Anywhere else and it will be deleted and an infraction will be issued.
  • If this is your first time here please read our FAQ and Rules pages. They have some useful information that will get us all off on the right foot, especially our Own the Source rule. If you do not understand any of these rules send a private message to one of our staff for further details.
  • Please read our Rules & Guidelines

Captain Khajiit's Basic Guide to Encoding with HCenc

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
This guide is now functional.  Advanced issues might be covered at some point.

Please read the whole of the guide before posting questions.  The guide is intended to be simple and accessible and is not intended for advanced users.  The author is well aware that the issues covered in certain sections are far more complicated.   Slightly-more-advanced notes are placed in spoiler tags: you can use the guide successfully without reading them and should do so if you want to keep things simple.


1.  Introduction

HCenc is a free high-quality MPEG-2 encoder.  The guide will show you how to encode your videos to DVD-compliant MPEG-2 streams using nothing but freeware.  Initially, it will cover NTSC, but I might cover PAL encoding at some point.  HD encoding will not be covered.

Tools

Download the latest version of HCenc. (I shall try to keep the link up to date.)
AviSynth
DVD Fab HD Decrypter
DGIndex
DGAVCDec
VirtualDub (This is included here to allow you to preview your AviSynth script.  If you want to preview your script, go to File→Open video file... not Run script...)
MediaInfo (If you are inexperienced, use this to check if your video is RGB or YUV.)
Notepad  (This should be on your system already under Accessories.)
eac3to
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
2. Writing Simple AviSynth Scripts

(A) Starting Off


Install AviSynth. Inside your AviSynth folder, you will see a directory called "plugins".

MPEG-2 Sources

If your source is MPEG-2, install DGIndex. Look in your DGIndex directory, find DGDecode.dll and copy it to your AviSynth plugins directory. Open your file in DGIndex.

File→Open Video→Field Operation→Honor Pulldown Flags
File→Save Project→Save as Type: DGIndex Project File (*.d2v)

H.264 Sources


If your source is H.264, install DGAVCDec. Look in your DGAVCDec109 directory, find DGAVCDecode.dll, and copy it to your Avisynth plugins directory.
Open your file in DGAVCDec. File→Open
Video→Field Operation→Honor Pulldown Flags
File→Save Project→Save as Type: DGavcIndex Project File (*.dga)

AVI Sources

If your source is AVI, do not worry about this sub-section. Go straight on to 2(B).

I do not intend to cover VC-1. Even if you have used a VC-1 source, you ought to have converted it to something else to edit it in, and I see no reason why you would have rendered a project in VC-1 before encoding to DVD.

(B) Writing the First Line of the Script

Install AviSynth. Open Notepad. File→Save As... MyScript.avs – do not forget to add .avs to the end.

If your source is MPEG-2, type the following, adjusting it to fit your directory structure.
Code:
Mpeg2Source("C:\Wherever\Whatever.d2v")

If your source is H.264, type the following, adjusting it to fit your directory structure.
Code:
AVCSource("C:\Wherever\Whatever.dga")

If your source is AVI, type the following, adjusting it to fit your directory structure.
Code:
AviSource("C:\Wherever\Whatever.avi")

N.B. Remember to use both inverted commas and brackets, whatever your source. ("")
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
3. Preparing Your Sources for Encoding

Encoders do not know what kind of files they are being fed. It is your job to make sure that you are handling your video correctly in terms of color space and luma range throughout your workflow. How you do this will depend on the editing program that you are using and is beyond the scope of this guide.

HCenc requires YUV (YV12 or YUY2) as input. For our purposes, YUV comes in two forms: Rec.709 and Rec.601. Rec.709 is for HD. Rec.601 is for DVD.

There are undoubtedly Rec.709 DVDs in existence. Some people think that they exist and are "legal". I think that they exist but are not "legal". I strongly advise you to convert to Rec.601 for DVD encoding. (The guide assumes that you will do this.)
Writing The Second Line of the Script

If your source is SD and YUV (e.g. if you have smart rendered from Womble), go straight on to section 4
(unless you are completely sure that you have a Rec.709 DVD, in which case follow the procedure given in the next paragraph).
If your source is HD and YUV, install Colormatrix, put ColorMatrix.dll in your Avisynth plugins directory and make this the second line of your script. (It will convert Rec.709 to Rec.601.)

Code:
Colormatrix(mode="rec.709->rec.601",clamp=0)
If your source is computer RGB (the luma range is 0-255), make this the second line of your script.

Code:
ConverttoYV12()

If your source is studio RGB (the luma range is 16-235), make this the second line of your script.

Code:
ConverttoYV12(matrix="Pc.601")
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
4.  Basic Resizing

If your source is DVD, skip to section 5.  Your script is done.

If your source is HD, add the following line to your script.  Then your script is done.

Code:
Spline36Resize(704,480)
AddBorders(8,0,8,0)

N.B.  I am not prepared to debate the resizing instructions given in this guide.  If you feel you know better, then you do not need the guide.  People who have corresponded with me over PM might have gone into more advanced cropping and resizing.  I might write a guide for this at some point, but for now I want to keep this simple to avoid confusing people.  If you want to discuss more advanced resizing, PM me; please do not post in the thread about it.
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
5. Using a Bitrate Calculator

Now that your script is ready, you need to calculate an average bitrate for your movie before proceeding to encoding. I use Videohelp's bitrate calculator to do this.

First, find the length of your video. You can do this in many ways. Using Mediainfo is one; previewing your script in Virtualdub is another.

Secondly, go to Videohelp's bitrate calculator, and click on the "Advanced" tab. Input the length and use the drop-down menu to select DVD-5 or DVD-9 etc. Change the number and bitrate of the audio track(s) to suit your DVD. (5.1 cannot be higher than 448kbps for DVD.) You will then be given an average bitrate figure. This is the only one you need to take from the bitrate calculator. I usually reduce it a little to allow some space on the disc e.g. if it gives me 5185kbps I will use 5000kbps. Use your common sense.
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
6. Encoding Settings

This section will assume that your video has a frame rate of 23.976fps. If it is 29.97fps, then you most likely should have performed an inverse telecine before editing. Please see the FAQ.

Encoding settings will be organized following those of HCenc's tabs that concern us and the little boxes into which they are broken up. Ignore settings that are not covered: they are fine as they are. The word "checked" obviously means that the radio button in question should be checked (a blue dot in a ring) or the box in question, ticked.

Main
files
input: Select your AviSynth script as your input file.
output: Choose an output filename and destination.
logfile: Choose an output filename and destination.

bitrate
average bitrate: checked
average (kb/s): Input the figure that you received in Section 5.
maximum (kb\s): 8000

profile: best

dc prec: 9

miscellaneous
SMP: checked
scene change: checked
autogop: 12
closed gops: checked
3:2 pulldown: checked

aspect ratio: 16:9 for widescreen or 4:3 for fullscreen (Ignore all the others.)

Settings 1
interlacing options
progressive:checked
TFF: checked

chroma downsampling
progressive: checked

Quantization
AQ: 3

Settings 2
miscellaneous
VBR Bias: 30
min bitrate factor: 1.20

luminance gain: 3
colorimetry: SMPTE170M

Settings 3
chroma output format
4:2:0 (YV12 or YUY2 input): checked

Matrix
matrix
built in matrix: checked

built in matrix: manono1
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
7. FAQ

How do I make sure my source is 23.976fps?


You should follow these steps, preferably before editing if you intend to edit lossless AVI e.g. in Vegas or Premiere; Womble users will have to convert afterwards.


Step 1

Rip with DVD Fab HD Decrypter.  (AnyDVD has a free trial and is a better program.)

Demux with PGCDemux by following this procedure.  Start the program.  Click Browse next to Input IFO and try opening each IFO of your ripped DVD in turn until you find the one that gives a runtime that matches your movie.

Settings
Mode: by PGC
Domain: Titles
Demux video stream: checked
Demux audio streams: checked

Check anything else you want. Fill out your output folder. Process.  The result will be an .m2v video file and at least one audio track.

Install AviSynth and DGIndex.  Look in your DGIndex directory, find DGDecode.dll, and copy it to your AviSynth plugins directory.
Open your video file in DGIndex.  File→Open
Video→Field Operation→Honor Pulldown Flags
File→Save Project→Save as Type: DGIndex Project File (*.d2v)

Open Notepad.  File→Save As... MyScript.avs –€“ do not forget to add .avs to the end.

Type the following, adjusting it to fit your directory structure.

Code:
 Mpeg2Source("C:\Wherever\Whatever.d2v")

N.B.  Remember to use both inverted commas and brackets. ("")

Step 2

N.B.  If you are unsure of any of the following, I suggest that you send me a sample via PM and I shall take a look.  (See the bottom of the guide for instructions on how to make a sample.)



(A) If the source is an NTSC movie, perform an inverse telecine by adding this line:

Code:
TFM()
TDecimate()

This produces great results on almost all live-action NTSC movies.  You will need to  download Tritical's TIVTC filters and put the .dll in your AviSynth plugins directory.   If your source is animation, you might try the following instead.

Code:
TFM(slow=2)
TDecimate(mode=1)

Occasionally, you might have a difficult NTSC source that TFM().TDecimate() cannot handle; if so, TIVTC has a number of settings that you might try and there are other filters that can perform an inverse telecine that you might try, but this is rarely necessary with movie DVDs.

(B)  If the source is a PAL movie, there are a number of situations that you might come across.  I will outline the two that are most common.

If films are converted to PAL properly, both video and audio are sped up to 25fps.  To convert to NTSC, you simply undo the speed-up and resize the video.  Most PAL movie DVDs are made this way, and if you open your source in DGIndex and scroll around and see no sign of combing, this is probably what you are dealing with.  Add the following lines to your script.

Code:
AssumeFPS(24000,1001)
Spline36Resize(720,480)
LimitedSharpenFaster()#optional sharpening after resizing
If you do decide to sharpen, download the plugin, which comes in the form of a script, in your AviSynth plugins directory.  Make sure it is called LimitedSharpenFaster.avsi so that it loads automatically.

You also need to slowdown your audio.  To do this I use eac3to.  (You might choose to use Besweet; if so, google it.)

This command line gives the pattern to follow.  You have to change it to fit your directory structure.

eac3to input.ac3 output.wavs -slowdown

The first part is the location of eac3to on your hard drive.  (You will find the .exe inside your eac3to folder.)
The second part is the location of the source file, presumably AC-3, on your hard drive.
The third part is where you want your output to be and what you want it to be called.
The fourth part is a switch: you just need to add it at the end.

For example,

"C:\eac3to\eac3to.exe" €œC:\Wherever\whatever.ac3 €œC:\Wherever\whatever.wavs€ -slowdown

You input this at the command prompt. (If you do not how to find this,  click on the Start button in the bottom left, and type Run into the  start box to bring it up.  Alternatively, on Vista and above, you can  copy and paste your command line into the search box and hit enter and  it should work.)

The result will be individual mono wavs that should be in sync with your video. If you do not want mono wavs, you can change the output to whatever you like.  For a .w64 file for editing in Vegas, adjust this to fit your directory structure as shown above:

eac3to input.ac3 output.w64 -slowdown

If you want to downmix to stereo (DPL II), adjust this to fit your directory structure as shown above:

eac3to input.ac3 output.wav -slowdown -down2 -Normalize

Proceed to step 3.

Films can also be converted to PAL by having frames blended together.  There is no speed up, so the audio does not require adjustment.  If you open your video in DGIndex and scroll around and do see signs of combing, then your PAL source probably has blended frames.  If so, download Yadif and put the .dll file in your AviSynth plugins folder and download SRestore, which comes in the form of a script, and put it in your AviSynth plugins directory.  (Make sure it is called SRestore.avsi so that it loads automatically.)
Add the following lines to your script.

Code:
Load_Stdcall_plugin("C:\Avisynth 2.5\Plugins\yadif.dll")#adjust this to match your directory structure 
Yadif(mode=1)
SRestore()
Proceed to step 3.

Step 3

If you need to convert to RGB, you can also add:

Code:
ConverttoRGB()#expands the luma range i.e. converts to what Sony calls "computer RGB"

If you are converting before editing, proceed to make a lossless AVI by doing the following.

Open the script in VirtualDub.
File→Open video file...
Video→Compression→your chosen codec (such as Lagarith)
Video→Fast Recompress
File→Save as AVI

If you are a Womble user and are converting to NTSC after editing, do not convert to RGB.  Load your script straight into HCenc.


Why do you recommend that people convert to 23.976fps and resize to 720x480 i.e. convert to NTSC?

The reason for converting to NTSC is that most people who view fanedits  are in North America.  While almost all European equipment plays NTSC,  most North American equipment cannot play PAL; consequently, the most  compatible DVD release is an NTSC DVD-5.  (A DVD-5 is a standard single-sided, single-layered DVD; a DVD-9 is a single-sided, dual-layered DVD – the ones that go through a layer change on playback.)


Why a DVD-5 and not a DVD-9?


You can certainly choose to release a DVD-9, but – strange though it may seem –€“ many people still cannot burn DVD-9s, so it is advisable to make a DVD-5 too if you can.  Unless your movie is considerably longer than two hours and twenty minutes, it is usually possible to compress it to fit a DVD-5 and retain good quality.


How do I make a sample?

Load your .m2v into DGIndex.  Use the square brackets [ ] in the bottom right to mark out a small section, preferably one involving plenty of movement, from somewhere in the middle of your movie.

File→Save Project and Demux Video

Upload your sample to a file host e.g. Sendspace.

Why does Virtualdub give me the following error message when I attempt to open my script in it?


AviSynth open failure: MPEG2Source: couldn't open source file, or obsolete D2V file.

DGIndex is probably picking up an old version of DGDecode.dll.   Sometimes other programs install  it too.   You must use the one that came with the latest version of DGIndex.    Try looking for other versions on your hard drive and deleting them.


Thanks

I would like to thank the following people for improving this FAQ by asking questions and spotting typographical errors:

Rogue-theX
TV's Frink
Gatos
FoolsFollowing
BladeRunner391
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,676
Reaction score
406
Trophy Points
193
Halp!

I'm trying to load a lagarith avi into HCenc using an avs script per the guide. I'm getting an error from HCenc, which unfortunately is cut off by the program...but here is what I can read:

error loading Avisynth script,AVISource autodetect: couldn't open file 'c:\distribute\FrinkFanedit\TPM_Frink\Ep1_The Ridiculous Menace\Rendered Media\maulreaction.avi' Error code: 3 (C:\Distribute\f
Unfortunately not much to go on. I tried a google search on Error code 3 but no dice. Here's the avs script for reference:

Avisource("c:\distribute\FrinkFanedit\TPM_Frink\Ep1_ The Ridiculous Menace\Rendered Media\maulreaction.avi")
Incidentally, I also tried The Film Machine on the avi file and got this error:

You have to choose Mediafiles with standard framerates like 23, 23.976, 24, 25, or 29.97 fps. Please choose another AVI/MP4/MOV/RMVB/MKV file.
It's worth noting that I'm using Vegas Studio Platinum 9, and all my clips are 23.976, but my project settings are 29.97 fps, and for some reason the program won't let me select 23.976 (it's not even an option in the pulldown).
 

Rogue-theX

Well-known member
Faneditor
Cover Artist
Messages
6,890
Reaction score
7
Trophy Points
81
You might need your script to look like this:
Code:
Avisource("c:\distribute\FrinkFanedit\TPM_Frink\Ep 1_ The Ridiculous Menace\Rendered Media\maulreaction.avi")
ConverttoYV12()

Im pretty certain you need a YV colorspace to encode with hc, but im a bit fuzzy about that. Khajiit???
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,676
Reaction score
406
Trophy Points
193
I guess I assumed that my lagarith avi was already YUV. Per the guide above, is there a way to check my luma range in Vegas?
 

Rogue-theX

Well-known member
Faneditor
Cover Artist
Messages
6,890
Reaction score
7
Trophy Points
81
I don't know about vegas, but maybe with virtualdub. Try this:
Code:
Avisource("c:\distribute\FrinkFanedit\TPM_Frink\Ep 1_ The Ridiculous Menace\Rendered Media\maulreaction.avi")
Info()
Load that in virtualdub by going File-->open video file--> whateveryourfileiscalled.avs
That should tell you what it is i think. Just remember to take the Info() out of the script before encoding or the info will be watermarked on the video ;)
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
No; Info() won't tell you about the luma range. You should know whether you have expanded the luma range or not by keeping track of your workflow.

ConverttoYV12() is correct if you have expanded the luma range. If you haven't expanded the luma range, you use ConverttoYV12(matrix=Pc.601).

Does your script now open in HCenc, Frink?
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,676
Reaction score
406
Trophy Points
193
I wouldn't even know how to change the luma range, so unless I did it by accident, or if someone else did it on one of their clips, it wouldn't be expanded.

So I tried this:

Avisource("c:\distribute\FrinkFanedit\TPM_Frink\Ep1_ The Ridiculous Menace\Rendered Media\TRMtest.avi")
ConverttoYV12(matrix=Pc.601)
And got back this:

error loading Avisynth script,Script error: expected a , or ) (C:\Distribute\fanedits\FrinkFanedit\TPM_Frink\Ep1_The Ridiculous Menace\Copy of test.avs, line 2, column 27)
Line 2, column 27 appears to be right where the closed parenthesis is, so.... ???

Incidentally, I also tried just using the ConverttoYV12() and got back the original Error 3 code I first posted about.
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
I wouldn't even know how to change the luma range, so unless I did it by accident, or if someone else did it on one of their clips, it wouldn't be expanded.

Well, actually when converting to RGB many applications expand the luma range by default, so it depends how you converted to RGB initially. I would guess that you did expand the luma range when converting, so I would assume that ConverttoYV12() is correct.

That error message usually means that there is a typing error in the script. It looks as if you've put a space after "Ep1" that shouldn't be there.
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,676
Reaction score
406
Trophy Points
193
I fixed the typo, but now I just get the Code 3 error regardless of the second line.

I'm starting to think there's a problem with the avi file, or maybe something with my computer. After all, The Film Machine wouldn't load the avi either. Would anyone be willing to take a look at the avi clip?
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
Yes; if you can render out a short clip and upload it for me, I'll have a look, but I still think that there's a typo. If you right click on the file and go to "Properties", you should be able to find the object name of the file under one of the tabs: in Windows 7, it's under "Security"; I don't know about the older versions. Try cutting and pasting it into the script and make sure that you open and close both brackets and inverted commas.
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,676
Reaction score
406
Trophy Points
193
Thanks Captain K, I'll PM you.

I'm not sure why you think there is still a typo. How is the object name of the file different than the file name itself? Again, here's the script:

Avisource("c:\distribute\FrinkFanedit\TPM_Frink\Ep1_The Ridiculous Menace\Rendered Media\TRMtest.avi")
ConverttoYV12(matrix=Pc.601)
 

Rogue-theX

Well-known member
Faneditor
Cover Artist
Messages
6,890
Reaction score
7
Trophy Points
81
Try capitalizing the "c" at the start of the script like this
Code:
AVIsource("C:\

I tried opening a script without the C capitalized and it wouldnt open.

EDIT: um maybe if i fire up my hard drive that might make a difference, lol, it actually doesnt make a difference if the c is capped, my bad, again, ill stay quiet now.
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,676
Reaction score
406
Trophy Points
193
Believe it or not, I had already tried that.

I keep thinking if the script was really the problem, then I would be able to open the clip with The Film Machine instead, but that won't open it either.
 

Captain Khajiit

Well-known member
Donor
Messages
2,685
Reaction score
8
Trophy Points
48
Yes; Avisynth is not case sensitive.

e.g. aViSoUrCe() is just as good as Avisource()

People tend to follow capitalization conventions when they post scripts, simply to make it easier for the reader.

As an update on Frink's problem, the AVI clip that he sent me opened first time in Virtualdub and HCEnc, and I successfully encoded it with HCenc. That's why I'm almost certain that the problem lies in a typo.

EDIT: Frink, you are using the latest version of Virtualdub, aren't you? Moreover, are you certain that you saved your script with .avs at the end?
 
Top Bottom