locked
SinkWriter and frame resizing RRS feed

  • Question

  • Re-posting this under MSDN account.

    I'm working on a simple video editing application.  It is required to do simple trimming and combining across multiple video files (ie take 10 seconds from video A and 10 seconds from video B and write them to a single file).  I may assume that all video files are MP4 containers with one H264 encoded video stream.  I currently have a working build that fulfills these basic requirements.   However, I must be able to combine clips from videos with different resolutions.  Setting SinkWriter's input type to have a different resolution than its output type results in an error.  Attempting to set the SourceReader's output type to a different resolution than the video it is reading also results in an error.  The approach I've decided to take is to use the Video Resizer DSP to manually resize the frames after I get them from the SourceReader, then pass them on to the SinkWriter.

    I'm creating a VideoResizer and using it as an IMFTransform.  I use its IPropertyStore to set the 4 MFPKEY_RESIZE_DST properties, then set its input and output types using the output type of the SourceReader.  Finally, I call ProcessMessage with MFT_MESSAGE_NOTIFY_START_OF_STREAM.  However, when I call ProcessInput with a video sample, it returns E_INVALIDARG.  Error checking is omitted in the code below,  all function calls return S_OK.

    Creating the Resizer's input and output media types from the reader

    //Use the reader's output type as the Resizer's input type IMFMediaType* theInputType; aReader->GetCurrentMediaType( mOutputVideoStreamIndex, &theInputType ); //Copy the reader's ouput type IMFMediaType* theOutputType; MFCreateMediaType( &theOutputType ); theInputType->CopyAllItems( theOutputType ); //Set the frame size to the desired size UINT32 theFrameWidth, theFrameHeight; MFGetAttributeSize(mUncompressedVideoType, MF_MT_FRAME_SIZE, &theFrameWidth, &theFrameHeight); MFSetAttributeSize(theOutputType, MF_MT_FRAME_SIZE, theFrameWidth, theFrameHeight);

    ConfigureVideoResizer( theInputType, theOutputType );

    Resizer Configuration

    CoCreateInstance(CLSID_CResizerDMO, NULL, CLSCTX_ALL, __uuidof( IMFTransform ), (void**)( &mVideoResizer ) );
    
        MFGetAttributeSize(aOutputType, MF_MT_FRAME_SIZE, &mVideoWidth, &mVideoHeight);
        IPropertyStore* thePropertyStore;
        mVideoResizer->QueryInterface( &thePropertyStore ), dHere );
    
        PROPVARIANT theTopLeft;
        InitPropVariantFromInt32(0, &theTopLeft);
        thePropertyStore->SetValue( MFPKEY_RESIZE_DST_LEFT, theTopLeft;
        thePropertyStore->SetValue( MFPKEY_RESIZE_DST_TOP, theTopLeft;
    
        //Set width and height to scale to
        PROPVARIANT theWidthVariant, theHeightVariant;
        InitPropVariantFromInt32( mVideoWidth, &theWidthVariant);
        InitPropVariantFromInt32( mVideoHeight, &theHeightVariant );
         thePropertyStore->SetValue( MFPKEY_RESIZE_DST_WIDTH, theWidthVariant );
         thePropertyStore->SetValue( MFPKEY_RESIZE_DST_HEIGHT, theHeightVariant );
    
         mVideoResizer->SetInputType( 0, aInputType, NULL );
         mVideoResizer->SetOutputType( 0, aOutputType, NULL );

    1. The obvious first question: is using the VideoResizer a viable approach to solve the problem I am facing

    2. What are the possible causes of receiving E_INVALIDARG from the VideoResizer?

    Monday, July 15, 2013 2:32 PM