History

h264_parser: export video format and dimensions

Anton Khirnov committed 11 years ago

Commit 31d20391 parent 5b1d9ce5 files · +58 −1Browse files

Unified · Split

5 files
  1. doc/APIchanges +4 −0
  2. libavcodec/avcodec.h +22 −0
  3. libavcodec/h264_parser.c +29 −0
  4. libavcodec/parser.c +2 −0
  5. libavcodec/version.h +1 −1
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2014-08-09 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2015-xx-xx - xxxxxxx - lavc 56.13
17+ Add width, height, coded_width, coded_height and format to
18+ AVCodecParserContext.
19+
1620 2015-xx-xx - xxxxxxx - lavu 54.9.0
1721 Add AV_PIX_FMT_QSV for QSV hardware acceleration.
1822
libavcodec/avcodec.h+22−0
@@ -3883,6 +3883,28 @@ typedef struct AVCodecParserContext { · 3882 unmodified lines
38833883 * For example, this corresponds to H.264 PicOrderCnt.
38843884 */
38853885 int output_picture_number;
3886+
3887+ /**
3888+ * Dimensions of the decoded video intended for presentation.
3889+ */
3890+ int width;
3891+ int height;
3892+
3893+ /**
3894+ * Dimensions of the coded video.
3895+ */
3896+ int coded_width;
3897+ int coded_height;
3898+
3899+ /**
3900+ * The format of the coded data, corresponds to enum AVPixelFormat for video
3901+ * and for enum AVSampleFormat for audio.
3902+ *
3903+ * Note that a decoder can have considerable freedom in how exactly it
3904+ * decodes the data, so the format reported here might be different from the
3905+ * one returned by a decoder.
3906+ */
3907+ int format;
38863908 } AVCodecParserContext;
38873909
38883910 typedef struct AVCodecParser {
libavcodec/h264_parser.c+29−0
@@ -275,6 +275,35 @@ static inline int parse_nal_units(AVCodecParserContext *s, · 274 unmodified lines
275275 h->sps = *h->sps_buffers[h->pps.sps_id];
276276 h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);
277277
278+ s->coded_width = 16 * h->sps.mb_width;
279+ s->coded_height = 16 * h->sps.mb_height;
280+ s->width = s->coded_width - (h->sps.crop_right + h->sps.crop_left);
281+ s->height = s->coded_height - (h->sps.crop_top + h->sps.crop_bottom);
282+ if (s->width <= 0 || s->height <= 0) {
283+ s->width = s->coded_width;
284+ s->height = s->coded_height;
285+ }
286+
287+ switch (h->sps.bit_depth_luma) {
288+ case 9:
289+ if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P9;
290+ else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P9;
291+ else s->format = AV_PIX_FMT_YUV420P9;
292+ break;
293+ case 10:
294+ if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P10;
295+ else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P10;
296+ else s->format = AV_PIX_FMT_YUV420P10;
297+ break;
298+ case 8:
299+ if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P;
300+ else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P;
301+ else s->format = AV_PIX_FMT_YUV420P;
302+ break;
303+ default:
304+ s->format = AV_PIX_FMT_NONE;
305+ }
306+
278307 avctx->profile = ff_h264_get_profile(&h->sps);
279308 avctx->level = h->sps.level_idc;
280309
libavcodec/parser.c+2−0
@@ -89,6 +89,8 @@ found: · 88 unmodified lines
8989 s->dts_sync_point = INT_MIN;
9090 s->dts_ref_dts_delta = INT_MIN;
9191 s->pts_dts_delta = INT_MIN;
92+ s->format = -1;
93+
9294 return s;
9395 }
9496
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/version.h"
3030
3131 #define LIBAVCODEC_VERSION_MAJOR 56
32−#define LIBAVCODEC_VERSION_MINOR 12
32+#define LIBAVCODEC_VERSION_MINOR 13
3333 #define LIBAVCODEC_VERSION_MICRO 0
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t