CodecPage
 video encoding&cleaning


 
MPEG2
(DVD video) encoding

A free and good MPEG2 encoder is HC-Encoder. Other than the (discontinued) champion CCE (see below), it can also do HDTV, and at a very competitive quality, and constant quality VBR, that CCE offers in the utterly expensive pro version only.

For HDTV, though, I strongly recommend the h.264 encoding described at the HDtv page, unless you are preparing video that should also play on old hardware. It works easy and reliable and delivers very good quality.

HC-encoder is good, but a bit picky: It only accepts .d2v frameserving pseudofiles (from DVD2AVI or DGindex) or .avs (AVIsynth) input, and it reads all its settings from a .ini file that has to be prepared some way. There is a GUI for this but I would avoid it except for exploring the settings, as it behaves somewhat inconsistent with saving parameters in .ini files. Parameters are also explained in HC's web wiki.

To feed a video into HC, one could write a short script directly reading a video file, like this:

Videoclip=DirectShowSource("U:\TVprogram.mpg")
ConvertToYV12(Videoclip)
This however relies on Directshow filters to read the file, and these are extremely sensible against stream errors. This would abort somewhere in any other TV recording.

The DGindex I also don't recommend any more due to crispness and sync issues. For information, it went as follows:  open the source MPEG2 file with DGindex, optionally mark beginning and end frames, and save the 'project' as a .d2v file. Now DGindex is busy saving the audio of the source separately and making the (small) pseudo file that will later deliver video to HC-Encoder via the VFAPI codec. 

Best free method: VirtualDub and HC

A safe and versatile method relies on frameserving with VirtualDub

All we need then is an avisynth script adapting the VD frameserver to HC-Encoder. Here it is:

Videoclip=AVIsource("f:\video\video.vdr")
ConvertToYV12 (Videoclip)

Save this for example as read source.avs and open it with HC. 
Then make a hc.ini file like this:

*INFILE              C:\PortableApps\HC025\readsource.avs
*OUTFILE          F:\encoded.m2v
*LOGFILE          C:\PortableApps\HC025\enc.log
*MAXBITRATE   8000
*PROFILE          best
*AUTOGOP       15
*CQ_MAXBITRATE  11.000
*DC_PREC        10
*INTERLACED
*ASPECT           16:9
*INTRAVLC         2
*MATRIX             mpeg

Save this into HC's directory as well. You can download the two files as a zip archive here. Of course, you have to edit the filenames and paths to fit your needs.

If you now start HC.exe, it will use the hc.ini and readsource.avs right away and start encoding.

What is important: we use the CQ_MAXBITRATE command instead of CQ. With CQ alone, HC would ignore the MAXBITRATE command and could produce excessive bitrate paks that e.g. cause GuiDVD to abort.
This HC.ini file serves for almost any job, if you adapt it a bit:
If the source is progressive, delete the INTERLACED command.
If the source is 4:3, replace ASPECT 16:9 by ASPECT 4:3.

Multiplexing

Separate video and audio streams may be good for DVD authoring, but if you want to re-combine them into plain MPEG2, read the multiplexing page.


Opening various file formats

If the original HD source isn't MPEG2 but AVC (x.264), WMV, or something else, we have to look how to decode it for HC encoder.

Old: Avisynth interface

As long as the file plays in media Player, i.e., you have the required DirectShow codecs installed, you can still use an AVIsynth script, like
     
Videoclip=Directshowsource("D:\clip.mp4")
      ConvertToYU12(Videoclip)

A script can also open a frame-serving from VirtualDub, and VirtualDub itself can be used for any DirectShow source with another script, as described in the cleaning page.

New and better: VirtualDub direct

Since recently, Virtualdub can also directly with h.264 and most other sources if we add fccHandler's plugins.
This method is highly preferred, as it is a lot more robust than reading file with AVIsynth and the wacky Directshow filters it relies on (more on this at the hdtv page).
With this, we can also use all filtering capabilities of VirtualDub, before encoding. As described above already, a script to open a VirtualDub frameserver looks like follows:
     
Videoclip=AVIsource("u:\aname.vdr")
     ConvertToYV12 (Videoclip)

Audio

When transcoding from MPEG2 to MPEG2, re-encoding the sound is not necessary nor recommendable. Demultiplex the sound from the source with Mpg2Cut2 and re-use the extracted audio with the compressed video. Some programs allow to select the re-encoded video and the old video as video and audio sources in TMPGenc's multiplexer, it will automatically extract the sound from the old video and mix it with the new one in one .mpg file.

Possible but not recommendable: MPEG2 encoding with Virtualdub alone

This we mention just for completeness:
with ffdshow installed, you can select ffdshow as video compressor in VirtualDub and select any of its encoders, for example  the MPEG2 one. What you get is an avi file with mpeg2 in it. To be able to play this, you must also enable the "mpeg2 in avi" decoder in ffdshow. Which also means this will hardly play on anything but a PC with ffdshow. Using this avi for DVD authoring is also not possible, and so is recovering a standard mpeg stream for the purpose. You may, however, open this avi with Virtualdub again and frameserve to other applications for another recompression...

 CCE (Cinemacraft Encoder)

The best MPEG2 encoder used to be Cinemacraft (an affordable version was CCE Basic), which unfortunately has been discontinued. The following information is kept here for reference.

Preparing/filtering for CCE is best done with VirtualDub, Either you save the result as an intermediate file (e.g., DV with the Mainconcept encoder to preserve quality at a reasonable file size), or you frameserve to CCE (best option for one-pass encoding). Installing the frameserver is described here.
In Virtualdub, start the frameserver, give the frameserver any name and give the .vdr (signpost) file the name and path you want for your  final output. .vdr files can directly be opened with CCE. You may start several instances of Virtualdub including frameserving parallel, and open them all with CCE, for sequential processing (overnight or so).  If you want to run this in background while using your machine, give all the Virtualdub tasks low priority in Windows Task Manager (Ctrl-Alt-Del invokes it).

See these Examples to judge on your own.

Here is how to use CCE Basic for DV and other sources:

First, start it and draw your avi into its window.

Double click on the avi and set the following parameters:

Always uncheck 'Quality Settings' if the source is not too noisy. This will give you significantly better sharpness. Leave the slider at 'Complex' (if it does anything, it's better that way).
Check 16:9 if your source is widescreen.
If you want to archive very crisp and difficult sources, select a higher bitrate or just constant (CBR) bitrate as high as possible (9000). Settings (this time for the newest CCE version) here.
You may specify an external audio source file, and you may select "System stream" if you want to produce an already multiplexed MPEG. Default is that video and audio are written to separate files (OK if you use TMPGEnc DVD Author, but not for most others).

Now press the Video Button.

Offset line 1 (default) is already correct for DV sources. For scenes captured with MJPEG or frameserved with Virtualdub from non-DV sources such as MPEG, 0 would be appropriate. For non interlaced sources, Progressive frame and Zigzag should be selected. For NTSC video, set N/M to 4 !
The Luminance setting here is valid for PAL, but I could not find any effect of it at all, anyway.

Then Audio. Set it to Stereo ! (Joint stereo is for people without ears, because in CCE this is intensity joint stereo, e.g. it kills all spatial information and makes shortwave effects).
If not yet so, set 48.000 Hz. DVD needs that.

Finally, you should disable YUY2 (this is one setting where the default is faulty):

(otherwise, contrast would be increased, bleaching some detail in bright image areas !).

Press all OK and encode.

Some final hints for movie encoding:
Don't forget to set offset line to 0 with all another than DV sources.
16:9 non interlaced films can be done with less than 2500 kbps, especially if the source is cleaned. For example, try 1500/2000/6000 for the min/avg/max bitrates. It's important not to choose the minimum bitrate too low if the average is already low, otherwise some low action scenes might get blocky. The quality at this bitrate is quite good, believe it or not. For an average of 2500 or more, the minimum value can usually be set to zero. The maximum bitrate could also be 9000, the only reason to sometimes keep it lower is to avoid wasting bits to noisy scenes.
For movies already coming from VHS tape, maybe even in long play, you can set CCE to "half horizontal resolution". Uncheck the "DVD compliant" box with this, or it won't do it (the stream will nevertheless be DVD compliant, the DVD standard allows for half resolution encoding).
This is still about as sharp as long play VHS. Bitrates for this can be set as low as 1000/1300/4000, allowing for about 7 hours on a single DVD. I would not recommend it for standard play VHS in PAL countries (Europe etc.). There, "half" resolution is visibly below that of the VHS tape.

Tools

DVBviewer full version
VirtualDubMPEG2
DVD2AVI with VFAPI plugin, plus VFAPI reader codec.
From: http://arbor.ee.ntu.edu.tw/~jackei/dvd2avi/    
(no longer recommended)
DVDpatcher
MPEG2Cut
MP3trim
MP3merge
toolame/toolameGUI and VFAPI converter: See doom9.
ffdshow contains many codecs, activate only those you need !
AVIdemux a universal encoder/processor that also handles AVC, MP4 etc. Can encode to AVC (H.264) MP4 in good quality.
CoreAVC fast playback codec for AVC (H.264); better use an accelerating decoder fit to your hardware, though.
AC3ACM AC3 decoder for media player, Virtualdub etc.
Media Player Classic versatile replacement for the good old Media Player 6.4
XVID HDTV capable MPEG4 (H.263) compliant codec (some hints here)
HC-Encoder is the best freeware MPEG2 encoder and capable of HDTV.
DGindex
can demuix and generates .avs input for HC. No longer recommended
AVIsynth is useful feeding input to HC-Encoder, and for many other tasks.

 


 



Copyright (C) 1998-2012; all rights reserved. All materials in these pages are presented for scientific evaluation of video technologies only. They may not be copied from here and used for entertainment or commercial activities of any kind.
We do not have any relation to and do not take any responsibility for any software and links mentioned on this site. This website does not contain any illegal software for download. If we, at all, take up any 3rd party software here, it's with the explicit permission of the author(s) and regarding all possible licensing and copyright issues, as to our best knowledge. All external download links go to the legal providers of the software concerned, as to our best knowledge.
Any trademarks mentioned here are the property of their owners. To our knowledge no trademark or patent infringement exists in these documents; any such infringement would be purely unintentional.
If you have any questions or objections about materials posted here, please
e-mail us immediately.
You may use the information presented herein at your own risk and responsibility only. We do also not guarantee the correctness of any information on this site or others and do not encourage or recommend any use of it.
One further remark: These pages are covering only some aspects of PC video and are not intended to be a complete overview or an introduction for beginners.