Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, November 11, 2008 12:03:36 AM(UTC)
Red Rabbit

Groups: Registered
Posts: 3


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);
Red Rabbit attached the following image(s):
frame-corrupt.png
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, November 11, 2008 12:05:03 AM(UTC)
Red Rabbit

Groups: Registered
Posts: 3


This is how my graph looks like:
Red Rabbit attached the following image(s):
graph-video-capture.png
 
#3 Posted : Tuesday, November 11, 2008 7:04:09 AM(UTC)

Qasem Lubani  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

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.
 
#4 Posted : Tuesday, November 11, 2008 9:40:35 PM(UTC)
Red Rabbit

Groups: Registered
Posts: 3


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
 
#5 Posted : Thursday, November 13, 2008 5:20:29 AM(UTC)

Yasir Alani  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

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
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.120 seconds.