Tuesday, June 12, 2012

Using the VPP H.264 DirectShow filter

In this post, we take a quick look at how the VPP H.264 filter can be used using GraphEdit. The H.264 filter accepts both the RGB24 as well as the I420 media types making it compatible with the VPP YUV source filter. The filter can be configured via the property page. Currently, the property page contains the options shown in Figure 1. More options will be added in the future.

Figure 1


At the bottom of the property page, one can tick a checkbox in order to use the standard Microsoft H.264 decoder that comes stock with Windows 7. If the box is unchecked, the VPP decoder will be used, which has a custom media type. Figure 2 shows a graph in which the stock MS H.264 decoder is used to decode the video.



Figure 2
Currently, there are two Modes of Operation that can be selected, mode 0 and mode 1. In mode 0, the Quality of the video can be configured. Valid values lie in the range [0 - 51] with 0 having the best quality and 51 the worst. Figure 2 shows a graph in which the first encoder has Quality 0 and the second encoder Quality 35.


Figure 2

Alternatively, the frame bit limit can be set by setting Mode of Operation equal to 1 which effectively limits the bitrate of the media stream. The frame bit limit is, as the name suggests, measured in bits per frame. That means that to achieve a rate of 128 kb/s with a source video of 10 frames a second, one would need to set the frame bit limit to 12,8 * 1024 = 13107 bits per frame. In a live media pipeline, the VPP Framerate estimator filter may be useful to measure the approximate framerate of the video source.

The other option of interest is the I-frame Period which creates periodic IDR-frames i.e. every n-th frame, will be encoded as an IDR frame.

All parameters are programmatically settable by using the COM ISettingsInterface which all all/most of the VPP DirectShow filters inherit, but that is a post for another day...

P.S. The Notify on I-frame and Prepend parameter sets are no longer used and will be removed in the next release of the software.

11 comments:

  1. Is there an installer with 64-bit filters ?

    ReplyDelete
    Replies
    1. Unfortunately not at the moment, Gifford. I need to take a closer look to see how quick/easy this is to do...

      Delete
    2. gifford, there is an experimental version of the 64-bit filters available at http://sourceforge.net/projects/videoprocessing/files/x64/. Please let us know if you have any issues with it. We only ran some basic tests to see of everything is ok.

      Delete
  2. How do you use the encoder to write an AVI file? I've added this in GraphEdit, but when adding a 'File Writer' I get an error that the pins are incompatible (VPP Encoder Output-> File writer input).

    ReplyDelete
    Replies
    1. Ruud, I haven't tried putting H264 in an avi file myself. You probably need an AVI mux in the pipeline before the AVI file, but I'm not sure if the standard one accepts the MEDIASUBTYPE_H264 format.

      Alternatively if you want to create an Annex B Bitstream, you can connect the encoder to Dump filter. There was one in one of the MS DS SDK samples, and there's another one in Monogram's GraphStudio. Or, you can use Geraint Davies's MP4 muxer available on his website to create mp4 files.

      Also, be sure to select the "Use MS H264 Decoder" checkbox on the property page of our encoder if you want to connect to *standard* filters. This changes the output media type of the encoder to MEDIASUBTYPE_H264.

      Delete
    2. Ok thanks for that; it seems I can output directly to an AVI Writer. The resulting AVI looks fine, but it has no compression it seems.
      It may be the apparent default of quality=1 perhaps? Is there an interface I can use to reduce the quality? It seems when I use GraphEdit to set a lower quality and run that for a moment, these settings are not used when creating a filter path programmatically (which is what I do from C++).

      Delete
    3. Hi Ruud, there is the ISettingsInterface COM interface that can be used to set the quality of the encoder. ISettingsInterface can be found in Source\RtvcLib\DirectShow\SettingsInterface.h

      Using that interface, set the "quality" parameter.

      Another parameter you might be interested in is the "mode of operation". If set to "0", the quality parameters controls the quantization parameter (QP). If set to "1", the "framebitlimit" parameter limits the number of bits used per encoded frame i.e. a CBR approach. Also, note that in mode "1" the encoding will be much slower.

      Note that the ISettingsInterface uses "string" representations for parameter values.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Where can I find a list of the literal string parameters to use? I'm particularly interested in setting the Output Media Type.

    ReplyDelete
    Replies
    1. Don't worry. I've found the answer. For anyone else who's interested, the parameters are listed here: http://sourceforge.net/p/videoprocessing/code/HEAD/tree/tags/1.1.0/Source/Filters/DirectShow/FilterParameters.h#l35.

      Delete