]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vp9_parser.c
vp9: assign PTS to visible instead of invisible frames
[ffmpeg] / libavcodec / vp9_parser.c
index 922f36f3811baf0bfae97eeb4c4013ddff24ba83..220290fbf1ec135dd5afc9defddadae7df6dafbb 100644 (file)
 typedef struct VP9ParseContext {
     int n_frames; // 1-8
     int size[8];
+    int64_t pts;
 } VP9ParseContext;
 
 static void parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size)
 {
+    VP9ParseContext *s = ctx->priv_data;
+
     if (buf[0] & 0x4) {
         ctx->pict_type = AV_PICTURE_TYPE_P;
         ctx->key_frame = 0;
@@ -35,6 +38,15 @@ static void parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size)
         ctx->pict_type = AV_PICTURE_TYPE_I;
         ctx->key_frame = 1;
     }
+
+    if (buf[0] & 0x2) {
+        if (ctx->pts == AV_NOPTS_VALUE)
+            ctx->pts = s->pts;
+        s->pts = AV_NOPTS_VALUE;
+    } else {
+        s->pts = ctx->pts;
+        ctx->pts = AV_NOPTS_VALUE;
+    }
 }
 
 static int parse(AVCodecParserContext *ctx,
@@ -43,6 +55,7 @@ static int parse(AVCodecParserContext *ctx,
                  const uint8_t *data, int size)
 {
     VP9ParseContext *s = ctx->priv_data;
+    int full_size = size;
     int marker;
 
     if (size <= 0) {
@@ -77,12 +90,12 @@ static int parse(AVCodecParserContext *ctx,
                     idx += a; \
                     if (sz > size) { \
                         s->n_frames = 0; \
-                        *out_size = 0; \
+                        *out_size = size; \
                         *out_data = data; \
                         av_log(avctx, AV_LOG_ERROR, \
                                "Superframe packet size too big: %u > %d\n", \
                                sz, size); \
-                        return size; \
+                        return full_size; \
                     } \
                     if (first) { \
                         first = 0; \