locked
Microsort Media Foundation: writing out uncompressed video RRS feed

  • Question

  • Hello,

    In the following tutorial (Using a SinkWriter to encode a video)

    http://msdn.microsoft.com/en-us/library/windows/desktop/ff819477%28v=vs.85%29.aspx

    the input is uncompressed video (MFVideoFormat_RGB32) and the output is a compressed one (MFVideoFormat_WMV3).

    I am having trouble with following scenario: uncompressed output (use case: I am grabbing screen shots and want to write those in a file the same way 'as is' - uncompressed) How to bypass any encoding? What media type to use? What container? Etc... I tried several approaches but the closest one so far was: making input and output the same (MFVideoFormat_RGB32) but IMFSinkWriter::Finalize() hangs (in this case I was using MFCreateSinkWriterFromURL("out.wmv"...)) Thank you in advance.

    Friday, October 12, 2012 2:39 PM

All replies

  • Did you tried MFCreateSinkWriteFromURL("out.avi".....)? AVI if you won't specify any parameters, it will store it in uncompressed collection of images.
    Tuesday, October 16, 2012 10:07 AM
  • Thanks.

    I tried your suggestion

    HRESULT hr = MFCreateSinkWriterFromURL(L"output.avi", NULL, NULL, &pSinkWriter);

    It returns -1072875819

    So it does not work - looks like AVI extension (and associated container type) is not supported by SinkWriter subsystem of MF.

    Wednesday, October 17, 2012 5:12 PM
  • There is no AVI sink in MF, so you will not be able to write AVI files.  WMV files support uncompressed video, though, so you should be okay.  We have a number of tests that output RGB32 video through the sink writer into a WMV file, so it is surprising that you are hitting a hang.  Can you try setting a modified size (MF_MT_FRAME_SIZE) on the output media type of the sink writer?  This would cause a converter to get inserted which might shake things out of the broken state.

    Friday, November 9, 2012 1:18 AM
  • I have the same problem, also with WMV media writer. Changing output size results in SetInputMediaType failing with 0xc00d5212 error. 

    I also have this problem when I try to use my own Encoder (implementing IMFTransform). MF calls all methods of the IMFTransform correctly, including "Drain" message and last ProcessOutput, but SinkWriter Finalize never returns.

    I tried to investigate with MFTrace, but Finalize is not appearing in the log, last line is the last call to WriteSample


    We have a number of tests that output RGB32 video through the sink writer into a WMV file, so it is surprising that you are hitting a hang. 

    Is it possible to try one of those tests?

    • Edited by berguina Wednesday, November 28, 2012 5:33 PM
    Wednesday, November 28, 2012 4:23 PM
  • Here, a complete example of my attempt to write out uncompressed video, 50 frames at 25 fps.  It should print one line for each frame, then one line before and after call to SinkWriter::Finalize. It will never finish, it hangs in the Finalize call. If you replace uncompressed output type by the compressed one (which is commented), then everything works fine. 

    Another strange thing is that writing frames from about frame nr.28 is very slow.

    What am I doing wrong?

    #include "stdafx.h"
    #include <Windows.h>
    #include <mfapi.h>
    #include <mfidl.h>
    #include <Mfreadwrite.h>
    #include <mferror.h>
    
    #pragma comment(lib, "mfreadwrite")
    #pragma comment(lib, "mfplat")
    #pragma comment(lib, "mfuuid")
    
    #define FORCE(expr) { if(FAILED(hr=(expr))){printf("Error in %s, %d, %x\n",__FILE__,__LINE__,hr);goto END;} }
    template <class T> void SafeRelease(T **ppT){ if (*ppT){ (*ppT)->Release(); *ppT = NULL; }}
    
    const UINT32 VIDEO_WIDTH = 640;
    const UINT32 VIDEO_HEIGHT = 480;
    const UINT32 VIDEO_FPS = 25;
    const UINT32 VIDEO_BIT_RATE = 800000;
    const GUID   VIDEO_ENCODING_FORMAT = MFVideoFormat_WMV3;
    const GUID   VIDEO_INPUT_FORMAT = MFVideoFormat_RGB32;
    const UINT32 VIDEO_PELS = VIDEO_WIDTH * VIDEO_HEIGHT;
    const UINT32 VIDEO_FRAME_COUNT = 2 * VIDEO_FPS;
    const WCHAR VIDEO_FILE_NAME[] =L"E:\\temp\\testU.wmv";
    
    DWORD videoFrameBuffer[VIDEO_PELS];
    
    HRESULT WriteFrame(
        IMFSinkWriter *pWriter, 
        DWORD streamIndex, 
        const LONGLONG& rtStart,        // Time stamp.
        const LONGLONG& rtDuration      // Frame duration.
        )
    {
        IMFSample *pSample = NULL;
        IMFMediaBuffer *pBuffer = NULL;
    
        const LONG cbWidth = 4 * VIDEO_WIDTH;
        const DWORD cbBuffer = cbWidth * VIDEO_HEIGHT;
    
        BYTE *pData = NULL;
    	HRESULT hr = S_OK;
    
        FORCE(MFCreateMemoryBuffer(cbBuffer, &pBuffer));
        FORCE(pBuffer->Lock(&pData, NULL, NULL));
    
    	FORCE(MFCopyImage(
                pData,                      // Destination buffer.
                cbWidth,                    // Destination stride.
                (BYTE*)videoFrameBuffer,    // First row in source image.
                cbWidth,                    // Source stride.
                cbWidth,                    // Image width in bytes.
                VIDEO_HEIGHT                // Image height in pixels.
                ));
    
    
        FORCE(pBuffer->Unlock());
        FORCE(pBuffer->SetCurrentLength(cbBuffer));
        FORCE(MFCreateSample(&pSample));
        FORCE(pSample->AddBuffer(pBuffer));
        FORCE(pSample->SetSampleTime(rtStart));    
    	FORCE(pSample->SetSampleDuration(rtDuration));
        FORCE(pWriter->WriteSample(streamIndex, pSample));
        
    END:
        SafeRelease(&pSample);
        SafeRelease(&pBuffer);
        return hr;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	HRESULT hr=S_OK;
    	IMFSinkWriter *pSinkWriter=NULL;
    	IMFMediaType *pMediaTypeIn=NULL;
    	IMFMediaType *pMediaTypeOut=NULL;
    
    	FORCE(CoInitializeEx(NULL, COINIT_MULTITHREADED));
    	FORCE(MFStartup(MF_VERSION));
    
    	DWORD streamIndex=0;
    
    	for (DWORD i = 0; i < VIDEO_PELS; ++i)
        {
            videoFrameBuffer[i] = 0x0000FF00;
        }
    	
    	FORCE(MFCreateSinkWriterFromURL(VIDEO_FILE_NAME, NULL, NULL, &pSinkWriter));
    
    	FORCE(MFCreateMediaType(&pMediaTypeIn));   
    	FORCE(pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));     
    	FORCE(pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, VIDEO_INPUT_FORMAT));   
    	FORCE(pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));   
    	FORCE(MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));   
    	FORCE(MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, VIDEO_FPS, 1));   
    	FORCE(MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1,1));   
        FORCE(pMediaTypeIn->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE));
        FORCE(pMediaTypeIn->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
    
    	//Uncompressed output, this will hang in the SinkWriter::Finalize
    
    	FORCE(MFCreateMediaType(&pMediaTypeOut));   
    	FORCE(pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));     
    	FORCE(pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, VIDEO_INPUT_FORMAT));
    	FORCE(pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));   
    	FORCE(MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));   
    	FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, VIDEO_FPS, 1));   
    	FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1,1));   
        FORCE(pMediaTypeOut->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE));
        FORCE(pMediaTypeOut->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
    
    	//Compressed output, this works fine
    
    	//FORCE(MFCreateMediaType(&pMediaTypeOut));   
    	//FORCE(pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));     
    	//FORCE(pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, VIDEO_ENCODING_FORMAT));   
    	//FORCE(pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, VIDEO_BIT_RATE)); 
    	//FORCE(pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));   
    	//FORCE(MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));   
    	//FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, VIDEO_FPS, 1));   
    	//FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1,1));   
    
    	FORCE(pSinkWriter->AddStream(pMediaTypeOut, &streamIndex));   
    	FORCE(pSinkWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL));   
    
    	FORCE(pSinkWriter->BeginWriting());
    
        LONGLONG rtStart = 0;
        UINT64 rtDuration;
    
    	MFFrameRateToAverageTimePerFrame(VIDEO_FPS, 1, &rtDuration);
    
        for (DWORD i = 0; i < VIDEO_FRAME_COUNT; ++i)
        {
            printf("Writing frame %d/%d\n",i+1,VIDEO_FRAME_COUNT);
    
    		hr = WriteFrame(pSinkWriter, streamIndex, rtStart, rtDuration);
           
    		if (FAILED(hr))
            {
                break;
            }
    
            rtStart += rtDuration;
        }
    
    	printf("Calling finalize...\n");
    
    	FORCE(pSinkWriter->Finalize());
    
    	printf("Done! Press any key...\n");
    
    
    END:
    	SafeRelease(&pSinkWriter);
    	SafeRelease(&pMediaTypeIn);
    	SafeRelease(&pMediaTypeOut);
    	MFShutdown();
    	CoUninitialize();
    
    	getchar();
    	return hr;
    }


    • Edited by berguina Friday, November 30, 2012 3:45 PM
    Friday, November 30, 2012 3:40 PM
  • +1 on publishing just one of those working tests which write out uncompressed frames.

    Monday, December 17, 2012 8:16 PM
  • Maybe the sinkwriter does not support the .avi extension. You can write custom avi sink in order to  save to .avi file.

    Thursday, December 27, 2012 9:10 AM
  • I try to save .wmv, not .avi.  With the compressed media type it works fine.
    Thursday, December 27, 2012 10:05 AM
  • Hi,

    Take a look at this: http://msdn.microsoft.com/en-us/library/windows/desktop/ff485865(v=vs.85).aspx

    You have to set those attributes both for pMediaTypeIn and pMediaTypeOut. In my case for some reason I had also to set MF_MT_AVG_BITRATE for pMediaTypeOut (it's uncompressed, so use: cbImage * frameRate * 8), where cbImage is the output of MFCalculateImageSize). 

    I hope this helps.

    Giuliano



    • Edited by squalano Thursday, January 10, 2013 4:16 PM
    Thursday, January 10, 2013 4:06 PM
  • My MF_MT_SUBTYPE is MFVideoFormat_RGB32 for both input and output, which subtype should I use for the output?

    Could you please post your working code, or fix mine and post it?

    Thursday, January 10, 2013 4:11 PM
  • Hi

    Considering the attributes listed in that link, in your code you should use something like:

    ...
    
    UINT32 cbImage = 0;
    
    FORCE(MFCreateSinkWriterFromURL("output.wmv", NULL, NULL, &pSinkWriter);
    
    // Set the output media type
    FORCE(MFCreateMediaType(&pMediaTypeOut));
    FORCE(pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
    FORCE(pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32));
    FORCE(pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
    FORCE(MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));
    FORCE(MFSetAttributeSize(pMediaTypeOut, MF_MT_DEFAULT_STRIDE, VIDEO_WIDTH * BYTES_PER_PIXEL, 1)); // Calculate the default stride value.
    FORCE(MFCalculateImageSize(MFVideoFormat_RGB32, VIDEO_WIDTH, VIDEO_HEIGHT, &cbImage));	// Calculate the image size in bytes.
    FORCE(pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, cbImage * VIDEO_FPS * 8));
    FORCE(pMediaTypeOut->SetUINT32(MF_MT_SAMPLE_SIZE, cbImage));
    FORCE(pMediaTypeOut->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE));
    FORCE(pMediaTypeOut->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
    FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, VIDEO_FPS, 1));
    FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
    
    FORCE(pSinkWriter->AddStream(pMediaTypeOut, &streamIndex));
    FORCE(pMediaTypeOut->Release());
    
    // Set the input media type
    FORCE(MFCreateMediaType(&pMediaTypeIn);
    FORCE(pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
    FORCE(pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32));
    FORCE(pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
    FORCE(MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));
    FORCE(MFSetAttributeSize(pMediaTypeIn, MF_MT_DEFAULT_STRIDE, VIDEO_WIDTH * BYTES_PER_PIXEL, 1));
    FORCE(MFCalculateImageSize(MFVideoFormat_RGB32, VIDEO_WIDTH, VIDEO_HEIGHT, &cbImage));
    FORCE(pMediaTypeIn->SetUINT32(MF_MT_SAMPLE_SIZE, cbImage));
    FORCE(pMediaTypeIn->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE));
    FORCE(pMediaTypeIn->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
    FORCE(MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, VIDEO_FPS, 1));
    FORCE(MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
    
    FORCE(pSinkWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL));
    FORCE(pMediaTypeIn->Release());
    
    // Tell the sink writer to start accepting data
    FORCE(pSinkWriter->BeginWriting());
    
    ..

    Regards,

    Giuliano




    • Edited by squalano Friday, January 11, 2013 2:59 PM
    Thursday, January 10, 2013 8:50 PM
  • Hi Giuliano,

    Thanks for your code, but it doesn't work either. You have rgb24 in MFCalculateImageSize, I changed that to rgb32, but it doesn't help. I also tried rgb24, doesn't work.

    Maybe it only works in Windows 8? I have Windows 7 home premium.





    • Edited by berguina Friday, January 11, 2013 2:54 PM
    Friday, January 11, 2013 2:52 PM
  • Hi,

    Oh you're right, sorry for the typo.

    Anyway, I tried replacing my code block in your code, and it works for me:

    #include <Windows.h>
    #include <mfapi.h>
    #include <mfidl.h>
    #include <Mfreadwrite.h>
    #include <mferror.h>
    #include <cstdio>
    
    #pragma comment(lib, "mfreadwrite")
    #pragma comment(lib, "mfplat")
    #pragma comment(lib, "mfuuid")
    
    #define FORCE(expr) { if(FAILED(hr=(expr))){printf("Error in %s, %d, %x\n",__FILE__,__LINE__,hr);goto END;} }
    template <class T> void SafeRelease(T **ppT){ if (*ppT){ (*ppT)->Release(); *ppT = NULL; }}
    
    const UINT32 VIDEO_WIDTH = 640;
    const UINT32 VIDEO_HEIGHT = 480;
    const UINT32 VIDEO_FPS = 25;
    const UINT32 VIDEO_BIT_RATE = 800000;
    const GUID   VIDEO_ENCODING_FORMAT = MFVideoFormat_WMV3;
    const GUID   VIDEO_INPUT_FORMAT = MFVideoFormat_RGB32;
    const UINT32 VIDEO_PELS = VIDEO_WIDTH * VIDEO_HEIGHT;
    const UINT32 VIDEO_FRAME_COUNT = 2 * VIDEO_FPS;
    const WCHAR VIDEO_FILE_NAME[] =L"E:\\temp\\testU.wmv";
    
    DWORD videoFrameBuffer[VIDEO_PELS];
    
    HRESULT WriteFrame(
        IMFSinkWriter *pWriter, 
        DWORD streamIndex, 
        const LONGLONG& rtStart,        // Time stamp.
        const LONGLONG& rtDuration      // Frame duration.
        )
    {
        IMFSample *pSample = NULL;
        IMFMediaBuffer *pBuffer = NULL;
    
        const LONG cbWidth = 4 * VIDEO_WIDTH;
        const DWORD cbBuffer = cbWidth * VIDEO_HEIGHT;
    
        BYTE *pData = NULL;
    	HRESULT hr = S_OK;
    
        FORCE(MFCreateMemoryBuffer(cbBuffer, &pBuffer));
        FORCE(pBuffer->Lock(&pData, NULL, NULL));
    
    	FORCE(MFCopyImage(
                pData,                      // Destination buffer.
                cbWidth,                    // Destination stride.
                (BYTE*)videoFrameBuffer,    // First row in source image.
                cbWidth,                    // Source stride.
                cbWidth,                    // Image width in bytes.
                VIDEO_HEIGHT                // Image height in pixels.
                ));
    
    
        FORCE(pBuffer->Unlock());
        FORCE(pBuffer->SetCurrentLength(cbBuffer));
        FORCE(MFCreateSample(&pSample));
        FORCE(pSample->AddBuffer(pBuffer));
        FORCE(pSample->SetSampleTime(rtStart));    
    	FORCE(pSample->SetSampleDuration(rtDuration));
        FORCE(pWriter->WriteSample(streamIndex, pSample));
        
    END:
        SafeRelease(&pSample);
        SafeRelease(&pBuffer);
        return hr;
    }
    
    int main()
    {
    	HRESULT hr=S_OK;
    	IMFSinkWriter *pSinkWriter=NULL;
    	IMFMediaType *pMediaTypeIn=NULL;
    	IMFMediaType *pMediaTypeOut=NULL;
    
    	FORCE(CoInitializeEx(NULL, COINIT_MULTITHREADED));
    	FORCE(MFStartup(MF_VERSION));
    
    	DWORD streamIndex=0;
    
    	for (DWORD i = 0; i < VIDEO_PELS; ++i)
        {
            videoFrameBuffer[i] = 0x0000FF00;
        }
    
    	UINT32 cbImage = 0;
    
    	FORCE(MFCreateSinkWriterFromURL(L"output.wmv", NULL, NULL, &pSinkWriter));
    
    	// Set the output media type
    	FORCE(MFCreateMediaType(&pMediaTypeOut));
    	FORCE(pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
    	FORCE(pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32));
    	FORCE(pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
    	FORCE(MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));
    	FORCE(MFSetAttributeSize(pMediaTypeOut, MF_MT_DEFAULT_STRIDE, VIDEO_WIDTH * 4, 1)); // Calculate the default stride value.
    	FORCE(MFCalculateImageSize(MFVideoFormat_RGB32, VIDEO_WIDTH, VIDEO_HEIGHT, &cbImage));	// Calculate the image size in bytes.
    	FORCE(pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, cbImage * VIDEO_FPS * 8));
    	FORCE(pMediaTypeOut->SetUINT32(MF_MT_SAMPLE_SIZE, cbImage));
    	FORCE(pMediaTypeOut->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE));
    	FORCE(pMediaTypeOut->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
    	FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, VIDEO_FPS, 1));
    	FORCE(MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
    
    	FORCE(pSinkWriter->AddStream(pMediaTypeOut, &streamIndex));
    	FORCE(pMediaTypeOut->Release());
    
    	// Set the input media type
    	FORCE(MFCreateMediaType(&pMediaTypeIn));
    	FORCE(pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
    	FORCE(pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32));
    	FORCE(pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
    	FORCE(MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, VIDEO_WIDTH, VIDEO_HEIGHT));
    	FORCE(MFSetAttributeSize(pMediaTypeIn, MF_MT_DEFAULT_STRIDE, VIDEO_WIDTH * 4, 1));
    	FORCE(MFCalculateImageSize(MFVideoFormat_RGB32, VIDEO_WIDTH, VIDEO_HEIGHT, &cbImage));
    	FORCE(pMediaTypeIn->SetUINT32(MF_MT_SAMPLE_SIZE, cbImage));
    	FORCE(pMediaTypeIn->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE));
    	FORCE(pMediaTypeIn->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
    	FORCE(MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, VIDEO_FPS, 1));
    	FORCE(MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
    
    	FORCE(pSinkWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL));
    	FORCE(pMediaTypeIn->Release());
    
    	// Tell the sink writer to start accepting data
    	FORCE(pSinkWriter->BeginWriting());
    
        LONGLONG rtStart = 0;
        UINT64 rtDuration;
    
    	MFFrameRateToAverageTimePerFrame(VIDEO_FPS, 1, &rtDuration);
    
        for (DWORD i = 0; i < VIDEO_FRAME_COUNT; ++i)
        {
            printf("Writing frame %d/%d\n",i+1,VIDEO_FRAME_COUNT);
    
    		hr = WriteFrame(pSinkWriter, streamIndex, rtStart, rtDuration);
           
    		if (FAILED(hr))
            {
                break;
            }
    
            rtStart += rtDuration;
        }
    
    	printf("Calling finalize...\n");
    
    	FORCE(pSinkWriter->Finalize());
    
    	printf("Done! Press any key...\n");
    
    
    END:
    	SafeRelease(&pSinkWriter);
    	MFShutdown();
    	CoUninitialize();
    
    	return hr;
    }

    I'm in Win8, VC11.

    Giuliano


    • Edited by squalano Friday, January 11, 2013 3:08 PM
    Friday, January 11, 2013 3:07 PM
  • Hi Giuliano

    Thank you again. I tested your code and I have exactly the same error as before. It's most likely a problem of Windows 7 then. 


    Friday, January 11, 2013 3:17 PM
  • Hi, 

    I just verified that the same code does not work in Win7. Same symptom you described.
    Now it would be interesting to figure out why, considering that's a huge issue in terms of portability. I didn't find any hint in MSDN.

    Giuliano

    Monday, January 14, 2013 8:25 PM