Skip to content

Commit

Permalink
Merge commit '31d2039cb42668ebcf08248bc48bbad44aa05f49'
Browse files Browse the repository at this point in the history
* commit '31d2039cb42668ebcf08248bc48bbad44aa05f49':
  h264_parser: export video format and dimensions

Conflicts:
	libavcodec/h264_parser.c
	libavcodec/version.h

Merged-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed Feb 19, 2015
2 parents e375511 + 31d2039 commit 560eb71
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/APIchanges
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ libavutil: 2014-08-09

API changes, most recent first:

2015-xx-xx - xxxxxxx - lavc 56.13
Add width, height, coded_width, coded_height and format to
AVCodecParserContext.

2015-xx-xx - xxxxxxx - lavu 54.9.0
Add AV_PIX_FMT_QSV for QSV hardware acceleration.

Expand Down
22 changes: 22 additions & 0 deletions libavcodec/avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4381,6 +4381,28 @@ typedef struct AVCodecParserContext {
* For example, this corresponds to H.264 PicOrderCnt.
*/
int output_picture_number;

/**
* Dimensions of the decoded video intended for presentation.
*/
int width;
int height;

/**
* Dimensions of the coded video.
*/
int coded_width;
int coded_height;

/**
* The format of the coded data, corresponds to enum AVPixelFormat for video
* and for enum AVSampleFormat for audio.
*
* Note that a decoder can have considerable freedom in how exactly it
* decodes the data, so the format reported here might be different from the
* one returned by a decoder.
*/
int format;
} AVCodecParserContext;

typedef struct AVCodecParser {
Expand Down
29 changes: 29 additions & 0 deletions libavcodec/h264_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,35 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if(h->sps.ref_frame_count <= 1 && h->pps.ref_count[0] <= 1 && s->pict_type == AV_PICTURE_TYPE_I)
s->key_frame = 1;

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;

Expand Down
2 changes: 2 additions & 0 deletions libavcodec/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ AVCodecParserContext *av_parser_init(int codec_id)
s->dts_sync_point = INT_MIN;
s->dts_ref_dts_delta = INT_MIN;
s->pts_dts_delta = INT_MIN;
s->format = -1;

return s;

err_out:
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "libavutil/version.h"

#define LIBAVCODEC_VERSION_MAJOR 56
#define LIBAVCODEC_VERSION_MINOR 22
#define LIBAVCODEC_VERSION_MINOR 23
#define LIBAVCODEC_VERSION_MICRO 100

#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
Expand Down

0 comments on commit 560eb71

Please sign in to comment.