h264enc logo
.:: h264enc Frequently Asked Questions ::.
Last updated: 12-July-2008

The h264enc package includes a man page which you should read carefully. The package also includes a README.encoding file which is located in the doc directory and describes the encoding process in depth. Depending on the Linux distro you are using, the doc directory is usually located in /usr/share/doc/h264enc or /usr/share/doc/packages/h264enc. If you have installed h264enc using the install script included in the tgz compressed package, then this directory is located in /usr/local/share/doc/h264enc

Here are some of the most frequently asked questions I receive from users... Feel free to send me more questions if the ones below don't answer it for you. Please note that the questions and answers below are subject to the latest available version of h264enc.

h264enc is an interactive script. What this means is that it asks you questions and you have to answer them with either 'y' or 'n'. However, if you don't want to use something, then instead of always providing 'n' as an answer, you can just hit Enter.
- Why a shell script and not a GUI program?

Well, this has a lot to do with the history of h264enc. About 3 years ago, I was tired of always providing the MEncoder parameters on the command line whenever I wanted to encode something, so I needed a quick and dirty fix for that. And what is more faster to write than a shell script? There are other reasons though. Shell scripts are very easy to write, are less prone to bugs and are small in their sizes - not that anyone cares though. h264enc was for about 1 year in private use before I made the decision to go public with it. I'm also more comfortable with scripting than with C or C++ coding and somehow I love their simplicity. Yes, shell scripting can be very restrictive when you need to do something (very) complex but in the case of h264enc, nothing really complex is done. It's basically a "collector" script for user input enhanced with automatic functions to retrieve information from DVDs and do some other stuff like cropping and muxing. One also has to ask himself about what a GUI does for 95% of the encoding process? The simple answer to this is that a GUI does absolutely nothing. It just sits there in memory displaying a fancy progress bar and that's it. So there you go, h264enc is just a stupid script which happens to work quite well for me, and I hope for others too...


- Why an interactive script?

Because if one wants to support the amount of video/audio filters and audio codecs, there is just no other way but to write a menu-driven interactive shell script.


- What do I need to get started?

That's already explained in the man page of h264enc but here it goes again. You'll need MPlayer 1.0rc1 or higher compiled with libx264 support, lsdvd for DVD scanning, LAME support in MPlayer/MEncoder for MP3 audio encoding, FAAC support in MPlayer/MEncoder for AAC audio encoding, mkvmerge if you want to conver the AVI into the Matroska container or MP4Box from gpac if you want to convert the AVI into the MP4 container, tsMuxeR for the TS container and ogmmerge from ogmtools if you want to convert the AVI to the OGM container.


- Does it support multi-pass encodings?

Yes, of course! h264enc supports 1-pass, 2-pass, 3-pass and fixed-quant (constant quality/constant rate factor) encoding modes. Using a 3-pass encoding is not really recommended as it provides a very small benefit over a 2-pass encoding. Sometimes it can even make the encoding a bit worse than 2-pass.


- Why is encoding so slow?

The H.264 coder is very processor intensive by default. This comes from the fact that it uses motion estimation and search algorithms which are very CPU hungry. Unless you have a supercomputer at home or are willing to wait a long time (sometimes days at the highest possible quality), you should stay away from presets like UHQ and IHQ as it will take a very long time to encode the content using these presets.


- Does h264enc supports other languages besides English?

No. h264enc is not localized so the only language supported is English. It's kind of hard to support other languages given the current code base of h264enc. I'm not saying that it can't be done but at the moment I'm not really interested in localization.


- Can I display/export DVD information?

Yes you can! h264enc uses the functionality of the 'lsdvd' program to full extent. h264enc supports displaying extensive information about a DVD disc and also exporting that information to a file on disk in text, perl, python, ruby or xml format.


- How do I encode a DVD VIDEO_TS folder/DVD ISO image which is on my hard disk?

This is easy. When asked upon if you want to encode a video file or a DVD, answer for DVD and provide as DVD device the top directory of the VIDEO_TS folder. For example, say you have a directory called DVD in your own home directory. If the VIDEO_TS folder is inside the DVD directory, then just specify as DVD device /home/your_username/DVD (replace your_username with the correct value). You can also mount a DVD ISO image using the loop device and encode it. Open up a console, login there as root and issue this command.

mount -o loop /path/to/iso/iso-image.iso /path/to/mount-point

Where mount-point is a directory you choose to mount the DVD ISO image. When h264enc asks you to specify the DVD device, just provide the mount point of the DVD ISO image and there you go :)

One can also directly specify the path to the ISO image and encode it. In this case, you don't have to mount it.


- Can I dump the contents of a DVD disc to a ISO image?

Yes, this is also possible with the '-iso' option which uses the 'pv' utility (pipeviewer - which displays a nice progress bar) to dump the contents of a disc to an ISO image. Note that some DVD discs use new protection algorithms and unlocking of these discs with MPlayer may fail, thus creating the ISO image out of such discs will also fail. If 'pv' is not found on the user's system, then 'dd' will be used instead. Before dumping the contents of a DVD disc, make sure you have enough space on your hard drive. h264enc by default checks the available disk space in the output destination directory and will warn you and exit if it detects that the space left over is less than or equal to 9 GiB.


- When I want to encode only a specific DVD chapter, it starts encoding it but continues until the DVD ends. What's wrong?

Well, you didn't specify the end of the chapter you are willing to encode. For example, say you want to encode only chapter 2 of a DVD. If you only provide 2 as a chapter, this will tell MEncoder to start encoding from chapter 2 but it will not tell it when to stop so the encoding will continue until the end of the DVD. Now, to only encode chapter 2, you have to make MEncoder aware of this, thus you have to provide 2-2 and MEncoder will only encode chapter 2 from the given DVD. If you want to encode from, say, chapter 2 till the end of chapter 5, then provide 2-5.


- Can I export the DVD chapters information to a file on disk?

Yes! h264enc uses the 'dvdxchap' program from the 'ogmtools' package to export the DVD chapters information in simple text-based format.


- Can I import DVD chapters information into the MKV/MP4/OGM containers?

Yes, this is also supported. You have to first export the chapters information to a file on disk. Then you will be presented with an option to import this information into the MKV/MP4/OGM containers. Note that in the case of the MP4 container, the muxing program 'MP4Box' stores the chapters information in a special atom. For this reason, you will need a player (either soft or hardware based) which is capable of reading this information.


- Is there support for encoding from a different DVD angle?

Yup. That's also supported :)


- Can I use spaces for both input and output files?

Yes! h264enc is written to escape spaces in file names for files and directories.


- What if I provide a destination folder for the output file which doesn't exist?

Don't worry, h264enc will check for it and create one if it doesn't exist. If creation of the destination directory fails, then h264enc will warn you and exit.


- What if I'm running out of disk space in my destination folder?

Every time you run the h264enc script it does checking on both the output destination folder and its own temporary folder. If it detects that the space left over in one of these directories is less than 4 GB it will warn you about that.


- Does h264enc use a configuration directory, and if so, where is it?

Indeed. h264enc uses its own temporary directory to store information it needs to parse like during auto-detection of some option. It's more a temporary directory than a configuration one as the files will be deleted after the encoding is done and sometimes even sooner than that. The temp directory is located in your own home directory and is a hidden one called .h264enc. Please do not delete any of the files stored in there during an encoding process as this will interrupt the process. After encoding (and container conversion if desired) is done, h264enc will clean this directory.


- Is there support for batch encoding?

Yes there is! h264enc supports exporting the MEncoder parameters and the container muxing commands to an options file. Every time you configure the encoding for a video file or DVD, it appends the commands to this file. After you're done configuring everything, you can load the options file with h264enc -b /path/to/file/optionsfile. That way, one can let the PC do the whole job of encoding multiple video files/DVDs after each others and remuxing the encodes without user interaction.


- What if my input video file has more than one video and/or audio stream?

That's not a problem. h264enc scans the input video file to see if it has more than one video stream in it and if so, it lets you select which video stream to encode. The same goes for more than one audio stream in input video files.


- Is there support for pre/postprocessing video filters?

Yes there is! h264enc supports 5 deblock/dering postprocessing filters (spp, uspp, fspp, pp7, ha/va/dr), 4 denoise filters (denoise3d, hqdn3d, ow, tn), one noise filter (noise), one (un)sharp mask/gaussian blur filter (unsharp), 10 different
deinterlacers (lb, li, ci, md, fd, l5, yadif, tfields, mcdeint, kerndeint), 5 inverse telecine/3:2 pulldown filters (pullup, filmdint, ivtc, detc, telecine) and one interlacing filter (tinterlace combined with the phase filter). The deblock/dering, noise, denoise and (un)sharp mask/gaussian blur filters all have tunable parameters and are supported by both DVD and video file encodings. The same goes for the deinterlacing filters, though only one of them has tunable parameters - the adaptive kernel deinterlacer. The inverse telecine/3:2 pulldown filters are configured to do their task as best as possible.

- Which container formats are supported?

h264enc supports five container formats. The native MEncoder AVI container, Matroska, OGM, TS and the MP4 container which is native for H.264 video. Conversion to MP4/MKV/OGM/TS is done using external tools (MP4Box, mkvmerge, ogmmerge and tsMuxeR).


- Does h264enc supports quality presets?

Yes it does! h264enc has a total of 41 different video quality presets one can choose from. It is even possible to write your own quality preset file and load that file with h264enc. In the 'doc' directory of the h264enc package, there is a 'preset.cfg' skeleton file which one can use as reference to write his/her own presets and use them for encoding. Please read through the notes of the 'preset.cfg' file to give you a better idea on what is supported and what not.

Loading a custom preset file is just a matter of: h264enc -2p -p cp /path/to/file/custom_preset.cfg


- What about portable devices? Are there presets for them?

h264enc has built-in presets for the Apple iPod, Apple iPhone, AppleTV, Nokia S60, Sony PSP, Sony PS3 and the Microsoft Zune and XBOX 360 devices. For each device, there are two presets available. A normal and a high-quality preset. Please note that I cannot guarantee that these presets will work on all devices without a problem. It is best to upgrade the firmware of your device to the latest available version.


- What is this Bits per Pixel value I see every time when dealing with video bitrate and how is it related to image quality?

Color depth is a computer graphics term describing the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel (bpp), particularly when specified along with the number of bits used. Higher color depth gives a broader range of distinct colors. For more information, I'd suggest you
read the Wiki on bits per pixel.

- How is the bits per pixel value calculated?

Actually it is a very simple formula which multiplies the bitrate with 1000 and divides the outcome of it over the multiplied sum of the resolution width, height and frames per second (FPS) value.

bpp image




- What is the bits per block value and how is it calculated?

In MPEG type compression, each frame is broken into many small 16x16 pixels macroblocks. Each one of these 16x16 macroblocks consists of four 8x8 luminance blocks and two 8x8 chrominance blocks. The bits per block value represents how many bits each of the 16x16 macroblocks get. Good values are between 37-52 bpb. The bits per block value is calculated as follows:



bpp image




- Does h264enc supports auto-cropping?

Yes it does! It supports it for both DVD and input video files.


- Is it possible to dump DVD subtitles to a file on disk?

Yes! h264enc supports hardcoding the subtitles into the movie or dumping them to a file on disk in VobSub format.


- How do I load the subtitles from the files in MPlayer?

If you have selected to dump the subtitles to a file on disk, then MEncoder will create 2 files - an idx file and a sub file. These files will have the same name as the output name you have provided for the movie, except they will have the .idx and .sub extension in their names. For example, if you have provided as output /home/your_username/H264.avi then the name of the idx file will be /home/your_username/H264.idx and that of the sub file will be /home/your_username/H264.sub - replace your_username with the correct value.
To load these files with MPlayer, simply open a console and type this:

mplayer /home/your_username/H264.avi -vobsub /home/your_username/H264

If you need more information on subtitle loading in MPlayer, I suggest you read the man page of MPlayer and look at the -vobsub option.


- What about importing the ripped subtitles into the MKV/MP4/OGM containers?

That's also supported. If you have chosen to dump the selected subtitle to disk in VobSub format, then h264enc will ask you if you want to import it into the chosen container. Note that the OGM/TS containers do not support VobSub subtitles, thus importing the subtitles into these containers is not supported.


- What about interlaced content?

h264enc supports both interlaced encoding and deinterlacing through one of the 10 supported MEncoder filters. Which one you use for deinterlacing depends on the content and personal preferences. A lot of people still prefer the good old Linear Blend deinterlacer (lb), I myself prefer the FIR Lowpass 5 and Yadif deinterlacers. At the moment, Yadif is the most advanced one but is also a fairly new deinterlacer. If you deal with video which every now and then shows interlacing, then you can try out Donald Graft's Adpative Kernel Deinterlacer with a threshold. This deinterlacer will remove interlacing when a specified threshold is reached and will leave progressive frames alone. Further, h264enc also supports interlacing your progressive content with 'tinterlace' combined with the 'phase' filter. Note that if you want to interlace your progressive content (which is actually not adviced) you will have to use progressive PAL at 50 fps or 100 fps or progressive NTSC content at 59.94 fps or 119.88 fps as input. During the interlacing process the PAL frame rate will be reduced to 25 or 50 fps and the NTSC frame rate will be reduced to 29.97 or 59.94 fps.


- What about frame rate values?

h264enc has built-in code to auto-detect the frame rate value of the input source. However, this can be (very) tricky for Progressive NTSC and mixed Progressive NTSC/NTSC content, especially DVDs, since the built-in code only detects the FPS flag set on the video stream. In the case of Progressive NTSC content, a lot of DVDs "lie" about their frame rate by setting the FPS flag to 29.970 but they actually run at 23.976 FPS. In the case of mixed Progressive NTSC/NTSC content (also known as Soft Telecined, see topic below), the FPS flag set on the video stream is not correct at all, since this type of content switches frame rates forth and back between 23.976 and 29.970 FPS during playback time. For this reason it is best to know the FPS of the content in advance so, if needed, you can set the correct FPS value.


- Can I do frame rate conversions?

Yes, this is also possible. h264enc supports the following frame rate conversions:
  • PAL/SECAM Double (50p) -> PAL/SECAM (25p) (50 fps -> 25 fps)
  • PAL/SECAM Quad -> PAL/SECAM Double (100 fps -> 50 fps)
  • NTSC Video (30p) -> NTSC Film (24p) (29.970 fps -> 23.976 fps)
  • NTSC Double (60p) -> NTSC Video (30p) (60 fps -> 30 fps)
  • NTSC Double (60p) -> NTSC Video (30p) (59.940 fps -> 29.970 fps)
  • NTSC Double (60p) -> NTSC Film (24p) (59.940 fps -> 23.976 fps)
  • NTSC Quad -> NTSC Double (119.880 fps -> 59.940 fps)
  • PAL/SECAM -> PAL/SECAM Double (50p) (25 fps -> 50 fps)
  • NTSC Video (30p) -> NTSC Double (60p) (29.970 fps -> 59.940 fps)
- What is Pulldown/Telecine/Inverse Telecine/IVTC, etc and how to deal with it?

Telecine/Pulldown is a process meant to increase frame rate for a specific purpose. Pulldown Reversal or Pullup and Inverse Telecine or IVTC is the opposite of this process. There is a lot of great information out there which explains this process in depth, so I will only give a short summary and then point to external links...

To summarize it, Telecine/Pulldown is the process of increasing the frame rate of content originally shot at 24 fps (or 16 or 20) to a frame rate suitable for a specific video standard. Telecine and Pulldown is very often used in NTSC and to some extent in PAL content where Pulldown is used to speed it up from 24 to 25 fps. The process of converting a 24 fps content into a 29.97 fps one is called 3:2 Pulldown. There are other Pulldown methods, like 2:3, 2:2, 2^12:3 (or 2:2:2:2:2:2:2:2:2:2:2:3 Pulldown), the latter often used to avoid the 4% increase in sound pitch when converting 24 fps content into 25 fps PAL one. Telecine comes from the words television and cinema and is often necessary as television can only display video at 29.97 fps (for NTSC) or 25 fps (for PAL/SECAM) while cinematic content is often shot at 24 Progressive frames.

If you look at Telecined content and if you do not understand how Telecine and Interlacing is made, you will often mistake the Telecined content for Interlaced. Please, do not think that Telecine is exactly the same as normal Interlacing. Yes, both are very similar at first sight but are not 100% the same thing. For example, content pulled down to 29.97 fps is still fundamentally Progressive, it is just represented in an Interlaced manner. With truly Interlaced video, each field (where two fields comprise a frame) represents two discrete moments in time. The same is not true for Telecined content, except for two out of every five frames, but that's only an artificial characteristic of the process which can be losslessly reversed. To really bring back the Telecined content to its original frame rate, you have to apply a Inverse Telecine/Pulldown Reversal process. This process can restore for example a 29.97 fps Telecined NTSC content to a 23.976 fps Progressive NTSC content. Telecine comes in two forms; hard and soft. Hard Telecine is when the content is stored at playback rate (29.97 for NTSC or 25 for PAL) with the Telecined frames. Soft Telecine is when the content is stored in its original Progressive film rate (24 or 23.976 fps) and a special flag is set inside the video stream which tells the video player to apply the specific Pulldown effect at playback time. If you open up a console, fire up MPlayer and playback a DVD, sometimes you will see messages like demux_mpg: 24000/1001 fps progressive NTSC content detected, switching framerate and demux_mpg: 30000/1001 fps NTSC content detected, switching framerate while playing the DVD. This means that the DVD you are playing is Soft Telecined and if you want to encode it you should apply a Inverse Telecine process on it. Soft Telecined DVDs are very often from the NTSC camp, although PAL ones do exist but are very rare.

h264enc supports both Hard Telecining and Inverse Telecining of NTSC-only content. Inverse Telecine/Pullup can be done with one of the following supported filters: pullup, filmdint, ivtc or detc. Which one you choose depends on the content and your needs. A lot of people prefer to use the pullup filter while I sometimes prefer the filmdint one over the pullup as it seems to give better results in certain situations. It is always good to encode for a few minutes in 1-pass mode, hit CTRL+C and watch the sample to see if the filter you chose gives you the desired result. h264enc also supports Hard Telecining your encodes. However I do not advice to Hard Telecine the content you are willing to encode as Hard Telecine can be very tough to deal with and sometimes it is not possible to remove it 100% without hurting the content is some way. The Hard Telecine option is only there if you really really need to Hard Telecine your encodes for some reason. Because the Telecine/Inverse Telecine process also involves frame rates, if you have previousely provided an output frame rate value, this value will be overwritten to match the correct FPS for the chosen Telecine/Inverse Telecine process. Below are external links with excellent info on what Telecining and Interlacing is and how to deal with each one of them.

- Do I have to use a deinterlacer when using the Inverse Telecine/Pullup process?

No. The inverse telecine/pullup filters handle everything for you.


- What are matrix files and how do I use them?

In image compression, Quantization is a lossy compression technique used to compress a set of values to a single quantum value. By reducing a number of discrete symbols in a stream, the stream becomes more compressible. A matrix file contains specific quantization values which are used together with a Discrete Cosine Transform (DCT) matrix to carry out the above mentioned compression. For example, the human eye is fairly good at seeing small differences in brightness over a relatively large area, but not so good at distinguishing the exact strength of a high frequency brightness variation. This fact allows one to get away with a greatly reduced amount of information in the high frequency components. This is done by simply dividing each component in the frequency domain by a constant for that component, and then rounding to the nearest integer. Many video compression algorithms, like Xvid and H.264, allow custom matrices to be used. Most but not all of the custom matrices usually lead to a higher compression than the default built-in matrices of the video compression algorithm.
h264enc supports loading of custom matrix files when using quality presets or manual codec configuration (Advanced Settings). The h264enc package also includes 15 quantization matrices from Sharktooth, MP4Guy, Audionut and Soulhunter. These files are located in a sub-directory called matrices of the doc directory of the h264enc package. There is also a README.matrices file included in the package which gives more information about these matrix files and how to use them.


- Does it support other software scalers than the default Bicubic of MEncoder?

Yes it does! It supports 11 different software scalers you can choose from


- What about video bitrate calculation for a target file size?

No problem, that's also included but only for 1-, 2-, and 3-pass encoding modes. If you use one of these modes, the first question in the Miscellaneous Configuration will be about target file size. Answer y there and provide the desired target file size in Megabytes. Note that this does not work with VBR AAC audio encoding as I need more information on how to convert VBR values to bitrate values for the AAC codec.


- How many audio codecs does h264enc supports?

At the moment, h264enc supports 10 different audio codecs - MP2, MP3, AC3, AAC, AAC+, Vorbis, WMA, FLAC, PCM and ADPCM - In addition, h264enc also supports the COPY and NOSOUND formats of MEncoder. Please note that in order to be able to encode to WMA audio, you will need the latest SVN version of MPlayer or MPlayer 1.0rc2. For AAC+, neroAacEnc is required and for Vorbis audio, oggenc is required. Only the MP4 and the MKV container is supported when encoding to AAC+ or Vorbis audio.


- Does h264enc supports encoding more than one audio stream?

Unfortunately this is not supported. There are two issues that make it difficult to support. h264enc by default outputs to the AVI container and MEncoder doesn't support adding extra streams to this container. You can have more than one audio stream in the AVI, however the extra stream(s) will have to be added using external tools like avimerge or avidemux and this will add extra dependencies to h264enc which I'm not willing to support. MP4 and the Matroska container can have more than one audio stream in them but h264enc has a very simple implementation which only does muxing of the final encode into the MP4 and/or the Matroska container. It is also a bit hard to implement this with the current code base of h264enc and it will completely break the audio code of the script.

Also, if I had to make the script to only encode the video first, then to dump the audio streams and encode them to the selected codec (mp3, aac, etc) and then mux all of this into the chosen container, this can introduce major A/V sync issues, especially when doing a process which drops/duplicates frames during the encoding, like the interse telecine process. I will not break A/V sync just so I can add support for more than one audio stream in the chosen container!

If you want to have more than one audio stream, then I suggest you encode the original content with the NOSOUND option of h264enc, dump the audio streams from the original content to WAV files, encode them to some compressed audio format and mux the video and all the encoded audio streams using mkvmerge, MP4Box, avimerge or avidemux (depends on the container you want to use).


- What about multi-channel audio encoding?

That's supported too, but only by the AC3, AAC, AAC+, PCM, Vorbis and FLAC audio codecs. Note that routing could be a problem since MEncoder doesn't take routing into account when encoding to multi-channel audio. However, if you're using the latest SVN version of MEncoder, then the routing will be fixed by now.


- How come every time I use multi-channel AAC audio encoding, the bitrate I have specified is not respected?

That's because AAC needs more bitrate to allocate in order to satisfy all channels. For example, if you encode to AAC Quadro (4 channels) it will require ~170 kbps. The bitrate will be even higher when you choose for 5.1 channels. Also keep in mind that the FAAC AAC encoder doesn't have a CBR encoding mode and the bitrate will strongly depend on the complexity of the sound.


- Which audio filters are supported?

At the moment 3 audio filters are supported: resampling, volume normalization and the volume filter.


- How come h264enc doesn't support muxing to MP4 with AC3, DTS or WMA audio?

This is actually a limitation of the MP4 container itself which doesn't support AC3, DTS and WMA audio. However, the next draft of the MP4 container will add support for AC3 audio.


- Does h264enc supports file splitting?

Previous versions prior to 8.1.6 supported file splitting, however I decided to removed this functionality as the code got too unmanageable, espacially if one wants to support five container formats.