locked
SinkWriter - Set frame duration

    Question

  • In a Windows Store App, when I set the frame duration nothing seems to happen - each new frame gets added approx once per second. The video gets created at the set FPS rate. SetSampleDuration seems to have no effect (no matter what value I give it).

    ComPtr<IMFSample> spSample;  
    CHK(MFCreateSample(&spSample));  

    // In 100-nano-second units
    // 1ms = 1000ns
    // SampleDuration = 10 x Img.IntervalMS
    long long _duration = (long long)1; // frameDuration * (long long)10;
    CHK(spSample->SetSampleDuration(_duration));
    //CHK(spSample->SetSampleTime(_hnsSampleTime));  
    _hnsSampleTime += _duration;  

    // Add a media buffer
    ComPtr<IMFMediaBuffer> spBuffer;
    CHK(MFCreateMemoryBuffer(_bufferLength, &spBuffer));  
    CHK(spBuffer->SetCurrentLength(_bufferLength));  
    CHK(spSample->AddBuffer(spBuffer.Get()));  

    // Copy the picture into the buffer
    unsigned char *pbBuffer = nullptr;    
    CHK(spBuffer->Lock(&pbBuffer, nullptr, nullptr));  
    memcpy(pbBuffer, buffer->begin(), _bufferLength);
    CHK(spBuffer->Unlock());  

    // Write the media sample  
    CHK(_spSinkWriter->WriteSample(_streamIndex, spSample.Get()));

    Thursday, January 24, 2013 12:02 PM

Answers

  • Worked it out.

    long long _duration = (long long)frameDuration * (long long)10000;
    CHK(spSample->SetSampleDuration(_duration));
    CHK(spSample->SetSampleTime(_hnsSampleTime));
    _hnsSampleTime += _duration; 

    framDuration is in milliseconds

    Friday, January 25, 2013 3:39 AM

All replies

  • Worked it out.

    long long _duration = (long long)frameDuration * (long long)10000;
    CHK(spSample->SetSampleDuration(_duration));
    CHK(spSample->SetSampleTime(_hnsSampleTime));
    _hnsSampleTime += _duration; 

    framDuration is in milliseconds

    Friday, January 25, 2013 3:39 AM
  • Thanks for sharing the solution.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 28, 2013 3:03 AM