How to solve the intermittent stagnation of image during capture

Description

Users adopt Microsoft DirectShow SDK to develop applications for video capture cards. The user simultaneously captures video and audio, when he previews the image and recorded videos, he will get intermittent stagnation. If he cancels the capture of audio, the image will work well.

Reasons

When using DShow for audio capture, in default circumstance, Audio Capture Filter adopts 0.5-second buffer in order to ensure the continuity of sound while buffer time is not set for video. Therefore, when the asf file is produced, there is 0.5-second time lag between the captured audio and video. When playing the asf file, the video data will wait for the audio data, which leads to the intermittent stagnation of images.

Solutions

In normal situation, it is not necessary to set the buffer time as long as 0.5 seconds. Usually 50 to 80 milliseconds will be enough, if it shorter than that, it will affect the efficiency of audio capture and the performance. You can make the settings as below:

  1. enmu IAMBufferNegotiation.you can enmu from ICaptureGraphBuilder2 or you can also enmu from CapturePin of audio device.

    1. IAMBufferNegotiation* pNeg = NULL;
    2. ICaptureGraphBuilder2->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Audio, m_pAudioCaptureFilter, IID_IAMBufferNegotiation, (void **)&pNeg);
  2. Set the size of buffer zone.

    1. ALLOCATOR_PROPERTIES prop={0};
    2. prop.cbBuffer = 4096; // this is the size of audio data for each frame
    3. prop.cBuffers = 32; // set the frames of buffer zone
    4. prop.cbAlign = 16;
    5. hr = pNeg->SuggestAllocatorProperties(&prop);
    6. pNeg->Release();

After the above settings, you can start to capture audio and video. The intermittent stagnation of image will be solved.

Share this product

forefront imaging product catalog

Forefront Imaging Product Catalog

We welcome you to download our latest catalog in .PDF format. (Please note: Adobe Acrobat reader is required to view .PDF files. Don't have Adobe Acrobat (Download for free!)