locked
Microsoft Video 1 AVI File Playback Issue when FPS > 1 RRS feed

  • Question

  • Hi,

    I tried to create a compressed AVI file using VFW in C++. However the compressed AVI file seems cannot be played correctly in Media Player. Media Player will close before the last frame duration ends.

    For example, a AVI file is generated with 0.125 FPS, one frame should lasts for 8 seconds. If the file has 5 frames, the length should be 40 seconds. But the Media Player will stop at 00:31~00:32, just after the last frame is drawn. 

    A uncompressed file with same fps could be played correctly, including the last frame. The Media Player will ends at 00:40 correctly.

    I tried to convert the uncompressed file using ffmpeg with msvideo1 encoder, the output file still cannot be played correctly.

    VLC cannot play this file correctly either.

    Here's some code I used to prepare the stream:

        AVISTREAMINFO StreamInfo;
        ZeroMemory(&StreamInfo, sizeof(AVISTREAMINFO));
    
        FrameInfo.bmiHeader.biPlanes = 1;
        FrameInfo.bmiHeader.biWidth = 512;
        FrameInfo.bmiHeader.biHeight = 512;
        FrameInfo.bmiHeader.biCompression = BI_RGB;
        FrameInfo.bmiHeader.biBitCount = 24;
        FrameInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        FrameInfo.bmiHeader.biSizeImage = 512 * 512 * 3;
    
        auto HIC = ICOpen(mmioFOURCC('V', 'I', 'D', 'C'), mmioFOURCC('M', 'S', 'V', 'C'), ICMODE_QUERY);
        auto QueryResult = ICCompressQuery(HIC, &FrameInfo, nullptr);
        wcscpy_s(StreamInfo.szName, L"TEST Compress Video Stream");
    
        StreamInfo.fccType = streamtypeVIDEO;
        StreamInfo.fccHandler = mmioFOURCC('M', 'S', 'V', 'C');
        StreamInfo.dwScale = 100000;
        StreamInfo.dwRate = 12500;
        StreamInfo.dwQuality = 8000;
        StreamInfo.dwSuggestedBufferSize = FrameInfo.bmiHeader.biSizeImage;
        SetRect(&StreamInfo.rcFrame, 0, 0, FrameInfo.bmiHeader.biWidth, FrameInfo.bmiHeader.biHeight);
    
        auto CreateStreamResult = AVIFileCreateStream(AviFile, &Stream, &StreamInfo);
    
        AVICOMPRESSOPTIONS CompressOption;
        ZeroMemory(&CompressOption, sizeof(AVICOMPRESSOPTIONS));
        CompressOption.fccType = streamtypeVIDEO;
        CompressOption.fccHandler = StreamInfo.fccHandler;
        //CompressOption.dwKeyFrameEvery = 1;
        CompressOption.dwQuality = 8000;
        CompressOption.dwFlags = AVICOMPRESSF_VALID;
    
        auto MakeCompressStreamResult = AVIMakeCompressedStream(&CompressedStream, Stream, &CompressOption, nullptr);
        auto SetFormatResult = AVIStreamSetFormat(CompressedStream, 0, &FrameInfo.bmiHeader, FrameInfo.bmiHeader.biSize);


    Does anyone know why the last frame cannot be played correctly?

    Thanks for reading.

    Best Regards,

    Chen

    Thursday, December 8, 2016 3:54 AM