[FFmpeg-devel] [PATCH 2/2] mpeg12dec: Export GOP timecodes as side data

Derek Buitenhuis derek.buitenhuis at gmail.com
Sun Jan 31 14:13:42 CET 2016


The codec context field was rightly deprecated, and the data
may change per-frame.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
 ffprobe.c              |  8 --------
 libavcodec/mpeg12dec.c | 19 ++++++++++++++++---
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index c352b44..019863a 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -2226,14 +2226,6 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id
                 print_str("chroma_location", av_chroma_location_name(dec_ctx->chroma_sample_location));
             else
                 print_str_opt("chroma_location", av_chroma_location_name(dec_ctx->chroma_sample_location));
-
-            if (dec_ctx->timecode_frame_start >= 0) {
-                char tcbuf[AV_TIMECODE_STR_SIZE];
-                av_timecode_make_mpeg_tc_string(tcbuf, dec_ctx->timecode_frame_start);
-                print_str("timecode", tcbuf);
-            } else {
-                print_str_opt("timecode", "N/A");
-            }
             print_int("refs", dec_ctx->refs);
             break;
 
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 23c77cd..56a87a4 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2413,17 +2413,25 @@ FF_ENABLE_DEPRECATION_WARNINGS
     }
 }
 
-static void mpeg_decode_gop(AVCodecContext *avctx,
+static int mpeg_decode_gop(AVCodecContext *avctx,
                             const uint8_t *buf, int buf_size)
 {
     Mpeg1Context *s1  = avctx->priv_data;
     MpegEncContext *s = &s1->mpeg_enc_ctx;
+    AVFrameSideData *tcside;
     int broken_link;
     int64_t tc;
 
+    tcside = av_frame_new_side_data(s->current_picture_ptr->f,
+                                    AV_FRAME_DATA_GOP_TIMECODE, sizeof(int64_t));
+    if (!tcside)
+        return AVERROR(ENOMEM);
+
     init_get_bits(&s->gb, buf, buf_size * 8);
 
-    tc = avctx->timecode_frame_start = get_bits(&s->gb, 25);
+    tc = get_bits(&s->gb, 25);
+
+    memcpy(tcside->data, &tc, sizeof(int64_t));
 
     s->closed_gop = get_bits1(&s->gb);
     /* broken_link indicate that after editing the
@@ -2438,6 +2446,8 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
                "GOP (%s) closed_gop=%d broken_link=%d\n",
                tcbuf, s->closed_gop, broken_link);
     }
+
+    return 0;
 }
 
 static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
@@ -2604,8 +2614,11 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
             break;
         case GOP_START_CODE:
             if (last_code == 0) {
+                int gopret;
                 s2->first_field = 0;
-                mpeg_decode_gop(avctx, buf_ptr, input_size);
+                gopret = mpeg_decode_gop(avctx, buf_ptr, input_size);
+                if (gopret < 0)
+                    return gopret;
                 s->sync = 1;
             } else {
                 av_log(avctx, AV_LOG_ERROR,
-- 
2.7.0



More information about the ffmpeg-devel mailing list