Menu

YV12 to a Sample Grabber filter

kjj902
2010-02-04
2012-10-29
  • kjj902

    kjj902 - 2010-02-04

    Hi,

    I have searched this forum, but not able to find answers to my following
    question.

    I need to, but can't, link a filter to a sample grabber filter. After hours of
    searching online, I think it might be due to the reason that the media subtype
    of the output pin of the filter is YV12, which is not supported by Windows
    default Sample Grabber filter.

    I have tried inserting a Color Space Converter filter or YUVXfm (http://www.g
    dcl.co.uk/downloads.htm),
    (www.gdcl.co.uk) but none
    of them work.

    Any ideas how to work around this. Thank you very much.

     
  • kjj902

    kjj902 - 2010-02-04

    What I particularly confused is why it can't link to the MS Color Space
    Converter. According to the following MSDN page, http://msdn.microsoft.com
    /en-us/library/ms940088.aspx,
    Color Space Converter accepts YV12, and can
    outputs RGB565. Should I do some configuration of the Color Space Converter,
    and how? Many thanks.

     
  • snarfle

    snarfle - 2010-02-05

    I doubt that the problem is that the media subtype of the output pin is YV12.
    Looking at the docs for SG (http://msdn.microsoft.com/en-
    us/library/dd377544%28VS.85%29.aspx
    ), we see:

    • It does not support video types with top-down orientation (negative biHeight).
    • It does not support the VIDEOINFOHEADER2 format structure (format type equal to FORMAT_VideoInfo2).
    • It rejects any video type where the surface stride does not match the video width.

    Those are the things I would check first.

    As for the CSC, are you trying to place it before the SG? Once you have
    determined what the actual problem is, you might be able to convince the CSC
    to do some conversion. Check out http://msdn.microsoft.com/en-
    us/library/dd376993%28VS.85%29.aspx
    .

    As an alternative, you can write a DMO that connects to whatever you want.
    Read the docs at MSDN about DMOs and check out the DMO samples.

     
  • kjj902

    kjj902 - 2010-02-05

    Hi, snarfle,

    Thanks a lot for your info. You are right. The video I am trying to grab is
    after a DivX H.264 Decoder. When I am previewing the video, the “XForm Out”
    pin format is YV12 1280x-720. This means that the video is top-down (has
    negative biHeight), right? This probably prevents me linking it to a SG
    filter.

    However, I have several strange observations.

    When I disconnect DivX H.264 Decoder filter and VMR filter, there are several
    Preferred Media Types listed for “XForm Out” pin, including YV12, YUY2, RGB24,
    RGB32, etc. But after I connect DivX to VRM, the format becomes YV12 1280x720.
    Notice, now it is 1280x720, not negative. Then after I hit the “Play the
    graph” button, the format becomes negative, i.e., 1280x-720.

    My questions include:

    1. Why YV12 is selected when I connect DivX to VRM, not RGB24 or RGB32 for example?

    2. I then try forcing the media type using the following code. I am not a very experienced DirectShow programmer, but I have made the following code working for some video capture source filters.

    IAMStreamConfig stream_config = divx_h264_xform_out as IAMStreamConfig;
    int count, size;
    IntPtr ptr =
    Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VideoStreamConfigCaps)));
    stream_config.GetNumberOfCapabilities(out count, out size);
    for (int i = 0; i < count; i++)
    {
    media = new AMMediaType(); stream_config.GetStreamCaps(i, out media, ptr);
    VideoInfoHeader videoInfoHeader =
    (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr,
    typeof(VideoInfoHeader));
    DsUtils.FreeAMMediaType(media);
    }
    Marshal.FreeCoTaskMem(ptr);

    But it seems that I can’t cast divx_h264_xform_out, which is an IPin, to
    IAMStreamConfig. The value of stream_config is always null. What goes wrong?

    1. Why only after previewing the video, does the format change to negative?

    2. My ultimate goal is to insert a SG filter between Divx H.264 Decoder and VMR, such that I can grab some frames. How can I achieve this? I prefer avoiding writing my own filters, since I am not an experienced directshow programmer. At this moment, I don’t care too much about efficiency, so it would be Okay to add some other filters, such as CSC. What is easiest solution?

    Thank you very much again, and look forward to hearing from you.

     
  • kjj902

    kjj902 - 2010-02-05

    Sorry, forget to mention my observation about connecting CSC. I can't link CSC
    to DivX H.264 Decoder. It complains type compatibility. I noticed that I make
    a mistake in Message 2. It points to a MSDN page of CSC filter for Window CE
    5.0.

    According to the page http://msdn.microsoft.com/en-
    us/library/dd387892(VS.85).aspx,
    CSC filter accepts only RGB format. Is
    there a way to force DivX H.264 to output RGB format? Many thanks.

     
  • snarfle

    snarfle - 2010-02-06

    1) You need to understand how pins connect. In short, one pin starts sending
    AMMediaTypes to the other. The other pin looks at the media type, and if it
    supports it, accepts the connection. As a result, the first media type that
    both pins support will be the one used. You MAY be able to override this
    using IPin::Connect (http://msdn.microsoft.com/en-
    us/library/dd390420%28VS.85%29.aspx
    ), assuming both pins support the specific
    media type you provide.

    2) As with most interfaces in DS, a filter can choose whether or not it wants
    to support it. I am not familiar with the DivX filters, but it certainly seems
    possible that it simply doesn't support this interface. That would be a
    question for the DivX folks.

    3) Again, if you have questions about the how the DivX filter works, ask the
    Divx people.

    4) Have you looked at the VMRSnapper sample? Seems to me it lets you grab
    frames.

    5) s there a way to force DivX H.264 to output RGB format? Not to sound like
    a broken record here, but if you have a question about have a DivX product
    works...

     
  • kjj902

    kjj902 - 2010-02-06

    Hi, snarfle,

    Thank you very much for your information. I am sorry for those DivX questions.
    I just start working on DirectShow, and am new to this forum.

    I remember that I have read all the readme's of DirectShowLib examples, not
    sure why VMRSnapper passes me. This example does look like exactly what I
    want. Will take a careful look.

    Again, thank you very much indeed and sorry for any inconvenient.

     

Log in to post a comment.