# Ffdshow/Reference

ffdshow is a DirectShow filter, designed to both encode and decode video using both the DirectShow, and video for windows (VfW) interfaces. It was originally created and maintained by someone called Milan, but he disappeared in early 2006. After that time, ffdshow tryouts was born to carry the ffdshow torch and they have been working since to improve ffdshow.
ffdshow consists of three main components.
* Video decoder: This could be considered the 'meat' of ffdshow. It is the DirectShow component that can decode many different video formats to raw video. In addition, it can optionally transform the video in a number of ways (sharpening, resizing, etc.).
* Audio decoder: The counterpart to the previous component, this is a DirectShow decoder for audio, that also includes a sizeable number of transform filters (channel mixer, equaliser, etc.).
* VfW Codec: The ffdshow VfW component is both a video encoder and decoder which duplicates the functionality of the DirectShow decoder, except it works with the VfW interface. The VfW interface is an older system that is often used for video processing programs (VirtualDub, Adobe Premiere, etc.). As well as providing VfW decoding, it is also a VfW encoder for a large variety of formats.

## Video Decoder
### Codecs Page

The codecs page lets you control what formats ffdshow will decode. The decoder column will let you choose the decoder for each format listed, you can choose 'disabled' to prevent ffdshow from decoding it. Make sure to read the remarks, not all decoders are fully implemented.
Tips & Tricks
* If you right click anywhere on the list, you can enable all stable decoders in one click. This does not enable raw video processing.
* The last item, for raw video is useful if you want ffdshow to process the decoded video from another stream. One side effect of enabling this is that ffdshow will insert itself into more or less every stream. You can enable decoding only for one colorspace, or for all.
* Some items show additional checkboxes just underneath the list when you select them. These boxes will change the behavior of the decoder in certain ways:
   * h264: If you check 'skip deblocking when safe', the decoder will not always apply the inloop deblocking filter to the displayed frame, which will reduce CPU usage. If you check 'skip deblocking always', the decoder will never apply the inloop deblocker. Be aware the inloop deblocker is a normal part of h264 decoding, and disabling it (especially on low quality streams) will produce a suboptimal picture.
   * MPEG1/2: Both MPEG1 and MPEG2 include a setting 'use speedup tricks'. This setting will reduce the CPU usage for decoding, but produce a lower quality image. With MPEG2 decoding, you can also enable DVD decoding, which will allow ffdshow to decode DVD video. Consider it experimental, but stable.
   * Raw Video: Running Vista? If you want to use ffdshow as a passthrough for raw video in WMP11 you must check the 'Enable in Vista WMP11' checkbox.

### Info & Debug

This page lets you set a small number of miscellaneous options, and also gives statistics about the current stream being handled, if it exists.
Settings:
* You can change the filter merit for the decoder on this page. The filter merit is more or less the priority of ffdshow, compared to other filters. If multiple filters can decode a file, the one with highest merit will be used.
* If you check the 'Don't use ffdshow in' box, you can specify a list of executables that ffdshow will refuse to be run from. This affects only video decoder. Audio decoder has to be configured separately. Vfw codecs doesn't have this feature.
Tips & Tricks
* The statistics will only show up if you are viewing the config panel for an instance of ffdshow that is currently handling video. Because multiple copies of ffdshow can be running at the same time, you can't just open ffdshow from anywhere and get information on the particular stream you want. If you are using ffdshow in a media player, you will have to open the config panel from the media player in question for it to show you the stream statistics. In media players, this is often available in rclick on video -> filters. When a stream is playing and you have enabled the tray icon (on by default), you can double click that icon (File:Ffdshow icon.gif) as well.
* The 'average bitrate' info is calculated from when you open the ffdshow window. Don't be surprised if you see unexpectedly high bitrates if you open the window in the middle of an action scene.

### Resize & aspect

This section is based on ffdshow-tryouts rev 1103 or later. Earlier versions (or original ffdshow) will have some subtle and not so subtle differences. The dialog is made up of three sections that work in tandem:
* Resize, which defines the base output resolution,
* Aspect Ratio, which constrains the output resolution to satisfy aspect ratio limitations, and
* Conditional Activation, which enables or disables resizing based on the original resolution.
Resize
    File:Radiobox.gifSpecify horizontal and vertical size
      * "No aspect ratio correction" selected: Stretched or shrinked to the specified size.
      * "Keep original aspect ratio" selected: Stretched or shrinked until either width or height touch the specified size using the original aspect ratio. Black borders are added, if necessary.
      * Manually configured: Stretched or shrinked until either width or height touch the specified size using the specified aspect ratio. Black borders are added, if necessary.
    File:Radiobox.gifSpecify horizontal size
       Height is calculated automatically to keep original aspect ratio.
      * "No aspect ratio correction" and "Keep original aspect ratio" give the same result.
      * Manually configured: You can specify aspect ratio manually.
    File:Radiobox.gifSpecify aspect ratio
       Height is calculated based on width. (Let's call it a box here.)
      * No aspect ratio correction : Stretched to fill the box.
      * Keep original aspect ratio : Stretched or shrinked until either width or height touch the box using the original aspect ratio. Black borders are added, if necessary.
      * Manual : Stretched or shrinked until either width or height touch the box using the specified aspect ratio. Black borders are added, if necessary.
    File:Radiobox.gifExpand to next multiply of
      * Both width and height are expanded to the next multiple of the specified value. For example, if you specify 100, 320x160 becomes 400x200. You may want to use this mode when ffdshow connects to a filter which does not work with width or height of non-multiple of 16.
      * "Keep original aspect ratio" and "Manual" work in this mode too.
    File:Radiobox.gifMultiply by
      * Both horizontal and vertical sizes are stretched using the specified magnification ratio.
    Process pixel aspect ratio internally
      * If checked (by default), resize to the size taking into account pixel aspect ratio (SAR), and fix output SAR 1:1.
      * If unchecked, output SAR equals input SAR and the video renderer (or any downstream filter) handles it.
Aspect
    File:Radiobox.gifNo aspect ratio correction
      * The output aspect ratio (DAR) will not be affected by the original DAR.
    File:Radiobox.gifKeep original aspect ratio
      * The output DAR will be the same as the input DAR.
    File:Radiobox.gifManual
      * Manually specify the output DAR.
   * Overlay aspect ratio: If your computer's overlay does not have a 1:1 SAR (ie, your display has non square pixels), you can use this slider to correct it.
Conditional Activation
    File:Radiobox.gifResize if...
      * Only resize if the input resolution matches the conditions specified. By clicking the < or > signs, and the and or or sign, you can specify conditions that the resize filter will fire on. If the conditions are not met, the resize filter will not activate.
    File:Radiobox.gifResize if number of pixels is...
      * You can specify a condition for the resize filter to fire on based on the number of pixels in each input frame. You can click on the greater than or less than sign to swap the condition type. You can determine the number of pixels in a frame by multiplying width by height.
Example Following situation: You have a projector with 1280x720 resolution and you want to play a DVD whose pixel aspect ratio (aka SAR) changes during playback. To get the optimal resizing system:
* Specify horizontal and vertical size"->1280x720.
* Select "Keep original aspect ratio".
* Make sure "Process pixel aspect ratio internally" is checked.
You will find the video will always be resized to the largest possible resolution possible, while keping the aspect ratio correct.

### Avisynth

There is a page written on this filter available at the official ffdshow-tryouts site.

### Output

The output page gives you control over the output formats used by ffdshow. The top half gives you control over the allowed output colourspaces, while the lower half is used for miscellaneous output settings.
Colourspaces
This page allows you to set the default output colourspace and format used by ffdshow. There are two general colourspaces that can be used, and a number of formats within each colourspace.
* YUV Colourspace
    The default output colourspace. Read more about YUV on this and this wikipedia article. As the YUV colourspace (and YV12 in particular) is the colourspace of choice for video compression, setting ffdshow to output YV12 saves it from having to do any colourspace conversion on the decoded image, speeding up decoding.
    There are a number of different YUV output formats supported by ffdshow.
   * I420/IYUV: Similar to YV12 described below, but less hardware support. Not recommended, even if it's supported by your video card, as YV12 is faster. Uses 12 bits per pixel (bpp).
   * YV12: Almost always the fastest output mode (video codecs usually use YV12 for storage). The recommended output for most system setups, although some older/onboard video cards do not support it - if this is the case for you, try YUY2. Windows media player sometimes has trouble with YV12 output. Uses 12bpp.
       NVidia 8800 Owners take note! YV12 output appears to be broken in many instances and with most driver versions currently available (2007). If you run into any sort of image corruption issues, try falling back to YUY2.
   * YUY2: Used by MJPEG and some MPEG2 video streams, and has slightly more colour definition than YV12. Slightly slower to output than YV12, but generally not by much. If your input video is YUY2, or your video card doesn't support YV12, this is the recommended output. Uses 16bpp.
   * YVYU & UYVY: Rare and unused, avoid. Uses 12bpp.
   * NV12: Another rare output format, not even supported by many cards. Uses 12bpp.
* RGB Colourspace
These modes uses the more traditional and familiar colour format of RGB. Read about RGB on wikipedia (again). RGB output is slower, but possibly more accurate than YUV output - the difference will be minimal in any case.
    RGB formats supported.
   * RGB32 & RGB24: These modes will give you the same picture output, the only difference is that RGB32 is packed to 32bits which is usually faster to manipulate. These modes use 32 or 24bpp respectively.
   * RGB16 & RGB15: Same as bove, but only 16/15bit. RGB15 is a bad idea unless you know it's a good idea. These use 16 or 15bpp respectively.
   * High Quality YV12 to RGB Conversion: Because (almost) all video files are compressed in a YUV format (usually YV12), ffdshow must convert from the YUV colour system to the RGB colour system when outputting RGB modes. This checkbox will instruct it to use a slower, but higher quality conversion method. If you are planning on taking screenshots, or really really need every last drop of faithful quality reproduction, enable this.
Select closest matching colorspace
   * Checked: The closest colorspace to that of the input stream will be selected automatically.
   * Unchecked: The colorspaces will be tried in the order that is listed in the dialog.
File:Checkbox semi.gif Set pixel aspect ratio in output media type / Use overlay mixer
   * Unchecked: Use classic connection method.
   * Checked: Use an advanced connection method that includes pixel aspect ratio (SAR) and interlacing information when connecting with the next filter (usually a video renderer).
   * Indeterminate/grayed: Try advanced connection method first and fall back to classic connection method if it fails. This is the default and should not be touched unless you have some special purpose.
File:Checkbox empty.gif Set interlace flag in output media type / HW deinterlacing
   * Send interlacing related information obtained from the input stream or ffdshow's internal decoders to the next filter.
   * Some filters (like video renderers) will use this information to deinterlace the video if neccessary.
   * This is just for informing the downstream filters - the actual result will depend purely on the implementation of these filters.
   * Unchecked by default. DVDs are flagged interlaced, but in most cases they are originaly film (progressive) and just telecined. For such video, it is recomended to keep it unchecked.
Tips & Tricks
* You can select more than one output format, ffdshow will try to use the closest output format to the input. Generally this means YV12, but not always.
* The other settings on the page shouldn't be touched unless you know what they are. The author recommends using the settings in the image to the right (although with YV12 enabled). Flip video is occasionally useful for broken or old streams.

## Audio Decoder

The audio decoder shares many similarities with the video decoder. Because of this, some pages will not be covered here, and you can instead simply refer to the video decoder's information. These pages include:
* Codecs: The only change are the formats supported, and there are three items with checkboxes:
   * AC3: The checkbox enables Dynamic Range Compression, which is part of the normal AC3 decoder. It is not recommended that you disable this, unless you have good reason to do so.
   * DTS: The checkbox for Dynamic Range Compression is the same as above. The second checkbox, 'Check for DTS in WAV', is used to tell ffdshow to check .wav files and see if they actually have DTS audio inside them. You can get these files off Super Audio CDs and DVD Audio discs.
   * Vorbis: Enabling VorbisGain will tell ffdshow to read the suggested gain setting that can be written into vorbis bitstreams, and apply it if present. Use depends on user preference, you can consider it a form of 'volume levelling'.
* Info & Debug: Identical beyond the different information given for the currently playing stream.

### Mixer

This page controls the Mixer filter, which can change the number of channels in the audio stream being processed. Its main use is to mix all audio streams so they have the same number of streams as your audio setup has. Increasing the number of channels is known as upmixing, and reducing is known as downmixing.
There are two ways to define the number of output channels: by use of the configuration presets, or by manually specifying the matrix. Note that ffdshow can output a maximum of 6 channels (i.e. 5.1). Configuration Presets The most common and recommended presets are shown at full size, other presets are shown in a smaller font. Note the channel definitions used (2/0, 3/2, etc.) refer to front speakers / back speakers.
   * 1/0 - mono
   * 2/0 - stereo: If you have two speakers connected to your computer, this is the preset you want.
   * 3/0 - 3 front
   * 2/1 - surround
   * 3/1 - surround
   * 2/2 - quadro
   * 3/2 - 5 channels: If you have 5 speakers attached to your computer, you almost certainly want this setup.
   * Dolby Surround/ProLogic:You might want to use this preset or the next if you are sending the audio output to a amplifier that only supports stereo input, but handles ProLogic/ ProLogic II
   * Dolby ProLogic II
   * Same as input:No mixing.
   * Headphone virtual spatialization: Can make >2 channel audio sound better through headphones, can make it worse; usually makes 2 channel audio sound worse.
   * Head related transfer function

### Output

This page is identical in design to the video decoder's page, but the actual content is different.
Settings
* Supported Output Sample Formats: The checkboxes here set the allowed output formats that the video decoder will use.
   * 16/24/32/32float: These are normal PCM output, with different levels of bitdepth. The 'normal' rate for almost all audio streams encountered is 16bit (used in CDs, DVDs, most HDVDs/BDs), but using larger bitdepths can be advantageous in some settings. If you are using any audio filters it can help to increase bitdepth to produce more accurate 'rounding'. There are two important caveats when increasing the bitdepth here:
      * Converting between different audio bitdepths is a lossy conversion, and it will not increase the audio quality above the original. There is no point in outputting a 16bit CD as 32bit, you won't find there to be any better sound.
      * Many sound cards do not correctly support bitdepths other than 16bit. In particular, many creative cards will resample 24/32/32float output back to 16bit before sending it out to the speakers, which means you will end up just running your audio through multiple destructive processes for no gain.
   * AC3: This mode will encode the audio to AC3 and then output it along SPDIF (if the audio is already AC3, it will not be re-encoded). If you want to play your audio through speakers attached to a SPDIF compatible amp, consider using this option. Use the highest bitrate your link can support for maximum quality.
   * LPCM: As the helptext says: "LPCM output is intended for connecting to DVD audio decoder filters like one from Cyberlink." 'nuff said.
* Connect to is useful when you want to try and force the audio output to be sent to a particular location. Generally, directsound is the default, and preferred output, but you may want to use another in some cases.