Suggestions for Encoding in MediaCoder

Discuss about generic usage of MediaCoder.

Moderator: HuggiL

Posts: 3116
Joined: Tue Jun 23, 2009 2:45 pm
Location: Sydney, Australia

Suggestions for Encoding in MediaCoder

Postby meRobs » Mon Sep 27, 2010 5:20 pm

[updated 13 Feb 2013]

If you are unfamiliar with the use of MediaCoder, I suggest you begin by reading viewtopic.php?f=17&t=8917&start=0 and, as suggested in that Guide, maybe try the Setup Wizard or the UI Plugins. However, back to the topic ...

Section 1: General Comment
Section 2: Video & Audio
Section 3: Suggested Settings
Section 4: Notes

1. General Comment
When considering the conversion of an audio and/or video file, the first question to ask is “What do we want the output file for?” If it is for uploading to the web, such as YouTube, it may need to be an FLV file. If it is for an MP4 player it could be an MP4 file, if for a Mobile phone, maybe a 3GP file or if it is required for editing in an NLE video editor or playable in a DivX player, an AVI?

The descriptors: FLV, MP4, AVI, etc, are Containers, a type of packaging for audio and video streams. And there are many types of container. For example, MediaCoder build 4740 is able to deliver audio/video material in 21 different container types. Furthermore, each container is able to package the streams in a variety of different formats, with each defined by its Codec and referred to on the video and audio tabs of MediaCoder under 'Format'. For example, for video, there are 23 different formats and for audio, 23. But, don't panic, yet!

In summary, then, the container describes what the file looks like on the 'outside' with no hint as to what is on the 'inside'. To see details as to what is on the inside, open the file in MediaCoder and check the Properties panel, at right, or, for more info, select the Item menu and click 'Details of Selected File', which accesses the freebie 'MediaInfo'.

However, it is important to realise that for any given container not all combinations of video and audio formats are suitable, or even allowed. Also, each player, phone or video editor would have its own restrictions as to the formats. So, the first thing you need to do is:
find out what combinations of formats and containers are allowed or preferred by the intended output device. Look in the instruction manual or Google it. For example, a DivX player may require an AVI file with the video as MPEG4 and the audio as MP3 or AC3. An FLV may need to have its video as H263 or the more recent H.264 (= AVC), with the audio as MP3. And so on.

Having chosen the container and the formats for the video and audio streams we need to tell MediaCoder which Decoder to use to read the source file and which Encoder to use for the encoding. The first is called the 'Source' in MediaCoder. For video, a good all-rounder for the Source is MEncoder, and for the Encoder, I would begin by using FFmpeg, which is very flexible. For audio, I always start with Auto Select for the Source and FFmpeg for the Encoder. However, just to add to your confusion, there are many other options. For example, in build 5185, there are 17 video encoders and 26 audio encoders!

2. Video & Audio
But, that is not all! We need to specify the video and audio characteristics in more detail.
For video, both the frame size and the frame rate should be specified on the Picture tab and both will depend on the output device. The first is expressed in pixels and the second as frames per sec (fps). For example, if it ends up on a TV, it may need to be 720x576 pixels at 25 fps for PAL or 720x480 pixels at 29.97 fps (select 30000/1001) for NTSC. In many devices, such as a mobile phone, the frame size and rate would be smaller.

The third video characteristic is its bit rate, expressed as kilobits per sec (kbps). This sets the amount of storage space made available to the Codec for describing the video detail (colour, etc, for all the pixels). On the other hand, the bit rate required for a given quality depends on how many pixels are to be described in each frame and in each second. The more we increase the frame size and frame rate the greater should be the bit rate and hence the file size. With all else the same, a lowering of the bit rate would potentially lower the quality; and the decision as to what bit rate to use is subjective and may need some experimentation (use a small test file), starting with the value given in the Table below.

The audio also needs specifying. On the Audio tab of MediaCoder we need to set its bit rate and its sample frequency. The latter defines into how many pieces (samples) the original analogue sound had been cut when creating its digital equivalent and, obviously, the greater the sample rate the higher the quality and the greater we need to specify the bit rate. For example, a CD normally uses a sample rate of 44.1 kHz and a DVD, 48 kHz. Then, the bit rate should be at least 128 kbps, depending on the complexity of the sound and the efficiency of the encoder. At the other extreme we could set Mono (requires less data that stereo) at only 16 kbps and 8.0 kHz.

3. Suggested Settings in MediaCoder
Rather than specify the settings as a Preset (see: viewtopic.php?f=17&t=8131 ) I give my suggestions as MediaCoder-tab settings in the following Table. The reason? If the build of MediaCoder used to establish a Preset is too removed from the build you are using, it is unlikely to work (viewtopic.php?f=17&t=8521&start=0)!

The following Table has the settings for six file types that should work in most builds of MediaCoder (see Test Report in: viewtopic.php?f=17&t=12306). For settings suitable for importing to an NLE video editor like Adobe Premiere, see: viewtopic.php?f=17&t=11959.

Begin with File > Revert All Settings or, preferably, a Starter Preset (see section 3 in viewtopic.php?f=17&t=8131).
(!empty($user->lang['IMAGE'])) ? $user->lang['IMAGE'] : ucwords(strtolower(str_replace('_', ' ', 'IMAGE')))

* see Note 10 .... ** see Note 9 .... *** see Notes 6 & 13
# see Note 7 .... ## see Notes 4 & 11 .... ### see Note 15
^ Target rates (Average BR) .... ^^ see Note 14 .... ^^^ see Note 13
$ see Note 17 .... $$ see Note 16 .... $$$ see Note 18
When using the CUDA Encoder, the Multiplexer should be enabled or on Auto Select.

Please NOTE: in practice you should probably set Resize and Frame Rate at "Original", especially the frame rate. The simplest way to do this is to blank them out, by unchecking them (see Note 16, below). Use other values only if you need the change (I chose the above tabulated values just for testing purposes)!
If Resize is not set at 'Original' and the Aspect Ratio is different from that of the source file (see: viewtopic.php?f=17&t=8197&start=0 ), you will probably need to Crop (see: viewtopic.php?f=17&t=8188&start=0 ). This is especially so if you use “Set DAR = 16:9”, as suggested for MP4 (see Table).

Use of the Table
Select a group of settings that has formats and a container closest to the specifications you require and give it a go. If the outcome is satisfactory, then all is well. Otherwise, modify the settings (format, container, etc) to your taste, although, I do suggest you change only one setting at a time and revert if it fails. When things go wrong, always return the settings in the Table.

Each of the set of values in the Table is merely a suggested First Try.
Of course, you may need to vary the frame size ('Resize') and frame rate to suit the intended device. When doing so, choose multiples of 16 for Resize, like those in the Table, or multiples of 8, to ensure efficient operation of the video Codec. This is because video Codecs usually process in micro-blocks of 8x8 or 16x16 pixels. The exception is the value 854 given for MP4. It is not even divisible by 4, yet, it was chosen. with all other settings for MP4, to suit the requirements of YouTube as at Feb 2013!
If your choice results in a different Aspect Ratio (viewtopic.php?f=17&t=8197&start=0) you may need to change the Crop settings (viewtopic.php?f=17&t=8188&start=0) on the Picture tab.

Also, you may wish to vary the bit rates, to achieve the file size or quality you want, and the audio ‘Resample’ frequency. Changes in these values should not affect whether or not the set up works. So, set up the values in the column of your choice, change the bit rates, etc (see 'Group D' above), and create a Preset so that you may revert to these settings whenever things go wrong. Preset creation is explained here: viewtopic.php?f=17&t=8131.

If you are happy with the result then the job is done. Otherwise, keep modifying the settings, one at a time, until it works to your satisfaction. Finally, overwrite or replace the Preset with these values. For an example of a step-wise change, see Note 10, below.

On the other hand, you may wish to experiment with the other Codecs (formats) and Source/Encoder combinations available in MediaCoder. In that case, expect troubles! You may get a result more to your liking, such as a better quality to bit rate ratio, but, it may require much trial and error. For example, see Notes 6 and 10, below.

The settings given in the above Table may be grouped according to their significance in achieving a successful outcome:
Group A: the Container and multiplexer. The container is usually known, as defined by the intended purpose (player, etc). The multiplexer is also important and may need changing, depending on the other choices.
Group B: the Format for both the video and the audio streams. Usually, these are also known since they are the types of streams you aim to achieve by the conversion. However, of the ~23 formats available for each stream type there may be more than one that is suitable.
Group C: the Source and Encoder combination for the video and the audio. These are critical for success! There are, for example, ~13 options for the audio Source and ~24 audio encoders and it would be surprising if all combinations, or even most, would work for any chosen format! Indeed, most won't work! Fortunately, in most cases, a safe combination for the audio is Auto Select for the Source and FFmpeg for the encoder. For Video, a flexible and reliable combo is MEncoder as ‘Source’ and FFmpeg as Encoder, as given in the above Table. Although, sometimes, FFmpeg works better as a video source when converting MKV source files, according to Stanley (viewtopic.php?f=28&t=11156).
Group D: the Bit Rates, Sample frequency (Resample) and Video Frame characteristics (Resize, Frame rate and Aspect Ratio) are not critical in the sense that their choice should not affect whether a transcode will work, when using the above choices (formats, encoder, etc) – they will affect only the quality of the output! However, there are a few exceptions. For example, not all PAR values (Pixel Aspect Ratio) will work and the DV Video Codec (format) for video works only for PAL parameters (see: viewtopic.php?f=17&t=8197&p=25018#p25018).

Note 1: by default, the picture tab has Crop 'Disabled' and the Aspect Ratio at 'Keep Display AR'. Try this combination first and if the output file looks distorted, you may need to set Crop as 'Expand to Fit'. This would be because the aspect ratio of the source file doesn't match that of Resize. For a guide to Aspect Ratios see: viewtopic.php?f=17&t=8197&start=0 and for one on Cropping, see: viewtopic.php?f=17&t=8188&start=0.

Note 2: most conversions use inter-frame compression with infrequent Keyframes (I-frames), which have full data for all pixels, whereas the other frames are incomplete (compressed). This makes trimming and cutting inaccurate and editing in an NLE video editor more difficult. There are two alternatives. (1) change the default Keyframe separation, for example 250 frames with FFmpeg, to something like 12 (see Note 3) or (2) convert to DV AVI. The latter is possible for PAL (change the video format in column 1 from Xvid to DV Video). Unfortunately, this Codec in MediaCoder fails for NTSC. Then, use the ~lossless format 'Huffyuv', which gives files ~3x larger than DV AVI!

Note 3: the MPEG2 settings given in the Table were aimed at DVD-compliance. This also requires that the GOP length should be set (see: viewtopic.php?f=17&t=8599&start=0).

Note 4: the Xvid/AVI combination is intended for a player that supports DivX or Xvid. Some standalone players may fail to play it because it needs to see the correct FourCC code in the file header, such as “XVID” or “dx50”. The default entry ‘FMP4’ will not be accepted by many standalone players. This is not usually a problem if FFmpeg is used as the video encoder, since it usually writes ‘XVID’ to the file header for both the Format and Codec ID (as seen in MediaInfo). However, the encoder is best set as Xvidcore (more options).
Fortunately, most builds since 5000 display the Codec ID for the output file in the Properties panel of MediaCoder – see Report at: viewtopic.php?f=17&t=10383 . Thus, the success of the conversion may be checked. If the encoder fails to write ‘XVID’ to the file header as ‘Codec’, force the writing of the FourCC code by selecting Settings > Overall > Video and set “Override FourCC of output video stream” = dx50 or XVID – this setting will be retained until the process is reversed, by the use of Revert All Settings or by the loading of another Preset. See also, Note 11.

Note 5: on the Picture tab, I recommend that you click on the Effects button and set De-interlacing to Enable if the source file is an Interlaced file or Disabled, if Progressive. For more info, see Section 2 in viewtopic.php?f=17&t=9488&p=28837#p28837.

Note 6: the 'Flash Video' format, as suggested above for FLV, results in the use of the H263 Codec, an older standard. If you wish to choose the newer H.264 Codec (AVC), you may simply change the video Format/Encoder combo to H.264/x264 and leave all else the same. This allows some controls, on the x264 panel, at right (see Note 10). Suggest you experiment here! H.264 will offer a significantly better quality than H263, for the same bit rate, but would require more computation and take longer to encode. Is it worth it?

Note 7: there are two common video formats for MKV files, Xvid and H.264, both related to MPEG4. Prior to build 5010, I chose Xvid because it was 3-4x faster with my 100-sec test file than H.264 (X264 as encoder – see Note 6).
In the above Table, I chose the MPEG4 format with FFmpeg as encoder, because it is even faster, being ~5x faster than the H.264/x264 even though it may need a higher bitrate for the same quality. I would rather the larger file and not suffer a longer encoding (testing) time. Also, the H.264 requires more computing power to play the file. It's up to you. To change to H.264/x264 simply change the format and encoder, with all else the same.
The audio for MKV was changed from LC-AAC to MP3 after build 5026 because FFmpeg was no longer compatible with AAC.

Note 8: for the MP4 container, I initially chose the MPEG4 video because it was much faster than the other common format, H.264 (see also Note 6). However, I settled on the x264 encoder for H.264, which is ~2x slower than for MPEG4. See also, Note 10.

Note 9: initially, I used FAAC as the audio encoder for LC-AAC and changed it to FFmpeg when the FAAC panel at its right failed to work. Later, I discovered this was a bug that was fixed in build 4782. More recently, I changed to the Nero Encoder since it is reportedly better than FAAC. Very early builds of MediaCoder, such as 4582, are not supplied with the Nero EXE file ('neroAacEnc'). See also Note 10.

Note 10:For the settings on the x264 tab, to the right of the Video Tab (H.264 format), I chose: Profile = Baseline, Level = 3, Preset = Very Fast (see below), Tune = normal, GOP = 25 (min. interval) and ~250 (max.), B-frames = 3 (max. consecutive number) and Ref. Frames = 2 (see below).
* Notice, though, that your choice for the “Profile” should depend on the application, e.g., use Baseline for portable devices (mobiles, etc), 'Main' for output video equivalent to standard definition TV and 'High' for Blu-ray, etc.
* Moreover, the options for the “Preset” vary from 'Ultra Fast' (very quick with lowest quality) to 'Placebo' (very slow but with highest quality) in eight steps, and notice that the encoding time can vary by ~30 to 1 over this range!
* I use the 'Very Fast' preset. This is because I use these settings only for the routine testing of the MediaCoder builds (see: viewtopic.php?f=17&t=9611).
* For more information on the use of H.264, see the Guide: viewtopic.php?f=17&t=11026 .

Note 11: In builds 5002 to 5138, ‘Xvid’ was recommended as the encoder for the Xvid format. In build 5140, this encoder was replaced with Xvidcore, which became the logical choice. However, if this encoder gives problems FFmpeg could be used. For more comment on encoding with Xvid, see its Guide at: viewtopic.php?f=17&t=11023.
Also, on the Xvid tab at right, I chose Advanced Simple Profile Level 5, High Quality Mode, Medium Search for Motion Estimation and B-frames = 1 (or 2).

Note 12: the MPEG4/AVI option given in the above table is an example of a conversion suitable for an NLE video editor, such as Adobe Premiere. In which case, set a GOP of 12 (Note 3) to help scrubbing on the Timeline, etc. See also: viewtopic.php?f=17&t=9488&p=28837#p28837.

Note 13: deleted

Note 14: ‘Auto Select’ as audio source often fails. For example, for a source file with multi-audio tracks, MPlayer or MEncoder is better when selecting the track (Audio ID). Also, FFmpeg may be more reliable as audio source when converting MP4 or FLV files to MPEG4/AVI.

Note 15: initially I had used the FFmpeg encoder for MP3 audio at 112 kbps, for Xvid/AVI, but since it often resulted in 96 kbps (most builds from 5025 to 5185), I followed the advice from viewtopic.php?f=17&t=9374 and chose LAME MP3 at CBR (better for video sync) for builds from 5185. It is also a bit quicker.

Note 16: to more definitely set 'Original' for Resize, click on the button to its left on the Picture tab. This will open Settings > Video Filters > Scaling. Enter 0 for Width and Height to give Original (same as the source file). For the Frame Rate, click its button and enter 0 for “Output frame rate numerator” and for its denominator, enter 1.

Note 17: the Video Source was changed from MEncoder in build 5215 to Auto Select (resulted in FFmpeg) to avoid Error 13. However, in builds 5275 and 5280, it was noted that Subtitles failed to burn in for an MKV source file with Renderer = Default unless the video source was set as MEncoder. So: choose Auto or MEncoder, whichever works!

Note 18: prior to build 5292, the setting of ADPCM audio for WMV was accepted by the FFmpeg encoder. However, in builds 5292 and 9295, its selection gave the message “This format is unlikely to be supported by the encoder”. This was also true for WMA-7 and WMA-8 but not PCM. In any case, all these audio formats worked! As of build 5292, I shall use WMA-8.
Have you checked out the Tips & Guides for MediaCoder? Try:
Also, get older builds at:

Return to “Generic Discussions”

Who is online

Users browsing this forum: Bing [Bot] and 16 guests