1. Documentation Wiki
 

nanocosmos H.264 Video Encoder Filter

DirectShow Filter / Module

nanocosmos H.264 Video Encoder
Module Name: nh264enc.ax

DirectShow Connectivity

The input is accepting connections to video source, capture and decoder filters matching the following media types:

Major types:

  • MEDIATYPE_Video

Subtypes:

  • MEDIASUBTYPE_YV12,
  • MEDIASUBTYPE_I420,
  • MEDIASUBTYPE_YUY2,
  • MEDIASUBTYPE_UYVY,
  • MEDIASUBTYPE_HDYC,
  • MEDIASUBTYPE_RGB24,
  • MEDIASUBTYPE_RGB32,
  • MEDIASUBTYPE_ARGB32,
  • MEDIASUBTYPE_RGB565,

Formats:

  • FORMAT_VideoInfo
  • FORMAT_VideoInfo2

The output supports these media types:

Major types:

  • MEDIATYPE_Video

Subtypes:

  • FourCCs: H264, h264

Formats:

  • FORMATMPEG2VIDEO,
  • FORMAT_NONE

Configuration

The encoding configuration may be set by using either the property page or the COM Interface INanoCodecOpts as declared in header file INanoCodecOpts.h .

<code c++> Filter GUID {A88889A8-3C2A-4a32-8EAA-755D491D02A0} DEFINEGUID(CLSIDNANOH264ENCODER, 0xa88889a8, 0x3c2a, 0x4a32, 0x8e, 0xaa, 0x75, 0x5d, 0x49, 0x1d, 0x2, 0xa0);

Property Page GUID {7A8F0A5A-AEDC-4fa5-AB94-2E3FB1268DB3} DEFINEGUID(CLSIDNANOH264ENCODER_PROPPAGE, 0x7a8f0a5a, 0xaedc, 0x4fa5, 0xab, 0x94, 0x2e, 0x3f, 0xb1, 0x26, 0x8d, 0xb3);

Configuration Interface INanoCodecOpts {698E0F57-B828-4c40-8867-095FF49F77D6} DEFINEGUID(IIDINanoCodecOpts, 0x698e0f57, 0xb828, 0x4c40, 0x88, 0x67, 0x9, 0x5f, 0xf4, 0x9f, 0x77, 0xd6);

Configuration Interface ICodecProp {0F817204-82C8-4c12-884A-F45FB2F33A6E} DEFINEGUID(IIDICodecProp, 0xf817204, 0x82c8, 0x4c12, 0x88, 0x4a, 0xf4, 0x5f, 0xb2, 0xf3, 0x3a, 0x6e);

ICodecProp: IIDnanoPegLicenseString type: BSTR / Unicode string Set license string to unlock filter {1788F0B0-5985-4a19-B7FE-8AAC1BFC14B3} DEFINEGUID(IIDnanoPeg_LicenseString, 0x1788f0b0, 0x5985, 0x4a19, 0xb7, 0xfe, 0x8a, 0xac, 0x1b, 0xfc, 0x14, 0xb3); </code>

Setting the license to unlock filter

The filter can be unlocked either through a license key entry in the windows registry or by setting the license key through COM interface ICodecProp::SetProperty with the property IIDnanoPegLicenseString as first parameter. The second license parameter has to be a wide/unicode string!

Configuration through DirectShow filter property page

The filter's property page offers a subset of encoding parameters, containing the most important options.

Configuration through INanoCodecOpts interface

  1. Version check by calling GetCodecOptsVersion (optional)
  2. Instantiating a parameter structure of type MPDX4H264EncoderParams 3. Setting desired values for profile and level *(profileidc, levelidc) 4. Initializing the parameter struct by calling InitCodecOptions will set all parameters to default values for the selected profile and level 5. Setting custom values for resolution and bitrate 6. Applying settings by calling SetCodecOptions Common Encoder Settings | Parameter | Default values | Description | | ——— | ————– | ———– | | profileidc, levelidc | Baseline, 1.2 | H.264 Profile and Level | | basevideo.bitratekb | Profile and Level dependend | Video Bitrate in kBits/second | | basevideo.resolution.width | 0 - use input width | Picture Coding Width | | basevideo.resolution.height | 0 - use input height | Picture Coding Height | | entropycodingmode | Baseline+Extended: 0-CAVLC
    other profiles: 1-CABAC | [0,1] Entropy Coding Mode | | coding
    type | 0 - Frame/progressive | [0,1] Frame/Field coding type | | numrefframes | 2 | [1..16] Number of reference frames | | keyframecontrols.method | 1 - variable/maximum | [0-auto,1-variable/maximum,2-constant] Frame distance mode | | keyframecontrols.distancei | 20 | Intra Frame Distance / GOP length | | keyframecontrols.distancep | Baseline 1, other profiles 2 | P Frame Distance | Code sample: <code c++> HRESULT SetVideoEncoderOptions(CComPtr<IBaseFilter> &pVideoEncoder, int videoOutputWidth, int videoOutputHeight, …) { HRESULT hr; MPDX4_H264EncoderParams optionsH264; set lowest desired level here, lower level means lower latency level will be automatically increased by encoder if bitrate, resolution and framerate settings make a higher level necessary optionsH264.profileidc = MPDX4H264BASEPROFILE; optionsH264.levelidc = MPDX4H264LEVEL_30; create nano encoder options object from IBaseFilter CComQIPtr <INanoCodecOpts> encoderOpt = pVideoEncoder; if(encoderOpt) { MPDX4BaseVideoParams basevideo; perform profile/level based initialization of parameter structure hr = mEncoderOpt→InitCodecOptions((MPDX4BaseCodecOpts*) &optionsH264, INANOCODECOPTS_VERSION); choose constant bitrate for network streaming optionsH264.ratecontrols.method = MPDX4H264RATEM_CBR; set desired bitrate in kByte optionsH264.basevideo.bitratekb = 800; only example value if(videoOutputWidth>0 && videoOutputHeight>0) { perform resize in encoder basevideo.resolution.width = videoOutputWidth; basevideo.resolution.height = videoOutputHeight; } set frame distance mode MPDX4H264METHODAUTO = 0, automatic IDR/I-FRAMES intervals MPDX4H264METHODUSER = 1, user defined IDR/I-FRAMES intervals, variable/max distance MPDX4H264METHODUSERSTATIC = 2, user defined IDR/I-FRAMES intervals, static/constant distance optionsH264.keyframecontrols.method = MPDX4H264METHOD_USER; set GOP structure / distance between two i-frames (gop length) optionsH264.keyframecontrols.distance_i = 50; only example value distance between two p-frames, meaning: 1: no b-frames, 2: 1 b-frames, 3: 2 b-frames in Baseline profile this settings will be overridden (1) by encoder optionsH264.distance_p = 1; (no B-frames allowed in Baseline profile) hr = mEncoderOpt→SetCodecOptions((MPDX4BaseCodecOpts*) &optionsH264, INANOCODECOPTS_VERSION); } } </code> Encoding synchronized streams with multiple instances The nanocosmos H.264 Encoder supports writing constant I-frame distance/GOP length. For multiple synchronized streams the parameter keyframecontrols.method should be set to MPDX4H264METHODUSER_STATIC. Framerate, timestamps and GOP settings are recommended to be the same for all encoder instances. <code c++> / / MPDX4H264KeyFrameMethod / key frame insertion mode / enum MPDX4H264KeyFrameMethod { MPDX4H264METHODAUTO = 0, automatic IDR/I-FRAMES intervals MPDX4H264METHODUSER = 1, user defined IDR/I-FRAMES intervals, variable/max distance MPDX4H264METHODUSERSTATIC = 2 user defined IDR/I-FRAMES intervals, static/constant distance }; </code> ## Debug-Log Configuration Registry Settings Key: HKEYCURRENT_USER\Software\DebugNano\nh264enc.ax ### File name Sets the output file name. The folder must already exist.
    Value name: LogToFile

* Value type: REG_SZ / String

  • Valid values: a valid output file name to enable file logging or an empty string

Logging level

A higher value increases the amount of logging messages sent, and messages get more detailed.

  • Value name: TRACE
  • Value type: REG_DWORD
  • Valid values:
    • 0 - minimal logging
    • 9 - maximal logging
Further questions? Would you like a feature not available yet?
We can make it work for you based on our consulting and development / implementation services. Contact us.