Permalink
Browse files

Detect the cropped picture size in the h.264 parser.

This removes one instance of hardcoded 1088->1080 translation.
Refs #11358.
  • Loading branch information...
stichnot committed Mar 4, 2013
1 parent b174418 commit cc7d7749e38eb3c42edf3403aedf05c82e2e2f3b
@@ -3126,10 +3126,8 @@ int AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)
}
current_aspect = get_aspect(*m_h264_parser);
uint width = m_h264_parser->pictureWidth();
uint height = m_h264_parser->pictureHeight();
if (height == 1088 && current_height == 1080)
height = 1080;
uint width = m_h264_parser->pictureWidthCropped();
uint height = m_h264_parser->pictureHeightCropped();
float seqFPS = m_h264_parser->frameRate();
bool res_changed = ((width != (uint)current_width) ||
@@ -130,6 +130,7 @@ void H264Parser::Reset(void)
delta_pic_order_always_zero_flag = 0;
separate_colour_plane_flag = 0;
chroma_format_idc = 1;
frame_mbs_only_flag = -1;
pic_order_present_flag = -1;
redundant_pic_cnt_present_flag = 0;
@@ -758,7 +759,7 @@ bool H264Parser::decode_Header(GetBitContext *gb)
*/
void H264Parser::decode_SPS(GetBitContext * gb)
{
int profile_idc, chroma_format_idc;
int profile_idc;
seen_sps = true;
@@ -1340,3 +1341,27 @@ uint H264Parser::aspectRatio(void) const
return aspect * 1000000;
}
// Following the lead of libavcodec, ignore the left cropping.
uint H264Parser::pictureWidthCropped(void) const
{
uint ChromaArrayType = separate_colour_plane_flag ? 0 : chroma_format_idc;
uint CropUnitX = 1;
uint SubWidthC = chroma_format_idc == 3 ? 1 : 2;
if (ChromaArrayType != 0)
CropUnitX = SubWidthC;
uint crop = CropUnitX * frame_crop_right_offset;
return pic_width - crop;
}
// Following the lead of libavcodec, ignore the top cropping.
uint H264Parser::pictureHeightCropped(void) const
{
uint ChromaArrayType = separate_colour_plane_flag ? 0 : chroma_format_idc;
uint CropUnitY = 2 - frame_mbs_only_flag;
uint SubHeightC = chroma_format_idc <= 1 ? 2 : 1;
if (ChromaArrayType != 0)
CropUnitY *= SubHeightC;
uint crop = CropUnitY * frame_crop_bottom_offset;
return pic_height - crop;
}
@@ -136,6 +136,8 @@ class H264Parser {
uint pictureWidth(void) const { return pic_width; }
uint pictureHeight(void) const { return pic_height; }
uint pictureWidthCropped(void) const;
uint pictureHeightCropped(void) const;
/** \brief Computes aspect ratio from picture size and sample aspect ratio
*/
@@ -229,6 +231,7 @@ class H264Parser {
int8_t frame_mbs_only_flag;
int8_t pic_order_present_flag;
int8_t redundant_pic_cnt_present_flag;
int8_t chroma_format_idc;
uint num_ref_frames;
uint redundant_pic_cnt;

0 comments on commit cc7d774

Please sign in to comment.