transcode video process question regarding b_need_duplicate
Posted: 03 Aug 2014 06:42
I've been tracking down an issue with regards to maintaining near constant bitrate transcoding from mpeg4 to x264. No matter what options I set for x264, I see large spikes in bitrate. X264 logging indicates that the output bitrate is correct. P and I frame placement looks ok from X264's perspective. Running ffprobe on the stream being output shows periods where I'm receiving I frames at a very high rate. This indicates that vlc is doing something in the middle.
I found a code block in /modules/stream_out/transcode/video.c that I'm trying to understand. The code exists in the transcode_video_process function. My understanding of the below code is that in the unlikely event that video has drifted 50ms, don't send the picture, or in the unlikely case that the video is 50ms too early, send a duplicate. My observation is that the conditional which causes duplicates to be sent, causes a number of problems. When this occurs, a spurt of duplicates are sent for a number of seconds or more. This causes the bitrate to increase significantly. We also packetize for HLS, and this seems to break streaming to the latest generation of apple devices. If I comment out the conditional which sets the duplicate flag, bitrate is correct, and streaming works on the latest generation of apple devices. Can someone better explain the conditional below? What is the purpose of the duplicate flag?
I found a code block in /modules/stream_out/transcode/video.c that I'm trying to understand. The code exists in the transcode_video_process function. My understanding of the below code is that in the unlikely event that video has drifted 50ms, don't send the picture, or in the unlikely case that the video is 50ms too early, send a duplicate. My observation is that the conditional which causes duplicates to be sent, causes a number of problems. When this occurs, a spurt of duplicates are sent for a number of seconds or more. This causes the bitrate to increase significantly. We also packetize for HLS, and this seems to break streaming to the latest generation of apple devices. If I comment out the conditional which sets the duplicate flag, bitrate is correct, and streaming works on the latest generation of apple devices. Can someone better explain the conditional below? What is the purpose of the duplicate flag?
Code: Select all
if( unlikely( i_video_drift < (i_master_drift - 50000) ) )
{
#if 0
msg_Dbg( p_stream, "dropping frame (%i)",
(int)(i_video_drift - i_master_drift) );
#endif
picture_Release( p_pic );
continue;
}
else if( unlikely( i_video_drift > (i_master_drift + 50000) ) )
{
#if 0
msg_Dbg( p_stream, "adding frame (%i)",
(int)(i_video_drift - i_master_drift) );
#endif
b_need_duplicate = true;
}