Browse code

h264_parser: export video format and dimensions

Anton Khirnov authored on 2015/02/09 22:41:50
Showing 5 changed files
... ...
@@ -13,6 +13,10 @@ libavutil:     2014-08-09
13 13
 
14 14
 API changes, most recent first:
15 15
 
16
+2015-xx-xx - xxxxxxx - lavc 56.13
17
+  Add width, height, coded_width, coded_height and format to
18
+  AVCodecParserContext.
19
+
16 20
 2015-xx-xx - xxxxxxx - lavu 54.9.0
17 21
   Add AV_PIX_FMT_QSV for QSV hardware acceleration.
18 22
 
... ...
@@ -3883,6 +3883,28 @@ typedef struct AVCodecParserContext {
3883 3883
      * For example, this corresponds to H.264 PicOrderCnt.
3884 3884
      */
3885 3885
     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;
3886 3908
 } AVCodecParserContext;
3887 3909
 
3888 3910
 typedef struct AVCodecParser {
... ...
@@ -275,6 +275,35 @@ static inline int parse_nal_units(AVCodecParserContext *s,
275 275
             h->sps       = *h->sps_buffers[h->pps.sps_id];
276 276
             h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);
277 277
 
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
+
278 307
             avctx->profile = ff_h264_get_profile(&h->sps);
279 308
             avctx->level   = h->sps.level_idc;
280 309
 
... ...
@@ -89,6 +89,8 @@ found:
89 89
     s->dts_sync_point       = INT_MIN;
90 90
     s->dts_ref_dts_delta    = INT_MIN;
91 91
     s->pts_dts_delta        = INT_MIN;
92
+    s->format               = -1;
93
+
92 94
     return s;
93 95
 }
94 96
 
... ...
@@ -29,7 +29,7 @@
29 29
 #include "libavutil/version.h"
30 30
 
31 31
 #define LIBAVCODEC_VERSION_MAJOR 56
32
-#define LIBAVCODEC_VERSION_MINOR 12
32
+#define LIBAVCODEC_VERSION_MINOR 13
33 33
 #define LIBAVCODEC_VERSION_MICRO  0
34 34
 
35 35
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \