[FFmpeg-devel] [PATCH 1/2] mpeg12: raise timecode string to codec context.

Clément Bœsch ubitux at gmail.com
Tue Nov 22 18:01:10 CET 2011


On Wed, Nov 16, 2011 at 06:07:50PM +0100, Michael Niedermayer wrote:
> On Wed, Nov 16, 2011 at 05:52:33PM +0100, Clément Bœsch wrote:
> > From: Clément Bœsch <clement.boesch at smartjog.com>
> > 
> > ---
> >  doc/APIchanges       |    3 +++
> >  libavcodec/avcodec.h |    7 +++++++
> >  libavcodec/mpeg12.c  |   10 ++++++----
> >  libavcodec/version.h |    2 +-
> >  4 files changed, 17 insertions(+), 5 deletions(-)
> > 
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 8a2a9de..cc72063 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -13,6 +13,9 @@ libavutil:   2011-04-18
> >  
> >  API changes, most recent first:
> >  
> > +2011-11-xx - xxxxxxx - lavc 53.35.0
> > +  Add timecode string (timecode_str) to AVCodecContext.
> > +
> >  2011-11-03 - 96949da - lavu 51.23.0
> >    Add av_strcasecmp() and av_strncasecmp() to avstring.h.
> >  
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index d62cbfb..88ebbad 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -2679,6 +2679,13 @@ typedef struct AVCodecContext {
> >       */
> >      int64_t timecode_frame_start;
> >  
> > +    /**
> > +     * Codec timecode string
> > +     * - encoding: unused
> > +     * - decoding: set by libavcodec
> > +     */
> > +    char timecode_str[16];
> > +
> >  #if FF_API_REQUEST_CHANNELS
> 
> adding it in the middle can cause ABI issues
> also a note saying that it should only be accessed via av_opt*
> would avoid ABI issues if it moves
> char [16] might not work well with av_opt though
> 

Here is another way (with just a micro bump) of solving that issue: I used
the timecode_frame_start to store the 25-bit value from the GOP header
since it is ATM only used for encoding.

Maybe the timecode code could be exported so we can add a helper in order
to get the string representation.

About using av_opt* functions instead, it is not an easy solution: adding
a user RO field in the options doesn't work for probing since the context
is reset (avformat_find_stream_info → avcodec_close → av_opt_free) and
thus the field is freed and set to NULL. Because of that issue, having it
in ffprobe is compromised.

Here is a way to test the attached patch:
  ./ffmpeg -debug 1 -i foo.mpg -f null -|& grep GOP

The second patch (for ffprobe) will be sent in a moment.

-- 
Clément B.
-------------- next part --------------
From 4fff640feda72baed7426eceaab8cc36f4ae9ecb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
Date: Wed, 16 Nov 2011 17:40:00 +0100
Subject: [PATCH 1/2] mpeg12: raise timecode to codec context.

---
 libavcodec/avcodec.h |    2 +-
 libavcodec/mpeg12.c  |   20 +++++++++-----------
 libavcodec/version.h |    2 +-
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index dfd396c..b1c0be2 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2681,7 +2681,7 @@ typedef struct AVCodecContext {
     /**
      * GOP timecode frame start number, in non drop frame format
      * - encoding: Set by user.
-     * - decoding: unused
+     * - decoding: Set by libavcodec (timecode in the 25 bits format)
      */
     int64_t timecode_frame_start;
 
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 5385748..fde4e02 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -2141,20 +2141,12 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
 {
     Mpeg1Context *s1  = avctx->priv_data;
     MpegEncContext *s = &s1->mpeg_enc_ctx;
-
-    int drop_frame_flag;
-    int time_code_hours, time_code_minutes;
-    int time_code_seconds, time_code_pictures;
     int broken_link;
+    int64_t tc;
 
     init_get_bits(&s->gb, buf, buf_size*8);
 
-    drop_frame_flag   = get_bits(&s->gb, 1);
-    time_code_hours   = get_bits(&s->gb, 5);
-    time_code_minutes = get_bits(&s->gb, 6);
-    skip_bits1(&s->gb); // marker bit
-    time_code_seconds  = get_bits(&s->gb, 6);
-    time_code_pictures = get_bits(&s->gb, 6);
+    tc = avctx->timecode_frame_start = get_bits(&s->gb, 25);
 
     s->closed_gop = get_bits1(&s->gb);
     /*broken_link indicate that after editing the
@@ -2162,11 +2154,17 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
       are missing (open gop)*/
     broken_link = get_bits1(&s->gb);
 
-    if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+    if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
+        int time_code_hours    = tc>>19 & 0x1f;
+        int time_code_minutes  = tc>>13 & 0x3f;
+        int time_code_seconds  = tc>>6  & 0x3f;
+        int drop_frame_flag    = tc     & 1<<24;
+        int time_code_pictures = tc     & 0x3f;
         av_log(s->avctx, AV_LOG_DEBUG, "GOP (%02d:%02d:%02d%c%02d) closed_gop=%d broken_link=%d\n",
                time_code_hours, time_code_minutes, time_code_seconds,
                drop_frame_flag ? ';' : ':',
                time_code_pictures, s->closed_gop, broken_link);
+    }
 }
 /**
  * Find the end of the current frame in the bitstream.
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a2d96a4..d9e2cea 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -22,7 +22,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR 53
 #define LIBAVCODEC_VERSION_MINOR 36
-#define LIBAVCODEC_VERSION_MICRO  0
+#define LIBAVCODEC_VERSION_MICRO  1
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
1.7.7.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111122/6d23e5dc/attachment.asc>


More information about the ffmpeg-devel mailing list