From 31d2039cb42668ebcf08248bc48bbad44aa05f49 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 9 Feb 2015 14:41:50 +0100 Subject: h264_parser: export video format and dimensions --- libavcodec/h264_parser.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libavcodec/h264_parser.c') diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 693af00309..21e320d752 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -275,6 +275,35 @@ static inline int parse_nal_units(AVCodecParserContext *s, h->sps = *h->sps_buffers[h->pps.sps_id]; h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num); + s->coded_width = 16 * h->sps.mb_width; + s->coded_height = 16 * h->sps.mb_height; + s->width = s->coded_width - (h->sps.crop_right + h->sps.crop_left); + s->height = s->coded_height - (h->sps.crop_top + h->sps.crop_bottom); + if (s->width <= 0 || s->height <= 0) { + s->width = s->coded_width; + s->height = s->coded_height; + } + + switch (h->sps.bit_depth_luma) { + case 9: + if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P9; + else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P9; + else s->format = AV_PIX_FMT_YUV420P9; + break; + case 10: + if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P10; + else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P10; + else s->format = AV_PIX_FMT_YUV420P10; + break; + case 8: + if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P; + else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P; + else s->format = AV_PIX_FMT_YUV420P; + break; + default: + s->format = AV_PIX_FMT_NONE; + } + avctx->profile = ff_h264_get_profile(&h->sps); avctx->level = h->sps.level_idc; -- cgit v1.2.3