Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.
3061 Discussions

How to set the encoding options for MPEG-2 Video CBR Encoding



Hi, I'm using Intel Media SDK 2014 for Client version.

I'm trying to transcode from H.264 to MPEG-2 Video with CBR(Constant Bit Rate) control mode and use the FFMpeg library for muliplexing.

But the CBR mode doesn't work.  The reason why I think that  is as below.

When mpeg-2 ts(transport stream) rate is 9 Mbps and MPEG-2 Video bitrate is 8Mbps, ffmpeg MPEG-2 TS multiplexing errors occur.

The ffmpeg error is that "dts < pcr, TS is invalid". 

Is it possible to encode with CBR mode for MPEG-2 Video?

Please let me know that, if it is possible.


More detailed video encoding option values that I give are  as follows.

        m_initVideoParam.mfx.CodecProfile = MFX_PROFILE_MPEG2_MAIN;
        m_initVideoParam.mfx.CodecLevel= MFX_LEVEL_MPEG2_HIGH;
        m_initVideoParam.mfx.FrameInfo.Width = 1920;
        m_initVideoParam.mfx.FrameInfo.Height= 1080;
        m_initVideoParam.mfx.FrameInfo.FrameRateExtN = 30000;
        m_initVideoParam.mfx.FrameInfo.FrameRateExtD = 1001; 
        m_initVideoParam.mfx.FrameInfo.AspectRatioW = 0;
        m_initVideoParam.mfx.FrameInfo.AspectRatioH = 0;
        m_initVideoParam.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
        m_initVideoParam.mfx.InitialDelayInKB = 500;
        m_initVideoParam.mfx.BufferSizeInKB = 0;
        m_initVideoParam.mfx.TargetKbps = 8000;
        m_initVideoParam.mfx.MaxKbps = 8000;
        m_initVideoParam.mfx.TargetUsage = 0;
        m_initVideoParam.mfx.GopOptFlag = MFX_GOP_STRICT;
        m_initVideoParam.mfx.GopPicSize = 15;
        m_initVideoParam.mfx.GopRefDist = 3;
        m_initVideoParam.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
        m_initVideoParam.mfx.NumRefFrame = 3;
        m_initVideoParam.mfx.NumSlice = 0;  


when I called GetVideoParam(&vparam), I got the below values.

        vparam.mfx.CodecProfile = MFX_PROFILE_MPEG2_MAIN;
        vparam.mfx.CodecLevel= MFX_LEVEL_MPEG2_HIGH;
        vparam.mfx.FrameInfo.Width = 1920;
        vparam.mfx.FrameInfo.Height= 1088;
        vparam.mfx.FrameInfo.FrameRateExtN = 60000;
        vparam.mfx.FrameInfo.FrameRateExtD = 2002; 
        vparam.mfx.FrameInfo.AspectRatioW = 1;
        vparam.mfx.FrameInfo.AspectRatioH = 1;
        vparam.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
        vparam.mfx.InitialDelayInKB = 364;
        vparam.mfx.BufferSizeInKB = 728;
        vparam.mfx.TargetKbps = 8000;
        vparam.mfx.MaxKbps = 8000;
        vparam.mfx.TargetUsage = 0;
        vparam.mfx.GopOptFlag = MFX_GOP_STRICT;
        vparam.mfx.GopPicSize = 15;
        vparam.mfx.GopRefDist = 3;
        vparam.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
        vparam.mfx.NumRefFrame = 3;
        vparam.mfx.NumSlice = 68;



0 Kudos
3 Replies

Yes CBR is a supported rate control method for MPEG2.  However, the Media SDK encoder's perspective is simply the video elementary stream.  Aside from some rate control cases, Media SDK will just pass along the timestamps it gets from the splitter through the pipeline to the muxer.  Managing the coordination between external container libraries like ffmpeg and Media SDK is left to the application.  

0 Kudos

Hi, Jeffrey.

First, thank you for fast response.

I used "Full Transcoding Sample 5.0.337.78585", which is one of Intel Media SDK Samples.

I modified the sample code for CBR rate control. Because it only supports VBR mode.

The error from ffmpeg container means video stream rate is higher than the expected . 

I have had some experiences about managing between ffmpeg container and video encoders like h.264 for CBR control.

Actually, I calculated the average video rate per one second with the video elementary stream from your MPEG-2 video encoder.

the result is 363794

Please check the attached file.






0 Kudos

So far I have been unable to replicate with the full transcode sample.  Could you attach your modifications, and perhaps a short input to give more details on how to reproduce?

Some things to keep in mind:

  • Media SDK and mpegts time units are 1/90000th of 1 second.
  • Are you sure that timestamps are monotonically increasing?

Thanks, Jeff


0 Kudos