diff mbox series

[FFmpeg-devel,v6,2/3] API: add AV_PKT_DATA_S12M_TIMECODE to AVPacketSideDataType

Message ID 1593610798-21093-2-git-send-email-lance.lmwang@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v6,1/3] avutil/timecode: add description for SMPTE binary format | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Lance Wang July 1, 2020, 1:39 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 doc/APIchanges        |  3 +++
 libavcodec/avpacket.c |  1 +
 libavcodec/decode.c   |  1 +
 libavcodec/packet.h   |  8 ++++++++
 libavcodec/version.h  |  2 +-
 libavformat/dump.c    | 21 +++++++++++++++++++++
 6 files changed, 35 insertions(+), 1 deletion(-)

Comments

Devin Heitmueller July 9, 2020, 11:16 p.m. UTC | #1
Given the questions regarding the format used for the timecodes, this
patch from my personal repo might help:

commit e4c9ae661fb55e59eff1461140a8cd039b7c3f04
Author: Devin Heitmueller <dheitmueller@ltnglobal.com>
Date:   Thu Jul 5 17:18:36 2018 -0400
    Clarify where the binary representation comes from for ffmpeg's SMPTE struct

    There are a number of different binary representations in which
    SMPTE timecodes can use.  Make clear that the specific representation
    that ffmpeg refers to corresponds to the DV video spec, which is
    SMPTE S314M:2005 for standard definition video and ST 370-2013 for
    high definition video.

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index e9d8504ee7..93bba2af31 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -117,6 +117,7 @@ static unsigned bcd2uint(uint8_t bcd)

 char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte,
int prevent_df)
 {
+    /* See SMPTE ST 314M-2005 Sec 4.4.2.2.1 "Time code pack (TC)" */
     unsigned hh   = bcd2uint(tcsmpte     & 0x3f);    // 6-bit hours
     unsigned mm   = bcd2uint(tcsmpte>>8  & 0x7f);    // 7-bit minutes
     unsigned ss   = bcd2uint(tcsmpte>>16 & 0x7f);    // 7-bit seconds


On Wed, Jul 1, 2020 at 9:40 AM <lance.lmwang@gmail.com> wrote:
>
> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  doc/APIchanges        |  3 +++
>  libavcodec/avpacket.c |  1 +
>  libavcodec/decode.c   |  1 +
>  libavcodec/packet.h   |  8 ++++++++
>  libavcodec/version.h  |  2 +-
>  libavformat/dump.c    | 21 +++++++++++++++++++++
>  6 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 1d6cc36..7aa8d9e 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2017-10-21
>
>  API changes, most recent first:
>
> +2020-06-xx - xxxxxxxxxx - lavc 58.94.101 - packet.h
> +  Add AV_PKT_DATA_S12M_TIMECODE.
> +
>  2020-06-12 - b09fb030c1 - lavu 56.55.100 - pixdesc.h
>    Add AV_PIX_FMT_X2RGB10.
>
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index dce26cb..4801163 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -400,6 +400,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type)
>      case AV_PKT_DATA_PRFT:                       return "Producer Reference Time";
>      case AV_PKT_DATA_ICC_PROFILE:                return "ICC Profile";
>      case AV_PKT_DATA_DOVI_CONF:                  return "DOVI configuration record";
> +    case AV_PKT_DATA_S12M_TIMECODE:              return "SMPTE ST 12-1:2014 timecode";
>      }
>      return NULL;
>  }
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index de9c079..f2244fc 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -1699,6 +1699,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
>          { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,        AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
>          { AV_PKT_DATA_A53_CC,                     AV_FRAME_DATA_A53_CC },
>          { AV_PKT_DATA_ICC_PROFILE,                AV_FRAME_DATA_ICC_PROFILE },
> +        { AV_PKT_DATA_S12M_TIMECODE,              AV_FRAME_DATA_S12M_TIMECODE },
>      };
>
>      if (pkt) {
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index 96f237f..0a19a0e 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -283,6 +283,14 @@ enum AVPacketSideDataType {
>      AV_PKT_DATA_DOVI_CONF,
>
>      /**
> +     * Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t
> +     * where the first uint32_t describes how many (1-3) of the other timecodes are used.
> +     * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
> +     * function in libavutil/timecode.h.
> +     */
> +    AV_PKT_DATA_S12M_TIMECODE,
> +
> +    /**
>       * The number of side data types.
>       * This is not part of the public API/ABI in the sense that it may
>       * change when new side data types are added.
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 05f5990..51fba22 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -28,7 +28,7 @@
>  #include "libavutil/version.h"
>
>  #define LIBAVCODEC_VERSION_MAJOR  58
> -#define LIBAVCODEC_VERSION_MINOR  93
> +#define LIBAVCODEC_VERSION_MINOR  94
>  #define LIBAVCODEC_VERSION_MICRO 101
>
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> diff --git a/libavformat/dump.c b/libavformat/dump.c
> index 1083d7d..46db039 100644
> --- a/libavformat/dump.c
> +++ b/libavformat/dump.c
> @@ -34,6 +34,7 @@
>  #include "libavutil/replaygain.h"
>  #include "libavutil/spherical.h"
>  #include "libavutil/stereo3d.h"
> +#include "libavutil/timecode.h"
>
>  #include "avformat.h"
>
> @@ -407,6 +408,22 @@ static void dump_dovi_conf(void *ctx, const AVPacketSideData *sd)
>             dovi->dv_bl_signal_compatibility_id);
>  }
>
> +static void dump_s12m_timecode(void *ctx, const AVPacketSideData *sd)
> +{
> +    const uint32_t *tc = (const uint32_t *)sd->data;
> +
> +    if ((sd->size != sizeof(uint32_t) * 4) || (tc[0] > 3)) {
> +        av_log(ctx, AV_LOG_ERROR, "invalid data\n");
> +        return;
> +    }
> +
> +    for (int j = 1; j <= tc[0]; j++) {
> +        char tcbuf[AV_TIMECODE_STR_SIZE];
> +        av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0);
> +        av_log(ctx, AV_LOG_INFO, "timecode - %s%s", tcbuf, j != tc[0] ? ", " : "");
> +    }
> +}
> +
>  static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
>  {
>      int i;
> @@ -473,6 +490,10 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
>              av_log(ctx, AV_LOG_INFO, "DOVI configuration record: ");
>              dump_dovi_conf(ctx, sd);
>              break;
> +        case AV_PKT_DATA_S12M_TIMECODE:
> +            av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: ");
> +            dump_s12m_timecode(ctx, sd);
> +            break;
>          default:
>              av_log(ctx, AV_LOG_INFO,
>                     "unknown side data type %d (%d bytes)", sd->type, sd->size);
> --
> 1.8.3.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Lance Wang July 10, 2020, 1:39 a.m. UTC | #2
On Thu, Jul 09, 2020 at 07:16:28PM -0400, Devin Heitmueller wrote:
> Given the questions regarding the format used for the timecodes, this
> patch from my personal repo might help:
> 
> commit e4c9ae661fb55e59eff1461140a8cd039b7c3f04
> Author: Devin Heitmueller <dheitmueller@ltnglobal.com>
> Date:   Thu Jul 5 17:18:36 2018 -0400
>     Clarify where the binary representation comes from for ffmpeg's SMPTE struct
> 
>     There are a number of different binary representations in which
>     SMPTE timecodes can use.  Make clear that the specific representation
>     that ffmpeg refers to corresponds to the DV video spec, which is
>     SMPTE S314M:2005 for standard definition video and ST 370-2013 for
>     high definition video.
> 
> diff --git a/libavutil/timecode.c b/libavutil/timecode.c
> index e9d8504ee7..93bba2af31 100644
> --- a/libavutil/timecode.c
> +++ b/libavutil/timecode.c
> @@ -117,6 +117,7 @@ static unsigned bcd2uint(uint8_t bcd)
> 
>  char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte,
> int prevent_df)
>  {
> +    /* See SMPTE ST 314M-2005 Sec 4.4.2.2.1 "Time code pack (TC)" */

Thanks for the clarify, I'll merge this comment for reference, but it seems
that it's not free, so I'll keep the detail format document without any change.


>      unsigned hh   = bcd2uint(tcsmpte     & 0x3f);    // 6-bit hours
>      unsigned mm   = bcd2uint(tcsmpte>>8  & 0x7f);    // 7-bit minutes
>      unsigned ss   = bcd2uint(tcsmpte>>16 & 0x7f);    // 7-bit seconds
> 
> 
> On Wed, Jul 1, 2020 at 9:40 AM <lance.lmwang@gmail.com> wrote:
> >
> > From: Limin Wang <lance.lmwang@gmail.com>
> >
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  doc/APIchanges        |  3 +++
> >  libavcodec/avpacket.c |  1 +
> >  libavcodec/decode.c   |  1 +
> >  libavcodec/packet.h   |  8 ++++++++
> >  libavcodec/version.h  |  2 +-
> >  libavformat/dump.c    | 21 +++++++++++++++++++++
> >  6 files changed, 35 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 1d6cc36..7aa8d9e 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -15,6 +15,9 @@ libavutil:     2017-10-21
> >
> >  API changes, most recent first:
> >
> > +2020-06-xx - xxxxxxxxxx - lavc 58.94.101 - packet.h
> > +  Add AV_PKT_DATA_S12M_TIMECODE.
> > +
> >  2020-06-12 - b09fb030c1 - lavu 56.55.100 - pixdesc.h
> >    Add AV_PIX_FMT_X2RGB10.
> >
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index dce26cb..4801163 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -400,6 +400,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type)
> >      case AV_PKT_DATA_PRFT:                       return "Producer Reference Time";
> >      case AV_PKT_DATA_ICC_PROFILE:                return "ICC Profile";
> >      case AV_PKT_DATA_DOVI_CONF:                  return "DOVI configuration record";
> > +    case AV_PKT_DATA_S12M_TIMECODE:              return "SMPTE ST 12-1:2014 timecode";
> >      }
> >      return NULL;
> >  }
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index de9c079..f2244fc 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1699,6 +1699,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
> >          { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,        AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> >          { AV_PKT_DATA_A53_CC,                     AV_FRAME_DATA_A53_CC },
> >          { AV_PKT_DATA_ICC_PROFILE,                AV_FRAME_DATA_ICC_PROFILE },
> > +        { AV_PKT_DATA_S12M_TIMECODE,              AV_FRAME_DATA_S12M_TIMECODE },
> >      };
> >
> >      if (pkt) {
> > diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> > index 96f237f..0a19a0e 100644
> > --- a/libavcodec/packet.h
> > +++ b/libavcodec/packet.h
> > @@ -283,6 +283,14 @@ enum AVPacketSideDataType {
> >      AV_PKT_DATA_DOVI_CONF,
> >
> >      /**
> > +     * Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t
> > +     * where the first uint32_t describes how many (1-3) of the other timecodes are used.
> > +     * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
> > +     * function in libavutil/timecode.h.
> > +     */
> > +    AV_PKT_DATA_S12M_TIMECODE,
> > +
> > +    /**
> >       * The number of side data types.
> >       * This is not part of the public API/ABI in the sense that it may
> >       * change when new side data types are added.
> > diff --git a/libavcodec/version.h b/libavcodec/version.h
> > index 05f5990..51fba22 100644
> > --- a/libavcodec/version.h
> > +++ b/libavcodec/version.h
> > @@ -28,7 +28,7 @@
> >  #include "libavutil/version.h"
> >
> >  #define LIBAVCODEC_VERSION_MAJOR  58
> > -#define LIBAVCODEC_VERSION_MINOR  93
> > +#define LIBAVCODEC_VERSION_MINOR  94
> >  #define LIBAVCODEC_VERSION_MICRO 101
> >
> >  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> > diff --git a/libavformat/dump.c b/libavformat/dump.c
> > index 1083d7d..46db039 100644
> > --- a/libavformat/dump.c
> > +++ b/libavformat/dump.c
> > @@ -34,6 +34,7 @@
> >  #include "libavutil/replaygain.h"
> >  #include "libavutil/spherical.h"
> >  #include "libavutil/stereo3d.h"
> > +#include "libavutil/timecode.h"
> >
> >  #include "avformat.h"
> >
> > @@ -407,6 +408,22 @@ static void dump_dovi_conf(void *ctx, const AVPacketSideData *sd)
> >             dovi->dv_bl_signal_compatibility_id);
> >  }
> >
> > +static void dump_s12m_timecode(void *ctx, const AVPacketSideData *sd)
> > +{
> > +    const uint32_t *tc = (const uint32_t *)sd->data;
> > +
> > +    if ((sd->size != sizeof(uint32_t) * 4) || (tc[0] > 3)) {
> > +        av_log(ctx, AV_LOG_ERROR, "invalid data\n");
> > +        return;
> > +    }
> > +
> > +    for (int j = 1; j <= tc[0]; j++) {
> > +        char tcbuf[AV_TIMECODE_STR_SIZE];
> > +        av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0);
> > +        av_log(ctx, AV_LOG_INFO, "timecode - %s%s", tcbuf, j != tc[0] ? ", " : "");
> > +    }
> > +}
> > +
> >  static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
> >  {
> >      int i;
> > @@ -473,6 +490,10 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
> >              av_log(ctx, AV_LOG_INFO, "DOVI configuration record: ");
> >              dump_dovi_conf(ctx, sd);
> >              break;
> > +        case AV_PKT_DATA_S12M_TIMECODE:
> > +            av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: ");
> > +            dump_s12m_timecode(ctx, sd);
> > +            break;
> >          default:
> >              av_log(ctx, AV_LOG_INFO,
> >                     "unknown side data type %d (%d bytes)", sd->type, sd->size);
> > --
> > 1.8.3.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 
> 
> 
> -- 
> Devin Heitmueller, Senior Software Engineer
> LTN Global Communications
> o: +1 (301) 363-1001
> w: https://ltnglobal.com  e: devin.heitmueller@ltnglobal.com
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 1d6cc36..7aa8d9e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@  libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-06-xx - xxxxxxxxxx - lavc 58.94.101 - packet.h
+  Add AV_PKT_DATA_S12M_TIMECODE.
+
 2020-06-12 - b09fb030c1 - lavu 56.55.100 - pixdesc.h
   Add AV_PIX_FMT_X2RGB10.
 
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index dce26cb..4801163 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -400,6 +400,7 @@  const char *av_packet_side_data_name(enum AVPacketSideDataType type)
     case AV_PKT_DATA_PRFT:                       return "Producer Reference Time";
     case AV_PKT_DATA_ICC_PROFILE:                return "ICC Profile";
     case AV_PKT_DATA_DOVI_CONF:                  return "DOVI configuration record";
+    case AV_PKT_DATA_S12M_TIMECODE:              return "SMPTE ST 12-1:2014 timecode";
     }
     return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index de9c079..f2244fc 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1699,6 +1699,7 @@  int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
         { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,        AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
         { AV_PKT_DATA_A53_CC,                     AV_FRAME_DATA_A53_CC },
         { AV_PKT_DATA_ICC_PROFILE,                AV_FRAME_DATA_ICC_PROFILE },
+        { AV_PKT_DATA_S12M_TIMECODE,              AV_FRAME_DATA_S12M_TIMECODE },
     };
 
     if (pkt) {
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 96f237f..0a19a0e 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -283,6 +283,14 @@  enum AVPacketSideDataType {
     AV_PKT_DATA_DOVI_CONF,
 
     /**
+     * Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t
+     * where the first uint32_t describes how many (1-3) of the other timecodes are used.
+     * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
+     * function in libavutil/timecode.h.
+     */
+    AV_PKT_DATA_S12M_TIMECODE,
+
+    /**
      * The number of side data types.
      * This is not part of the public API/ABI in the sense that it may
      * change when new side data types are added.
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 05f5990..51fba22 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@ 
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  93
+#define LIBAVCODEC_VERSION_MINOR  94
 #define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 1083d7d..46db039 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -34,6 +34,7 @@ 
 #include "libavutil/replaygain.h"
 #include "libavutil/spherical.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/timecode.h"
 
 #include "avformat.h"
 
@@ -407,6 +408,22 @@  static void dump_dovi_conf(void *ctx, const AVPacketSideData *sd)
            dovi->dv_bl_signal_compatibility_id);
 }
 
+static void dump_s12m_timecode(void *ctx, const AVPacketSideData *sd)
+{
+    const uint32_t *tc = (const uint32_t *)sd->data;
+
+    if ((sd->size != sizeof(uint32_t) * 4) || (tc[0] > 3)) {
+        av_log(ctx, AV_LOG_ERROR, "invalid data\n");
+        return;
+    }
+
+    for (int j = 1; j <= tc[0]; j++) {
+        char tcbuf[AV_TIMECODE_STR_SIZE];
+        av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0);
+        av_log(ctx, AV_LOG_INFO, "timecode - %s%s", tcbuf, j != tc[0] ? ", " : "");
+    }
+}
+
 static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
 {
     int i;
@@ -473,6 +490,10 @@  static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
             av_log(ctx, AV_LOG_INFO, "DOVI configuration record: ");
             dump_dovi_conf(ctx, sd);
             break;
+        case AV_PKT_DATA_S12M_TIMECODE:
+            av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: ");
+            dump_s12m_timecode(ctx, sd);
+            break;
         default:
             av_log(ctx, AV_LOG_INFO,
                    "unknown side data type %d (%d bytes)", sd->type, sd->size);