Chen OT
Chen OT

Reputation: 3614

How to add color space information in mp4 header using Media Foundation?

Trying to add color space information (primary/transfer matrix/transform function) in MediaFoundation transcoding.

To set the color related attributes on

Only the Nvidia has color tag on output mp4 header, but AMD and Intel do not have.

How do I add the color tag for these two vendor?

Upvotes: 0

Views: 476

Answers (1)

Chen OT
Chen OT

Reputation: 3614

Intercept the buffer and insert the vui parameter with color tag into sps header.

  1. Create a file sink wrapper, which internally create actual file sink by MFCreateMPEG4MediaSink.

  2. Set the attribute MF_MPEG4SINK_SPSPPS_PASSTHROUGH with TRUE to the actual media sink.

  3. Implement IMFMediaSink and IMFStreamSink to hook all APIs.

  4. The IMFStreamSink ::ProcessSample(__RPC__in_opt IMFSample *pSample) will get the encoder output sample.

  5. Create SinkWriter using MFCreateSinkWriterFromMediaSink() with the wrapper.

  6. When running, extract the raw buffer from IMFSample*/IMFMediaBuffer*/BYTE*. Follow the h264 or h265 spec to insert a sps header with

    • Colour Description Present, 1
    • Colour Primaries
    • Transfer Characteristics
    • Matrix Coefficients

Upvotes: 1

Related Questions