Community
cancel
Showing results for 
Search instead for 
Did you mean: 
frenet
Beginner
48 Views

Problem with video file using H264VideoEncoder and MP4Muxer

I am encoding live images using the H264VideoEncoder and the MP4Muxer. I need some help in determining which parameters that I am not setting correctly.

This is the problem that I am seeing:

I am encoding 300 frames. During the encoding process, I monitor the output video file in explorer and the file size remains zero until the 250th frame has been encoded. At this point the file size is updated. The file size will not change until after the muxer is closed at which time it updates to its final size. When I examine the completed video file, it reports only 250 frames and playback will only show 250 frames.

I noticed that 250 is the default value for the H264EncoderParams' key_frame_controls.interval member. If I set key_frame_controls.interval to 300 and re-run my app, then I see similar behaviour as before but this time during encoding the video file size remains 0 bytes until the last frame has been encoded. The final video reports 300 frames.

I have included some code snippets showing how I set things up. For the encoder I am only setting the resolution, frame rate and bitrate. I have also tried setting other values (commented out below) but the number of frames reported by the final video is whatever the key_frame_controls.interval is set to.

Are there any issues when encoding from a live source (I do not know how many frames will be encoded beforehand)?

Are there any examples of encoding a live source using the MP4Muxer?


These are the only settings that I modify for the H264EncoderParams:

UMC::H264EncoderParams currParams;
currParams.info.clip_info.width = 640
currParams.info.clip_info.height = 480;
currParams.info.framerate = 60;
currParams.info.bitrate = 1000000;
//currParams.numFramesToEncode = 0;
//currParams.key_frame_controls.method = 1;
//currParams.key_frame_controls.interval = 50;
//currParams.key_frame_controls.idr_interval = 0;
//currParams.B_frame_rate = 1;
//currParams.treat_B_as_reference = 1;
//currParams.num_ref_frames = 2;
//currParams.num_ref_to_start_code_B_slice = 1;
m_h264Encoder.Init(&currParams);


This is the code used to set up the MP4Muxer:

m_writerParams.m_portion_size = 0;
vm_string_strcpy(m_writerParams.m_file_name, filename);
m_fileWriter.Init(&m_writerParams);

m_videoInfo.clip_info.width = 640;
m_videoInfo.clip_info.height = 480;
m_videoInfo.framerate = 60;
m_videoInfo.stream_type = UMC::H264_VIDEO;
m_videoInfo.interlace_type = UMC::PROGRESSIVE;
m_videoInfo.color_format = UMC::YUV420;
m_videoInfo.streamPID = 0;

m_muxerParams.m_lpDataWriter = &m_fileWriter;
m_muxerParams.m_SystemType = UMC::H264_PURE_VIDEO_STREAM;
m_muxerParams.m_lFlags=UMC::FLAG_START_WITH_HEADER|UMC::FLAG_FRAGMENTED_AT_I_PICTURES;
m_muxerParams.m_nNumberOfTracks = 1;
m_muxerParams.pTrackParams = new UMC::TrackParams[m_muxerParams.m_nNumberOfTracks];
m_muxerParams.pTrackParams[0].type = UMC::VIDEO_TRACK;
m_muxerParams.pTrackParams[0].info.video = &m_videoInfo;
m_muxerParams.pTrackParams[0].bufferParams.m_prefOutputBufferSize = 1000000;
m_muxerParams.pTrackParams[0].bufferParams.m_prefInputBufferSize = 1000000;
m_muxerParams.pTrackParams[0].bufferParams.m_numberOfFrames = 30;
m_mp4Muxer.Init(&m_muxerParams);



Thanks.
0 Kudos
1 Reply
Tamer_Assad
Innovator
48 Views

Hi frenet ,

UMC Muxers associates a UMC FileWriter object, which performs a normal file writing opertion, so once the file data got commited your file on drive will be updated.

Regarding the number of frames produced, well, UMC encoders were not designed for real-time encoding, you may restart the components and the buffers at the beginning of each frame set, as a workaround. You will have to allign the GOP spesifications accordingly to produce a good stream then.

Regards,

Tamer Assad,
Reply