MediaFoundation HEVC H265 encoding










2















I'm able to successfully encode H264 video using MediaFoundation.



Now I want to export HEVC which is, according to official documentation, is supported.



I am doing everything as described there but whenever I want to set input media type to the writer it ends up with an error:



No suitable transform was found to encode or decode the content.



Here is a short code of what i do:



/* Set output media type */



IMFMediaType* pMediaTypeOut = nullptr;
MFCreateMediaType(&pMediaTypeOut);
pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC);
MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, 640, 480);
MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, 30, 1);
pMediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8);
pMediaTypeOut->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1);

// Add it to the sink writer
m_pWriter->AddStream(pMediaTypeOut, &m_streamIndex);


/* Set input media type */



IMFMediaType* pMediaTypeIn = nullptr;
MFCreateMediaType(&pMediaTypeIn);
pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, 640, 480);
MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, 30, 1),
MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1),

// Here it ends up with an error
m_pWriter->SetInputMediaType(m_streamIndex, pMediaTypeIn, nullptr);


Does anyone know if the HEVC encoding is really supported or it is just a documentation.
And if it is really supported by Microsoft, then what am I doing wrong?



BTW: I am using latest version of Windows 10.
Error checking is omitted for code simplicity










share|improve this question




























    2















    I'm able to successfully encode H264 video using MediaFoundation.



    Now I want to export HEVC which is, according to official documentation, is supported.



    I am doing everything as described there but whenever I want to set input media type to the writer it ends up with an error:



    No suitable transform was found to encode or decode the content.



    Here is a short code of what i do:



    /* Set output media type */



    IMFMediaType* pMediaTypeOut = nullptr;
    MFCreateMediaType(&pMediaTypeOut);
    pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
    pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC);
    MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, 640, 480);
    MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, 30, 1);
    pMediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8);
    pMediaTypeOut->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1);

    // Add it to the sink writer
    m_pWriter->AddStream(pMediaTypeOut, &m_streamIndex);


    /* Set input media type */



    IMFMediaType* pMediaTypeIn = nullptr;
    MFCreateMediaType(&pMediaTypeIn);
    pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
    pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
    MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, 640, 480);
    MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, 30, 1),
    MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1),

    // Here it ends up with an error
    m_pWriter->SetInputMediaType(m_streamIndex, pMediaTypeIn, nullptr);


    Does anyone know if the HEVC encoding is really supported or it is just a documentation.
    And if it is really supported by Microsoft, then what am I doing wrong?



    BTW: I am using latest version of Windows 10.
    Error checking is omitted for code simplicity










    share|improve this question


























      2












      2








      2


      2






      I'm able to successfully encode H264 video using MediaFoundation.



      Now I want to export HEVC which is, according to official documentation, is supported.



      I am doing everything as described there but whenever I want to set input media type to the writer it ends up with an error:



      No suitable transform was found to encode or decode the content.



      Here is a short code of what i do:



      /* Set output media type */



      IMFMediaType* pMediaTypeOut = nullptr;
      MFCreateMediaType(&pMediaTypeOut);
      pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
      pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC);
      MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, 640, 480);
      MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, 30, 1);
      pMediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8);
      pMediaTypeOut->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1);

      // Add it to the sink writer
      m_pWriter->AddStream(pMediaTypeOut, &m_streamIndex);


      /* Set input media type */



      IMFMediaType* pMediaTypeIn = nullptr;
      MFCreateMediaType(&pMediaTypeIn);
      pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
      pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
      MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, 640, 480);
      MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, 30, 1),
      MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1),

      // Here it ends up with an error
      m_pWriter->SetInputMediaType(m_streamIndex, pMediaTypeIn, nullptr);


      Does anyone know if the HEVC encoding is really supported or it is just a documentation.
      And if it is really supported by Microsoft, then what am I doing wrong?



      BTW: I am using latest version of Windows 10.
      Error checking is omitted for code simplicity










      share|improve this question
















      I'm able to successfully encode H264 video using MediaFoundation.



      Now I want to export HEVC which is, according to official documentation, is supported.



      I am doing everything as described there but whenever I want to set input media type to the writer it ends up with an error:



      No suitable transform was found to encode or decode the content.



      Here is a short code of what i do:



      /* Set output media type */



      IMFMediaType* pMediaTypeOut = nullptr;
      MFCreateMediaType(&pMediaTypeOut);
      pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
      pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC);
      MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, 640, 480);
      MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, 30, 1);
      pMediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8);
      pMediaTypeOut->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1);

      // Add it to the sink writer
      m_pWriter->AddStream(pMediaTypeOut, &m_streamIndex);


      /* Set input media type */



      IMFMediaType* pMediaTypeIn = nullptr;
      MFCreateMediaType(&pMediaTypeIn);
      pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
      pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
      MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, 640, 480);
      MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, 30, 1),
      MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1),

      // Here it ends up with an error
      m_pWriter->SetInputMediaType(m_streamIndex, pMediaTypeIn, nullptr);


      Does anyone know if the HEVC encoding is really supported or it is just a documentation.
      And if it is really supported by Microsoft, then what am I doing wrong?



      BTW: I am using latest version of Windows 10.
      Error checking is omitted for code simplicity







      c++ winapi video-encoding ms-media-foundation hevc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 1:25







      mbaros

















      asked Nov 14 '18 at 1:09









      mbarosmbaros

      376115




      376115






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Maybe you can check the existence of the h265 encoder first by DXVA Checker tool or programmatically use MFEnumEx(MFT_CATEGORY_VIDEO_ENCODER, ...) to lookup.



          If not found, you can try installing the HEVC Video Extension on MS App Store. It seems MS has separated the MF HEVC codec into app package after 2018 Fall Creator update. Also, the HW HEVC Encoder needed be installed via vendor's VGA driver.






          share|improve this answer

























          • Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

            – mbaros
            Nov 14 '18 at 23:21



















          2














          Your output media type is incomplete:




          MF_MT_AVG_BITRATE
          Average encoded bit rate, in bits per second. Must be greater than zero.




          Similar problem with MF_MT_INTERLACE_MODE.



          Code snippet that works:



          Check(MFStartup(MF_VERSION));

          ComPtr<IMFSinkWriter> SinkWriter;
          Check(MFCreateSinkWriterFromURL(L"D:\temp.mp4", nullptr, nullptr, SinkWriter.GetAddressOf()));

          ComPtr<IMFMediaType> OutputMediaType;
          Check(MFCreateMediaType(OutputMediaType.GetAddressOf()));
          Check(OutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(OutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC));
          Check(MFSetAttributeSize(OutputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(OutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(OutputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1));
          Check(OutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 1000000));

          DWORD StreamIndex;
          Check(SinkWriter->AddStream(OutputMediaType.Get(), &StreamIndex));

          ComPtr<IMFMediaType> InputMediaType;
          Check(MFCreateMediaType(InputMediaType.GetAddressOf()));
          Check(InputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(InputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12));
          Check(MFSetAttributeSize(InputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(InputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1)),
          //Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)),

          Check(SinkWriter->SetInputMediaType(StreamIndex, InputMediaType.Get(), nullptr));





          share|improve this answer

























          • This didn't work for me!

            – mbaros
            Nov 14 '18 at 22:45











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291761%2fmediafoundation-hevc-h265-encoding%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Maybe you can check the existence of the h265 encoder first by DXVA Checker tool or programmatically use MFEnumEx(MFT_CATEGORY_VIDEO_ENCODER, ...) to lookup.



          If not found, you can try installing the HEVC Video Extension on MS App Store. It seems MS has separated the MF HEVC codec into app package after 2018 Fall Creator update. Also, the HW HEVC Encoder needed be installed via vendor's VGA driver.






          share|improve this answer

























          • Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

            – mbaros
            Nov 14 '18 at 23:21
















          2














          Maybe you can check the existence of the h265 encoder first by DXVA Checker tool or programmatically use MFEnumEx(MFT_CATEGORY_VIDEO_ENCODER, ...) to lookup.



          If not found, you can try installing the HEVC Video Extension on MS App Store. It seems MS has separated the MF HEVC codec into app package after 2018 Fall Creator update. Also, the HW HEVC Encoder needed be installed via vendor's VGA driver.






          share|improve this answer

























          • Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

            – mbaros
            Nov 14 '18 at 23:21














          2












          2








          2







          Maybe you can check the existence of the h265 encoder first by DXVA Checker tool or programmatically use MFEnumEx(MFT_CATEGORY_VIDEO_ENCODER, ...) to lookup.



          If not found, you can try installing the HEVC Video Extension on MS App Store. It seems MS has separated the MF HEVC codec into app package after 2018 Fall Creator update. Also, the HW HEVC Encoder needed be installed via vendor's VGA driver.






          share|improve this answer















          Maybe you can check the existence of the h265 encoder first by DXVA Checker tool or programmatically use MFEnumEx(MFT_CATEGORY_VIDEO_ENCODER, ...) to lookup.



          If not found, you can try installing the HEVC Video Extension on MS App Store. It seems MS has separated the MF HEVC codec into app package after 2018 Fall Creator update. Also, the HW HEVC Encoder needed be installed via vendor's VGA driver.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 7:08

























          answered Nov 14 '18 at 1:29









          Chen OTChen OT

          1,49611229




          1,49611229












          • Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

            – mbaros
            Nov 14 '18 at 23:21


















          • Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

            – mbaros
            Nov 14 '18 at 23:21

















          Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

          – mbaros
          Nov 14 '18 at 23:21






          Yeah! Installing the extension and the code from @Roman helped me! Thanks a lot

          – mbaros
          Nov 14 '18 at 23:21














          2














          Your output media type is incomplete:




          MF_MT_AVG_BITRATE
          Average encoded bit rate, in bits per second. Must be greater than zero.




          Similar problem with MF_MT_INTERLACE_MODE.



          Code snippet that works:



          Check(MFStartup(MF_VERSION));

          ComPtr<IMFSinkWriter> SinkWriter;
          Check(MFCreateSinkWriterFromURL(L"D:\temp.mp4", nullptr, nullptr, SinkWriter.GetAddressOf()));

          ComPtr<IMFMediaType> OutputMediaType;
          Check(MFCreateMediaType(OutputMediaType.GetAddressOf()));
          Check(OutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(OutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC));
          Check(MFSetAttributeSize(OutputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(OutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(OutputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1));
          Check(OutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 1000000));

          DWORD StreamIndex;
          Check(SinkWriter->AddStream(OutputMediaType.Get(), &StreamIndex));

          ComPtr<IMFMediaType> InputMediaType;
          Check(MFCreateMediaType(InputMediaType.GetAddressOf()));
          Check(InputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(InputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12));
          Check(MFSetAttributeSize(InputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(InputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1)),
          //Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)),

          Check(SinkWriter->SetInputMediaType(StreamIndex, InputMediaType.Get(), nullptr));





          share|improve this answer

























          • This didn't work for me!

            – mbaros
            Nov 14 '18 at 22:45
















          2














          Your output media type is incomplete:




          MF_MT_AVG_BITRATE
          Average encoded bit rate, in bits per second. Must be greater than zero.




          Similar problem with MF_MT_INTERLACE_MODE.



          Code snippet that works:



          Check(MFStartup(MF_VERSION));

          ComPtr<IMFSinkWriter> SinkWriter;
          Check(MFCreateSinkWriterFromURL(L"D:\temp.mp4", nullptr, nullptr, SinkWriter.GetAddressOf()));

          ComPtr<IMFMediaType> OutputMediaType;
          Check(MFCreateMediaType(OutputMediaType.GetAddressOf()));
          Check(OutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(OutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC));
          Check(MFSetAttributeSize(OutputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(OutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(OutputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1));
          Check(OutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 1000000));

          DWORD StreamIndex;
          Check(SinkWriter->AddStream(OutputMediaType.Get(), &StreamIndex));

          ComPtr<IMFMediaType> InputMediaType;
          Check(MFCreateMediaType(InputMediaType.GetAddressOf()));
          Check(InputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(InputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12));
          Check(MFSetAttributeSize(InputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(InputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1)),
          //Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)),

          Check(SinkWriter->SetInputMediaType(StreamIndex, InputMediaType.Get(), nullptr));





          share|improve this answer

























          • This didn't work for me!

            – mbaros
            Nov 14 '18 at 22:45














          2












          2








          2







          Your output media type is incomplete:




          MF_MT_AVG_BITRATE
          Average encoded bit rate, in bits per second. Must be greater than zero.




          Similar problem with MF_MT_INTERLACE_MODE.



          Code snippet that works:



          Check(MFStartup(MF_VERSION));

          ComPtr<IMFSinkWriter> SinkWriter;
          Check(MFCreateSinkWriterFromURL(L"D:\temp.mp4", nullptr, nullptr, SinkWriter.GetAddressOf()));

          ComPtr<IMFMediaType> OutputMediaType;
          Check(MFCreateMediaType(OutputMediaType.GetAddressOf()));
          Check(OutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(OutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC));
          Check(MFSetAttributeSize(OutputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(OutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(OutputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1));
          Check(OutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 1000000));

          DWORD StreamIndex;
          Check(SinkWriter->AddStream(OutputMediaType.Get(), &StreamIndex));

          ComPtr<IMFMediaType> InputMediaType;
          Check(MFCreateMediaType(InputMediaType.GetAddressOf()));
          Check(InputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(InputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12));
          Check(MFSetAttributeSize(InputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(InputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1)),
          //Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)),

          Check(SinkWriter->SetInputMediaType(StreamIndex, InputMediaType.Get(), nullptr));





          share|improve this answer















          Your output media type is incomplete:




          MF_MT_AVG_BITRATE
          Average encoded bit rate, in bits per second. Must be greater than zero.




          Similar problem with MF_MT_INTERLACE_MODE.



          Code snippet that works:



          Check(MFStartup(MF_VERSION));

          ComPtr<IMFSinkWriter> SinkWriter;
          Check(MFCreateSinkWriterFromURL(L"D:\temp.mp4", nullptr, nullptr, SinkWriter.GetAddressOf()));

          ComPtr<IMFMediaType> OutputMediaType;
          Check(MFCreateMediaType(OutputMediaType.GetAddressOf()));
          Check(OutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(OutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC));
          Check(MFSetAttributeSize(OutputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(OutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(OutputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8));
          //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1));
          Check(OutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 1000000));

          DWORD StreamIndex;
          Check(SinkWriter->AddStream(OutputMediaType.Get(), &StreamIndex));

          ComPtr<IMFMediaType> InputMediaType;
          Check(MFCreateMediaType(InputMediaType.GetAddressOf()));
          Check(InputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
          Check(InputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12));
          Check(MFSetAttributeSize(InputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
          Check(InputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
          Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1)),
          //Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)),

          Check(SinkWriter->SetInputMediaType(StreamIndex, InputMediaType.Get(), nullptr));






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 7:03

























          answered Nov 14 '18 at 6:45









          Roman R.Roman R.

          57.2k465107




          57.2k465107












          • This didn't work for me!

            – mbaros
            Nov 14 '18 at 22:45


















          • This didn't work for me!

            – mbaros
            Nov 14 '18 at 22:45

















          This didn't work for me!

          – mbaros
          Nov 14 '18 at 22:45






          This didn't work for me!

          – mbaros
          Nov 14 '18 at 22:45


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291761%2fmediafoundation-hevc-h265-encoding%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo