Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

MPEG4VideoEncoder resizing frame resolution

stsybikov
Beginner
608 Views

Hi,

 

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;

Muxer.Init(&MuxerParams);

 

UMC::MPEG4EncoderParams videoParams;

videoParams.info.clip_info.height = 780;

videoParams.info.clip_info.width = 1280;            

videoParams.info.bitrate = 24000;

videoParams.info.color_format = UMC::YUV420;

videoParams.info.framerate = 10000000;

videoParams.info.stream_type = UMC::MPEG4_VIDEO;

videoParams.info.aspect_ratio_height = 9;

videoParams.info.aspect_ratio_width = 16;

videoParams.numThreads = 1; 

 

UMC::MPEG4VideoEncoder Mpeg4Encoder;

Mpeg4Encoder.Init(&videoParams);

 

UMC::VideoData DataVideoIn;

DataVideoIn.Init(1920,1080,UMC::YUV420,8);

 

Int VideoBufferSize = 1080x1920*3/2;

DataVideoIn.SetBufferPointer(m_pVideoFrameBuffer, VideoBufferSize);

DataVideoIn.SetDataSize(VideoBufferSize);

 

DataVideoOut.SetBufferPointer(pOutputVideoData, 100000000);

 

Mpeg4Encoder.GetFrame(DataVideoIn, DataVideoOut);

int nDataSize = DataVideoOut.GetDataSize();    

MuxVideoData.SetBufferPointer(pOutputVideoData, nDataSize);

Mp4Muxer.PutVideoData(pMuxVideoData);

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

MuxVideoData->SetDataSize(nDataSize);

 

 

 

I attached the mpeg4 file.

0 Kudos
1 Solution
Pavel_V_Intel
Employee
608 Views
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); inputData.Alloc(); resizedData.Init(1280, 780, YUV420); resizedData.Alloc(); resizer.SetMethod(IPPI_INTER_LINEAR); // interpolation method, there is more for(;;) { readFrame(inputData); resizer.GetFrame(inputData, resizedData); decoder.GetFrame(resizedData, outputData); }

View solution in original post

0 Kudos
8 Replies
stsybikov
Beginner
608 Views
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.
0 Kudos
stsybikov
Beginner
608 Views
Sorry, My name is Sergey Tsybikov, Smith & Nephew Endoscopy
0 Kudos
Pavel_V_Intel
Employee
609 Views
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); inputData.Alloc(); resizedData.Init(1280, 780, YUV420); resizedData.Alloc(); resizer.SetMethod(IPPI_INTER_LINEAR); // interpolation method, there is more for(;;) { readFrame(inputData); resizer.GetFrame(inputData, resizedData); decoder.GetFrame(resizedData, outputData); }
0 Kudos
stsybikov
Beginner
608 Views
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. Regards, Sergey Tsybikov Smith&Nephew Endoscopy
0 Kudos
Pavel_V_Intel
Employee
608 Views
You probably forgot to change resolution in parameters for muxer. Container report 1920x1080 and actual stream happens to be 1280x720.
0 Kudos
stsybikov
Beginner
608 Views
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].info.video = &VideoStreamInfo; I did the init MP4Muxer with MuxerParams MP4Muxer.Init(&MuxerParams); Defined encoder params with final resolution MPEG4EncoderParams.info.clip_info.height = 720; MPEG4EncoderParams.info.clip_info.width = 1280; Did the init of encoder MPEG4VideoEncoder.Init(&MPEG4Encoder); Plus based on you suggestion I used VideoResizing class with 1280 and 720 Thank you. Sergey Tsybikov
0 Kudos
stsybikov
Beginner
608 Views
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
0 Kudos
Pavel_V_Intel
Employee
608 Views
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.
0 Kudos
Reply