MPEG4VideoEncoder resizing frame resolution

MPEG4VideoEncoder resizing frame resolution



Did anyone resize a resolution using MPEG4VideoEncoder? It looks that the encoder does not handle the resizing correctly. It works correctly with MPEG2VideoEncoder.


This is my case: I have 1920x1080 YUV420 video streaming and I am trying to encode the data to mpeg4 file. With original 1920x1080 it works great but when I try a smaller frame size in file the video content doesn’t look correctly.

This is simplified sample of my code:


UMC::VideoStreamInfo VideoInfo;        

VideoInfo.streamPID       = 0;     

VideoInfo.stream_type       = UMC::MPEG4_VIDEO;              

VideoInfo.color_format      = UMC::YUV420;

VideoInfo.interlace_type        = UMC::PROGRESSIVE;

VideoInfo.aspect_ratio_height      = 9;

VideoInfo.aspect_ratio_width          = 16;

VideoInfo.clip_info.height       = 1080;

VideoInfo.clip_info.width                            = 1920;

VideoInfo.bitrate                                             = 10000000;

VideoInfo.framerate                                      = 24;


UMC::FileWriter Writer;

UMC::MuxerParams MuxerParams;

MuxerParams.m_lpDataWriter = &Writer;  

MuxerParams.m_SystemType  = UMC::MPEG4_PURE_VIDEO_STREAM;

MuxerParams.m_nNumberOfTracks = 1;

MuxerParams.pTrackParams = new UMC::TrackParams[MuxerParams.m_nNumberOfTracks];


UMC::MP4Muxer Muxer;



UMC::MPEG4EncoderParams videoParams; = 780; = 1280;     = 24000; = UMC::YUV420; = 10000000; = UMC::MPEG4_VIDEO; = 9; = 16;

videoParams.numThreads = 1; 


UMC::MPEG4VideoEncoder Mpeg4Encoder;



UMC::VideoData DataVideoIn;



Int VideoBufferSize = 1080x1920*3/2;

DataVideoIn.SetBufferPointer(m_pVideoFrameBuffer, VideoBufferSize);



DataVideoOut.SetBufferPointer(pOutputVideoData, 100000000);


Mpeg4Encoder.GetFrame(DataVideoIn, DataVideoOut);

int nDataSize = DataVideoOut.GetDataSize();    

MuxVideoData.SetBufferPointer(pOutputVideoData, nDataSize);


memcpy(MuxVideoData-.GetDataPointer(),DataVideoOut.GetDataPointer(), nDataSize);





I attached the mpeg4 file.

Downloadvideo/mp4 nature-result.mp48.12 MB
9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I uploaded mpeg 2 file as well. This is what I expected to be. I zipped it because it's not allowed to upload mpg file.


Downloadapplication/zip mpeg-2-file.zip9.21 MB

My name is Sergey Tsybikov, Smith & Nephew Endoscopy

Best Reply

Good day.

As I understand you have 1920x1080 raw file and want the encoder to resize it to 1280x780 before encoding.
Well, encoders usually don't do that (MPEG2 does because it use VideoProcessing for frame copying). You need to use VideoProcessing class or VideoResizing class directly.

E.g. (schematically):

VideoData inputData;
VideoData resizedData;
VideoResizing resizer;

inputData.Init(1920, 1080, YUV420);

resizedData.Init(1280, 780, YUV420);

resizer.SetMethod(IPPI_INTER_LINEAR); // interpolation method, there is more

resizer.GetFrame(inputData, resizedData);

decoder.GetFrame(resizedData, outputData);

Hi Pavel,

Thank you for the answer. It helped and it works for h264 encoding as well.

The other problem – I did the encoding as 1280x720 and when I tried to play back the mpeg4 video file using VLC media player it shows the size of video as 1920x1080 with garbage data except 1280x720 where I have correct video data. Please check the attached video. When I tried to do it at QuickTime it plays at 1920x1080 but the content is correct. QuickTime Movie Inspector shows me Format as 1920x1080

H264 file does not have this issue.

Sergey Tsybikov
Smith&Nephew Endoscopy

You probably forgot to change resolution in parameters for muxer. Container report 1920x1080 and actual stream happens to be 1280x720.

Hi Pavel,

I could not figure out where these parameters are for the muxer.

I attached original video size to VideoStreamInfo
VideoStreamInfo.clip_info.height = 1080;
VideoStreamInfo.clip_info.width = 1920;

I attached VideoStreanInfo to MuxerParams
MuxerParams.pTrackParams[0] = &VideoStreamInfo;

I did the init MP4Muxer with MuxerParams

Defined encoder params with final resolution = 720; = 1280;

Did the init of encoder

Plus based on you suggestion I used VideoResizing class with 1280 and 720

Thank you.
Sergey Tsybikov

Hi Pavel:

Playing with parameters I figured out that I have a correct video I have to define the follong

VideoStreamInfo.clip_info.height = 720; // target height
VideoStreamInfo.clip_info.width = 1080; // target width

VideoStreamInfo.disp_clip_info.height = 1080; // source height
VideoStreamInfo.disp_clip_info.width = 1920; // source width

Is it right approach?

Thank you
Sergey T

Good day.

> VideoStreamInfo.clip_info.height = 720; // target height
> VideoStreamInfo.clip_info.width = 1080; // target width

As I understand this is a misprint and you meant 1280
Yes, this is right. Container should have actual encoded frame size.

> VideoStreamInfo.disp_clip_info.height = 1080; // source height
> VideoStreamInfo.disp_clip_info.width = 1920; // source width

disp_clip_info is deprecated parameter and doesn't do anything useful.

Leave a Comment

Please sign in to add a comment. Not a member? Join today