Skip to main content

 none
Ho to encode video from uncompressed YUV data to raw H264 bit stream file with Media Foundation RRS feed

  • Question

  • I'd like to do encoding from YUV to raw H264 bitstream without any container(WMV, MP4)

    MS has a similar example for "Tutorial: Using the Sink Writer to Encode Video":
    https://docs.microsoft.com/en-us/windows/desktop/medfound/tutorial--using-the-sink-writer-to-encode-video
    It encodes RGB file to WMV file. 

    I know the VIDEO_INPUT_FORMAT should be changed to "MFVideoFormat_I420". But how to change output setting? I expect that output file is output.264 directly without any container. Any suggestion is appreciated in advance. 



    • Edited by HQ Media Wednesday, April 24, 2019 5:53 PM
    Wednesday, April 24, 2019 3:04 PM

Answers

  • Here is solution:

    Set MF_MT_MAJOR_TYPE to MFMediaType_Video and  MF_MT_SUBTYPE to MFVideoFormat_H264 for output media type. Get the sample(MFT_OUTPUT_DATA_BUFFER) of the output, then get the buffer pointer of the sample. Finally dump the bit stream from the buffer.

    • Marked as answer by HQ Media Tuesday, May 21, 2019 11:38 PM
    Tuesday, May 21, 2019 11:37 PM

All replies

  • Is there someone who can help to give some advice? Thanks in advance.
    • Edited by HQ Media Friday, April 26, 2019 1:10 AM
    Friday, April 26, 2019 1:08 AM
  • There are examples how to change this tutorial and have video encoded as MP4, you should probably look for them - they are almost 1:1 match to WMV encoding.

    You can't encode to raw H.264 that easily. The closest to this is use of Sample Grabber Sink as a sink primitive in order to receive data from encoder and get it to you without multiplexing into container format (MP4). This is known to be working but I am not aware of sample code for this. 

    In any event you are more likely to get feedback if you start sharing your code.


    http://alax.info/blog/tag/directshow

    Friday, April 26, 2019 5:59 AM
  • Hi Roman Ryltsov,
    Thank you very much for your information.  I will check Sample Grabber Sink to see if I can get some hints from it.


    Tuesday, April 30, 2019 4:56 PM
  • Here is solution:

    Set MF_MT_MAJOR_TYPE to MFMediaType_Video and  MF_MT_SUBTYPE to MFVideoFormat_H264 for output media type. Get the sample(MFT_OUTPUT_DATA_BUFFER) of the output, then get the buffer pointer of the sample. Finally dump the bit stream from the buffer.

    • Marked as answer by HQ Media Tuesday, May 21, 2019 11:38 PM
    Tuesday, May 21, 2019 11:37 PM