0

Is it possible to create DASH compliant Mp4 files with MFCreateFMPEG4MediaSink.

The API says MFCreateFMPEG4MediaSink supports fragmented mp4. Is this the default behavior or do we need to set some flags.

When I try to play files generated by MFCreateFMPEG4MediaSink in MediaSource in javascript, it does not play. I inspect the generated file with MP4Box.js and it says it is not fragmented.

Thanks UPDATE:

  IMFMediaBuffer * pBuffer;
    // Create a new memory buffer.
    HRESULT hr = MFCreateMemoryBuffer(data_length, &pBuffer);

    BYTE *pData = NULL;
    // Lock the buffer and copy the video frame to the buffer.
    if (SUCCEEDED(hr))
    {
        DWORD buffLen = data_length;
        hr = pBuffer->Lock(&pData,NULL, NULL);
    }

    if (SUCCEEDED(hr))
    {
        memcpy(pData, data, data_length);
    }

    if (pBuffer)
    {
        pBuffer->Unlock();
    }

    // Set the data length of the buffer.
    if (SUCCEEDED(hr))
    {
        hr = pBuffer->SetCurrentLength(data_length);
    }

    // Create a media sample and add the buffer to the sample.
    IMFSample * pSample;
    if (SUCCEEDED(hr))
    {
        hr = MFCreateSample(&pSample);
    }
    if (SUCCEEDED(hr))
    {
        hr = pSample->AddBuffer(pBuffer);
    }

    // Set the time stamp and the duration.
    if (SUCCEEDED(hr))
    {
        hr = pSample->SetSampleTime(rtStart);
    }
    if (SUCCEEDED(hr))
    {
        hr = pSample->SetSampleDuration(video_frame_duration);
    }
    rtStart += video_frame_duration;
    /*if (SUCCEEDED(hr))
    {
        hr = pSample->SetUINT32(MFSampleExtension_CleanPoint, isIDR);
    }*/
    //pSample->
    // Send the sample to the Sink Writer.
    if (SUCCEEDED(hr))
    {
        hr = pSinkWriter->WriteSample(0, pSample);
    }

    SafeRelease(&pSample);
    SafeRelease(&pBuffer);
    return 1;

THIS IS WHERE I CREATE THE SINKER

if (SUCCEEDED(hr))
    {
        hr = MFCreateMediaType(&pMediaType);
    }
    //unsigned char * pSeqHdr = reinterpret_cast<UINT8 *>(mSamplesQueue.SequenceHeader());
    /*
    if (SUCCEEDED(hr))
    {
        hr = pMediaType->SetBlob(MF_MT_MPEG_SEQUENCE_HEADER, blob, 25);
    }
    UINT32 pcbBlobSize = { 0 };
    hr = pMediaType->GetBlobSize(MF_MT_MPEG_SEQUENCE_HEADER, &pcbBlobSize);
    */


    /*if (SUCCEEDED(hr)) {
        hr = pMediaType->SetUINT32(MF_MPEG4SINK_MOOV_BEFORE_MDAT, 1);
    }*/
    if (SUCCEEDED(hr))
    {
        hr = pMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
    }
    if (SUCCEEDED(hr))
    {
        hr = MFSetAttributeRatio(pMediaType, MF_MT_FRAME_RATE, frame_rate, 1);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaType->SetUINT32(MF_MT_AVG_BITRATE, bit_rate);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
    }
    if (SUCCEEDED(hr))
    {
        hr = MFSetAttributeSize(pMediaType, MF_MT_FRAME_SIZE, width, height);
    }
    if (SUCCEEDED(hr))
    {
        // Pixel aspect ratio
        hr = MFSetAttributeRatio(pMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
    }


if (SUCCEEDED(hr))
    {
        hr = MFCreateFile(
            MF_ACCESSMODE_READWRITE,
            MF_OPENMODE_DELETE_IF_EXIST,
            MF_FILEFLAGS_NONE,
            L"output2temp.mp4",
            &pByteStream);
    }

    if (SUCCEEDED(hr))
    {
        hr = MFCreateMPEG4MediaSink(
            pByteStream,
            pMediaType,
            NULL,
            &pMediaSink);
    }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Evren Bingøl
  • 1,306
  • 1
  • 20
  • 32

0 Answers0