Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Re: Single frame grabbing doesn't work with the LEAD Color Space Converter
Started by Red Rabbit at 11-11-2008 5:08. Topic has 4 replies.

Print Search « Previous Thread Next Thread »
  11-11-2008, 5:08
Red Rabbit is not online. Last active: 11/11/2008 9:27:56 AM Red Rabbit

Not Ranked
Joined on 11-11-2008
Posts 3
Single frame grabbing doesn't work with the LEAD Color Space Converter

Attachment: frame-corrupt.png
Reply Quote
Hi,
I'm developing a Directshow application to preview and capture videos from any video device (not using the LEAD Multimedia SDK).
I also have to grab single frames using the ISampleGrabber interface.
It worked great since I installed the LEAD MPEG4 Encoder.

During the installation, the default color space converter has been replaced with the LEAD Color Space Converter.
Now, when i grab a single frame, the image is corrupt (see attachment) but rendering the video works properly.


This is how I grab the frame:
    HRESULT hr;

    if(!m_mediaControl) {
        return;
    }

    AM_MEDIA_TYPE MediaType;
    m_sampleGrabber->GetConnectedMediaType(&MediaType);
    VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)MediaType.pbFormat;

    long vSize   = pVideoHeader->bmiHeader.biSizeImage;
    long vWidth  = pVideoHeader->bmiHeader.biWidth;
    long vHeight = pVideoHeader->bmiHeader.biHeight;

    CoTaskMemFree(MediaType.pbFormat);

    long *buffer = new long[vSize];

    int counter = 0;
    while (++counter < 10) {
        hr = m_sampleGrabber->GetCurrentBuffer(&vSize, buffer);
        if (hr == VFW_E_WRONG_STATE)
            Sleep(100);
        else
            break;
    }

    if(FAILED(hr)) {
        return;
    }

    /* create BITMAP header */
    HANDLE fh;
    BITMAPFILEHEADER bmphdr;
    DWORD nWritten;

    memset(&bmphdr, 0, sizeof(bmphdr));
    bmphdr.bfType = ('M' << 8) | 'B';
    bmphdr.bfSize = sizeof(bmphdr) + sizeof(BITMAPINFOHEADER) + vSize;
    bmphdr.bfOffBits = sizeof(bmphdr) + sizeof(BITMAPINFOHEADER);


    /* write file*/
    std::string fileName = "myfilename.avi";

    fh = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    WriteFile(fh, &bmphdr, sizeof(bmphdr), &nWritten, NULL);
    WriteFile(fh, &pVideoHeader->bmiHeader, sizeof(BITMAPINFOHEADER), &nWritten, NULL);
    WriteFile(fh, buffer, vSize, &nWritten, NULL);
    CloseHandle(fh);


   Report 
  11-11-2008, 5:10
Red Rabbit is not online. Last active: 11/11/2008 9:27:56 AM Red Rabbit

Not Ranked
Joined on 11-11-2008
Posts 3
Re: Single frame grabbing doesn't work with the LEAD Color Space Converter

Attachment: graph-video-capture.png
Reply Quote
This is how my graph looks like:


   Report 
  11-11-2008, 12:09
Qasem Lubani is not online. Last active: 12/21/2008 9:12:09 PM Qasem Lubani



Top 10 Posts
Joined on 08-13-2006
Posts 1,187
Re: Single frame grabbing doesn't work with the LEAD Color Space Converter
Reply Quote
If I understood correctly, the data sent from the Output pin of the Frame Grabber is rendered correctly in the Video Renderer window, but the image you capture using the Frame Grabber is distorted. Is this correct?

Also, does the problem happen with all types of video sources? Can you try a video stream that has a width value which is an exact multiple of 4? If it works with such videos but not with others, this could indicate you're not handling byte alignment correctly.
Qasem Al-Lubani
LEAD Technical Support
www.leadtools.com
   Report 
  11-12-2008, 2:45
Red Rabbit is not online. Last active: 11/11/2008 9:27:56 AM Red Rabbit

Not Ranked
Joined on 11-11-2008
Posts 3
Re: Single frame grabbing doesn't work with the LEAD Color Space Converter
Reply Quote
Thanks for the quick answer [:)].

 Qasem Lubani wrote:
If I understood correctly, the data sent from the Output pin of the Frame Grabber is rendered correctly in the Video Renderer window, but the image you capture using the Frame Grabber is distorted. Is this correct?

Yes, the image captured is distorted but the render Video looks fine [^o)].

 Qasem Lubani wrote:
Also, does the problem happen with all types of video sources? Can you try a video stream that has a width value which is an exact multiple of 4? If it works with such videos but not with others, this could indicate you're not handling byte alignment correctly.

I also tried this some times ago but it didn't resolve the problem: the captured image is still distorted ...


  • Why is this happening with the LEAD Color Space Converter and not with the default one ?
  • Do I have to use the LEAD Color Space Converter when I use the LEAD MPEG4 encoder (they are not connected in the graph) ?
  • Currently, I do not add the any Color Space Converter filter to the graph by myself (Directshow does this automatically). Can I tell Directshow to use the default one instead of the LEAD one ?

Thanks in advance

   Report 
  11-13-2008, 10:25
Yasir Alani is not online. Last active: 11/16/2008 11:29:23 AM Yasir Alani



Top 10 Posts
Joined on 02-05-2007
Posts 311
Re: Single frame grabbing doesn't work with the LEAD Color Space Converter
Reply Quote
I'm not sure what causes this, but if it's an alignment problem, it might not happen in all cases. For example, maybe it happens with 32-bit pixels, but not with 24-bits (or the other way around).
Try to check the media type of the input pin to the sample grabber filter in both cases (when the problem happens, and when it doesn't) and see if there are any differences.

You don't have to use our color space converter. It probably got inserted to accommodate for differences in video subtype between output and input pins. This means if other graphs don't need it, you can unregister it.

You can change the priority of filters using the DirectShow merit system. For more information, see this forum post:
http://support.leadtools.com/SupportPortal/CS/forums/21611/ShowPost.aspx

Yasir Alani
LEADTOOLS Technical Support
support@leadtools.com
   Report 
Post
LEAD Support Fo... » Developer » Color Conversio... » Re: Single frame grabbing doesn't work with the LEAD Color Space Converter

Powered by Community Server, by Telligent Systems