Why does AVIStreamRead read nothing?

587 views Asked by At

I'm writing a simple AVI loader to get each frame from an AVI file and save it to an OpenGL texture. I'm using VFW, and AVIStreamRead isn't returning anything. This is my code that grabs each frame:

void CVideoControl::SetFrame(long frame)
{
    HRESULT result;
    long bytes, samples;

    //Update variables
    m_currentFrame = frame;
    m_lastFrameChangeMS = gGlobalData->GetLastFrame();

    //Get the frame
    result = AVIStreamRead(m_aviStream, m_currentFrame, 1, m_inputTexture, m_videoAdjustedWidth * m_videoAdjustedHeight * 3, &bytes, &samples);
    if(FAILED(result))
        return;

    //Decompress the stream
    if(ICDecompress(m_decompressor, 0, m_inFormat, m_inputTexture, m_outFormat, m_outputTexture) != ICERR_OK)
        return;

    //Draw it to the OpenGL texture
    glBindTexture(GL_TEXTURE_2D, m_videoOutputTexture);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_videoAdjustedWidth, m_videoAdjustedHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_outputTexture);
}

The variable bytes has a value of 2740, and samples is 1. However, m_inputTexture is empty. It's not a bad pointer or anything, its just... empty. AVIStreamRead doesn't return any errors. In the documentation, the only mention of data not being read is:

If lpBuffer is NULL, this function does not read any data;

But lpBuffer isn't NULL. I would post more code, but it's scrambled all over the place. There are no other apparent errors anywhere else, and the debugger shows all the correct information.

1

There are 1 answers

1
Warpin On

Different AVI files are encoded using different codecs. Perhaps the file you're trying to decode doesn't have a codec that can be handled by vfw.

Also I would start with some working sample code and slowly modify it to fit my needs. There are just too many details when video is involved, which make pure documentation mostly useless.