Multimedia dedicated weblog.

MONOGRAM x264 Encoder 1.0.2.0

December 29th, 2008 Posted in DirectShow

Hello,

after a little struggle with mingw I’m happy to announce a new version of the x264 wrapper filter with these changes:

  • libx264 built with mingw
  • memory leaks fixed
  • CRF support

hopefully this filter should not crash randomly :)

Please do some testing and report if anything goes wrong.

Source : mm_x264_1.0.2.0_src.zip (1.5 MB)

Binary : mm_x264_1.0.2.0_bin.zip (444 KB)

Enjoy,

Igor

  1. 49 Responses to “MONOGRAM x264 Encoder 1.0.2.0”

  2. By Angel Genchev on Jan 6, 2009

    Hi!
    ThanX for working on opensource;
    Something to mention - on this post lacks info on how can one use this wrapper by CLSID for lazy people (to read the source). I`ve got another question too - does this encoder give One NAL per frame on it`s output ?

  3. By Igor Janos on Jan 7, 2009

    Well.. There is a simple header file with all CLSID_*** and IID_*** this filter supports : x264_types.h

    All you need to do to use the filter is

    CComPtr<IBaseFilter> x264enc;
    CoCreateInstance(CLSID_MonogramX264, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&x264enc);
    gb->AddFilter(x264enc, L”Encoder”);

    Yes - the filter generates one NAL unit per frame.

  4. By Angel Genchev on Jan 7, 2009

    Thank You! For the very fast responce :). Actually the clsid was the unknown to me thing(i`ve read the src now). It was necessary, because i fail to find your filter by enumerating Video compressors using pSysDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory, &pEnumCat, 0);
    I`ve registered the .ax manually, w regsvr32.
    ffdshow,wmv8,9,indeo are shown.

  5. By Tevin on Jan 9, 2009

    this doesnt hook up to a file writer, so how do you know it actually works. i dont see a mux on your site that is compatible withit. shouldnt it allow to attach to the filewriter so you can output the raw encoded h264 file?

    thanks
    Tevin

  6. By Igor Janos on Jan 9, 2009

    Currently you can use Haali Muxer to write both MKV and MP4 files. MONOGRAM MP4 muxer should appear here on monday when our developer server is reinstalled.

  7. By Angel Genchev on Jan 13, 2009

    Hi, I`ve tried to use mm_x264_1.0.2.0 wrapper, but it just refuses to connect to my web camera. I`ve tried to use colorspace convertor w no success. In MS graph edit. The property page works:) though.

  8. By Igor Janos on Jan 14, 2009

    It only accepts YV12 color space. Try using ffdshow raw video filter between your camera and x264.

  9. By ernesto ferat on Jan 16, 2009

    Hi Igor, I’ve been trying to compile the source, but a got next errors (8 more same kind) I already check the libraries paths and hearders paths, also the type of project output, any idea to solve this? (I’ve been trying to compile it in VS2005 and also VS2008, WS2008 SDK, DXSDK, Platform SDK), please put me in rigth direction.

    Error 34 error LNK2001: unresolved external symbol _FilterDllMain encoder_x264 encoder_x264

    Error 35 error LNK2019: unresolved external symbol “public: __thiscall CMediaSample::CMediaSample(wchar_t const *,class CBaseAllocator *,long *,unsigned char *,long)” (??0CMediaSample@@QAE@PB_WPAVCBaseAllocator@@PAJPAEJ@Z) referenced in function “public: __thiscall CMediaSampleEx::CMediaSampleEx(wchar_t const *,class CBaseAllocator *,long *,unsigned char *,long)” (??0CMediaSampleEx@@QAE@PB_WPAVCBaseAllocator@@PAJPAEJ@Z) mediasample_ex.obj encoder_x264

  10. By Igor Janos on Jan 17, 2009

    Hi.

    Your BaseClasses library is not prepared correctly.

    I’m using my own builds of the baseclasses library. You can find some more info here :
    http://blog.monogram.sk/janos/2008/01/10/directshow-baseclasses-and-mfc/

    The filter is currently configured for static linking with MFC and unicode strings.

  11. By David on Jan 21, 2009

    Hi Igor, I am trying to write a DirectShow H.264 decoder filter to connect to your Encoder. I manage to connect the input and output pins.

    I also manage to receive the IMediaSample pSample at the receive() method.

    However, when I look at the recv buffer:

    pSample->GetPointer(&pBuf);
    iBuf=pSample->GetActualDataLength();
    int ret = p264_nal_decode( &nal, pBuf+4, iBuf-4);

    It does not have the start code.
    If I skip 4 bytes ,I can only see nal_u_type 1 and 5.

    So my question is :
    1) Is this the NAL unit?
    2) Where is the start code 00 00 00 01?
    3) Why must I skip the first 4 bytes?
    4) where are the PPS and SPS ,nal_u_type 7,8?
    5) How/when should I use the PPS and SPS to init my decoder.
    3) what’s the difference between checking the AnnexB check box option on your encoder?

    Need some help.
    - David

  12. By Igor Janos on Jan 21, 2009

    1) This filter delivers NAL units in the form as they are described in ISO/IEC 14496-15 (AVC File Format). That means each NAL unit is superceeded by 4-byte length and then the NAL unit follows (without the Annex B start code). Most filters supporting H.264 do this the same way (Haali splitter, ffdshow, …)

    e.g.
    00 00 00 37 | 45 … (another 0×36 bytes of IDR nal unit)

    If more NAL units are delivered they look like this

    <4byte SIZE>NAL<4byte SIZE>NAL

    2) “00 00 00 01″ is not in there

    3) When you skip the first 4 bytes you get the exact start of the NAL unit

    4) PPS and SPS are encoded in the mediatype format structure AFTER the VideoInfo or MPEG_VIDEO_INFO structures. They are encoded in this form

    <2byte size>NAL<2byte size>NAL

    This might look like this :

    00 1B 67 42 C0 33 AB 40 5A 09 37 FE 00 20 00 1E 20 00 00 03 00 20 00 00 06 51 E3 06 54 00 04 68 CE 3C 80

    5) You should read the SPS/PPS when the filters connect and init the decoder when streaming starts (CTransformFilter::StartStreaming). You should also take care and update your SPS/PPS if you encounter this NAL unit among the incomming NAL units.

    6) I think it’s not implemented in the current release of my encoder.

  13. By ernesto ferat on Jan 21, 2009

    Hi Igor,

    Which version of MinGW are you using for next libraries?

    libgcc.a
    libmingwex.a

    I’m getting next errors:

    Error 10 error LNK2019: unresolved external symbol __imp____lc_codepage referenced in function _mbrlen libmingwex.a encoder_x264

    Error 11 error LNK2001: unresolved external symbol __imp____lc_codepage libmingwex.a encoder_x264

  14. By David on Jan 22, 2009

    Many Thanks Igor. =)

  15. By Igor Janos on Jan 22, 2009

    @ernesto: Sorry I can’t tell you the exact version now - I did not manage to get to my home computer. But it was the latest MSYS and MinGW. I’ve even installed the latest gcc (I think 4.2.something)

  16. By Dori Ansari on Mar 1, 2009

    I have these errors when compiling using VS 2008:

    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _wcsrchr already defined in libcmtd.lib(wcsrchr.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __vsnprintf already defined in libcmtd.lib(vsnprint.obj)
    1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: “private: __thiscall type_info::type_info(class type_info const &)” (??0type_info@@AAE@ABV0@@Z) already defined in libcmtd.lib(typinfo.obj)
    1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: “private: class type_info & __thiscall type_info::operator=(class type_info const &)” (??4type_info@@AAEAAV0@ABV0@@Z) already defined in libcmtd.lib(typinfo.obj)
    1> Creating library .\bin\mmx264d.lib and object .\bin\mmx264d.exp

    Why am I getting these errors? Is it a VC08 special?

    Thanks

  17. By Igor Janos on Mar 7, 2009

    This might happen when you use different options for MFC Static/Shared linking for the final project and the BaseClasses library.

    Read the article “DirectShow Programming \ BaseClasses and MFC”

  18. By Xigga on Mar 15, 2009

    Hello Igor,

    I have a question for you. In your GraphStudio utility you are able to show the User Interface for a filter if it has one. What call do you make in the DirectShow API to show that User Interface? I’m trying to write a simple conversion app where I select a file and it will encode it. But I want to show the User Interface so that I can change the settings for the encoder.

    I check IBaseFilter and it doesn’t seem to have any calls to show the UI.

    Thanks

  19. By Igor Janos on Mar 16, 2009

    Try opening this file : http://dev.monogram.sk/websvn/filedetails.php?repname=graphstudio&path=%2Ftrunk%2Fsrc%2Fdsutil.cpp

    and search for DisplayPropertyPage

  20. By Xigga on Mar 17, 2009

    Thanks a lot Igor!

  21. By Jeroen on Mar 24, 2009

    Hi Igor,

    First of all a big thank you for creating these filters and making them available.

    Second a question:
    I’m trying to connect the output of you filter into the Mainconcept multiplexer to mux directly to a transport stream. Although connecting the mainconcept filter does not appear to be receiving signals from the encoder. Any ideas?

  22. By Igor Janos on Mar 24, 2009

    I haven’t tried Mainconcept muxer myself, but the encoder delivers data in the AVC-File way. That means - (NALSIZE)(NAL)(NALSIZE)(NAL) …

    I assume the muxer might want Annex-B formatted data - (STARTCODE)(NAL)(STARTCODE)(NAL)…

  23. By winnydows on Mar 24, 2009

    Bug found:
    x264 1.030 and 1.020 create unreadable x264 elementary stream if dump encoding result to .264 file.

  24. By Igor Janos on Mar 25, 2009

    That’s not a bug. Raw H264 files consist of NAL units written with the Annex-B syntax, while the encoder filter delivers AVC-File NAL units.

  25. By winnydows on Mar 25, 2009

    But x264vfw codec create correct RAW H264.
    And for example Elecard AVC codec create correct RAW stream and correct encode to container.

    Possible create correct RAW H264 with your filter ?

  26. By Igor Janos on Mar 25, 2009

    There is an option in the property page prepared for this - “Annex B output” but it’s not implemented right now. Sure it’s not a big problem.

  27. By winnydows on Mar 25, 2009

    Most ds muxers don`t accept output of your filter. Only one posibility use manual muxing after encoding. But problem in this case Mx264 can`t create RAW H264. So without this option codec possible use only with MONOGRAM MP4 Muxer. It`s very big limitation. Also most expirience user who know what is GraphEdit prefer encode to RAW and then mux with favorite muxer, for example TsMuxer.

    I use this way to, because can`t correct put x264 stream with Mx264 or with x264vfw to Elecard TS Muxer filter.

  28. By Igor Janos on Mar 25, 2009

    I have implemented the encoder to make it deliver data in the same way as many free/opensource demuxers do (e.g. Haali or Gabest) so it should not matter whether you are receiving the h264 stream from a mp4 file or transcoding on the fly.

    I personally prefer this way over the annex-b because it is easier to work with.

  29. By winnydows on Mar 25, 2009

    Ofcource one step encoding better. I use it only because can`t find way create TS and MP4 directly:

    TS:
    Elecard MPEG Muxer just crash after start coding.

    MP4:
    MONOGRAM MP4 muxer work fine. But limited to x264+aac
    Elecard MP4 work fine only if b-frames 0.
    Haali MP4 work, but Haali create incorrect MP4 - playble on PC only.

    May be you know how create TS with your filter ?

    Probably used old x264 codec source or missed some important options:
    x264vfw max quality (PS3-BluRay compatible) CRF 21 create 1.8 MB file.
    Mx264 max quality (PS3-BluRay compatible) CRF 21 create 3.8 MB file.
    Out quality same.

    in x264vfw I use subme 9, b-pyramid, weighted b predition, trellis mb-encode, fixed buffer size 24000. Can`t find this iportant options in Mx264.

  30. By Igor Janos on Mar 25, 2009

    Sure I know how to create TS :) - with MONOGRAM TS Muxer. Will be available soon, just need to find some time to finish the property page. If you want to play I might send you the binary for tests.

    The options you’ve mentioned are not present via the standard property page the current version of Mx264 offers. They will be added once I find some time… I’d also like to make 2-pass encoding available.

  31. By winnydows on Mar 25, 2009

    Nice news!!!
    Yep I want play with TS.

  32. By winnydows on Mar 25, 2009

    Can I donate you some stuff via PayPal ? I use your filters in my new encoder and highly interested in developing your filters.

  33. By winnydows on Mar 25, 2009

    Want play with filters brains too, but 100% busy with encoder. Hope found time for filters 6 month later.

  34. By Jeroen on Mar 28, 2009

    Hi Igor,

    I would be interested in a test version of the TS Muxer. Would appreciate it if you can send it.

    Thanks,

    Jeroen

  35. By Jeremy on Mar 30, 2009

    Igor,

    First, thanks a ton for this filter. It’s been really good to me thus far. :)

    That said, I have a question about packaging output for RFC 3984, and in particular, profile-level-id:

    “profile-level-id:
    A base16 [6] (hexadecimal) representation of the following three bytes in the sequence parameter set NAL unit specified in [1]: 1) profile_idc, 2) a byte herein referred to as profile-iop, composed of the values of constraint_set0_flag, constraint_set1_flag, constraint_set2_flag, and reserved_zero_5bits in bit-significance order, starting from the most significant bit, and 3) level_idc. Note that reserved_zero_5bits is required to be equal to 0 in [1], but other values for it may be specified in the future by ITU-T or ISO/IEC.

    How would I get this information from your filter? (and excuse me if this is a dumb question, i’m new to H.264 so if this question is totally nuts, let me know)

    Thanks,

    jer

  36. By Igor Janos on Apr 2, 2009

    Hi guys, I’ll get back to you on saturday with both the MPEG TS muxer and some source snippet of how to parse the SPS/PPS to construct a correct SDP file.

  37. By Jeremy on Apr 2, 2009

    I think I already found a way to get at the SPS/PPS stuff:

    hr = pPinOut->ConnectionMediaType( &mt);
    if ((mt.formattype == FORMAT_MPEG2Video) && (mt.cbFormat >= sizeof(MPEG2VIDEOINFO)) && (mt.pbFormat != NULL))
    {
    MPEG2VIDEOINFO *mi = (MPEG2VIDEOINFO*)mt.pbFormat;
    const char *out = (const char*)&mi->dwSequenceHeader[0];
    short spssize = (out[0] << 8) + out[1];
    short ppssize = ((out + sizeof(spssize) + spssize)[0] << 8) + (out + sizeof(spssize) + spssize)[1];
    QByteArray sps(out + sizeof(spssize), spssize);
    QByteArray pps(out + sizeof(spssize) + spssize, ppssize);

    (the above example is using the Qt ByteArray class as a container)

    Is this right? My question is more about the profile-level-id stuff, which I’m not so clear on. Thanks!

  38. By Jeremy on Apr 2, 2009

    whoops, I see one obvious bug in that:

    short ppssize = ((out + sizeof(spssize) + spssize + sizeof(ppssize))[0] << 8) + (out + sizeof(spssize) + spssize)[1];

    …didn’t increment the pointer far enough. And yes, it’s sloppy code, my apologies…

  39. By Jeremy on Apr 2, 2009

    Crap, one more time:

    QByteArray pps(out + sizeof(spssize) + spssize + sizeof(ppssize), ppssize);

  40. By Igor Janos on Apr 6, 2009

    http://blog.monogram.sk/janos/temp/mmtsmux.ax

    here’s the mentioned TS muxer. I give you a BIG WARNING !!! THIS FILE MUST BE CONNECTED with a PUSH DOWNSTREAM FILTER (such as the Dump.) ant NOT with FILE WRITER.

    Also B Frames work only with MMX264 ;) have fun.

  41. By winnydows on Apr 6, 2009

    Thanks, but link dead.

  42. By Igor Janos on Apr 7, 2009

    Sorry :Z

    http://blog.monogram.sk/janos/download/mmtsmux.ax

  43. By winnydows on Apr 7, 2009

    Filter don`t accept MM_AC3.
    1. Out TS without sound readable on PC only.
    2. Out TS with MM_MP3, MM_AAC, MM_MP2 is unreadable - sound only.
    If direct stream copy sound out TS will be as in case 1.

    Conteier fixed after remuxing in TsMuxer, but TsMuxer brake MP2, MP3 and AAC.

    Connected only mm_x264, but don`t know why even if use compatible options for ps3 - ps3 will play black sreen.
    x264vfw don`t have this problem.

  44. By winnydows on Apr 7, 2009

    Out writter filter - generic Dump.

  45. By Jeremy on May 7, 2009

    Igor,

    Thanks again for the filter, it’s working great. is there any way to add MEDIASUBTYPE_H264 and fourcc H264 to the output pin? I notice that a lot of other H.264 filters connect this way (for example, the ffdshow video encoder) and a lot of H.264 decoders use this as an input (for example, the dicas mpegableDS decoder filter).

    Thanks

    jeremy

  46. By Igor Janos on May 11, 2009

    Sure. I’ll add it in the next release.

  47. By Marcelo Coggan on Jun 7, 2009

    I´m tring to convert ts over ip with mpeg2 video to a ts over ip with avc video. I try many codecs and many mux. the only mux that can use with the monogram codec it the monogam mux. but the output it no have a continus ts. If I analyze with tsreader I find error in pcr and also variation in the ts. I´m using udp filter of Elecard. I can´t multiplex this output in my hardware multiplexer.

    thanks

    marcelo

  48. By Igor Janos on Jun 7, 2009

    well, the monogram ts muxer is a very experimental version. I did not have much time to work on it so far. As for the compatibility of the x264 encoder with other muxers - I will surely work on this. I just can’t promise any release dates.

    igor

  49. By Brian on Sep 23, 2009

    Hi Igor,

    I use this filter int GraphEdit. When I play the diagram, the video is not affluent in the first 10 secends,and after the time the video is affluent.
    Do I need to configure something in the encoder?

    Thanks,
    Brian

  50. By Jon Evans on Nov 20, 2009

    Re the x264 encoder, are there any plans to add an interface that can be obtained via the filter’s QueryInterface() such that the various compression options can be set programatically ?

    TTFN,
    Jon

Post a Comment