locked
MF_PD_DURATION return imprecise value

    Question

  • Hi I've created a simple decoder for windows 8.1, the output format is pcm_wav header 46bytes long.
    Ok the class works well and writes a file .wav well formatted.
    The problem is the length of pcm data, I calculate at the beginning of process
    in this way:

    HRESULT GetSourceDuration(IMFMediaSource *pSource, MFTIME *pDuration)
    {
        *pDuration = 0;

        IMFPresentationDescriptor *pPD = NULL;

        HRESULT hr = pSource->CreatePresentationDescriptor(&pPD);
        if (SUCCEEDED(hr))
        {
            hr = pPD->GetUINT64(MF_PD_DURATION, (UINT64*)pDuration);
            pPD->Release();
        }
        return hr;
    }

    this return (100ns ticks) an odd value es: 2593440625,
    from this I calculare the length of pcm in bytes

    (2593440625 /1e7)*(nChannel(2)*nByteIntoSample(2)*SampleRate(44100) )= 45748292,625
    I already get odd thing , 625 (??)

    by the way the right size of pcm is 45748224, that you know after write all bytes,
    yep the difference is only few bytes but the point is that: MF_PD_DURATION get wrong time, or imprecise time.
    So the question is how to get right pcm byte length?

    thanks.
    Wednesday, August 27, 2014 11:33 AM

Answers

  • Hi,

    MF_PD_DURATION attribute specifies the duration of a presentation, in 100-nanosecond units.        

    Note:

    Media sources can set this attribute on a presentation descriptor to indicate the duration of the presentation.

    This attribute is a signed value, although it is stored as a UINT64. However, the attribute should never contain a negative value.

    The GUID constant for this attribute is exported from mfuuid.lib.

    Examples

    The following example shows how to get the presentation duration from a media source.

    HRESULT GetSourceDuration(IMFMediaSource *pSource, MFTIME *pDuration)
    {
        *pDuration = 0;
    
        IMFPresentationDescriptor *pPD = NULL;
    
        HRESULT hr = pSource->CreatePresentationDescriptor(&pPD);
        if (SUCCEEDED(hr))
        {
            hr = pPD->GetUINT64(MF_PD_DURATION, (UINT64*)pDuration);
            pPD->Release();
        }
        return hr;
    }
    
    
    
    

    Thanks.

    Monday, September 01, 2014 1:56 AM