Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2 1/3] avutil/timecode: add ff_timecode_set_smpte
@ 2025-02-28 22:46 Timo Rothenpieler
  2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function Timo Rothenpieler
  2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 3/3] avcodec/nvenc: add time code writing for h264 Timo Rothenpieler
  0 siblings, 2 replies; 4+ messages in thread
From: Timo Rothenpieler @ 2025-02-28 22:46 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Timo Rothenpieler

---
 libavutil/timecode.c          | 27 +++----------------
 libavutil/timecode_internal.c | 51 +++++++++++++++++++++++++++++++++++
 libavutil/timecode_internal.h | 51 +++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 24 deletions(-)
 create mode 100644 libavutil/timecode_internal.c
 create mode 100644 libavutil/timecode_internal.h

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index f454466f97..bca16b6ac2 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include "common.h"
 #include "timecode.h"
+#include "timecode_internal.h"
 #include "log.h"
 #include "error.h"
 
@@ -127,32 +128,10 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum_arg)
     return buf;
 }
 
-static unsigned bcd2uint(uint8_t bcd)
-{
-   unsigned low  = bcd & 0xf;
-   unsigned high = bcd >> 4;
-   if (low > 9 || high > 9)
-       return 0;
-   return low + 10*high;
-}
-
 char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
 {
-    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
-    unsigned ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
-    unsigned drop = tcsmpte & 1<<30 && !prevent_df;  // 1-bit drop if not arbitrary bit
-
-    if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
-        ff <<= 1;
-        if (!skip_field) {
-            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
-                ff += !!(tcsmpte & 1 << 7);
-            else
-                ff += !!(tcsmpte & 1 << 23);
-        }
-    }
+    unsigned hh, mm, ss, ff, drop;
+    ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tcsmpte, prevent_df, skip_field);
 
     snprintf(buf, AV_TIMECODE_STR_SIZE, "%02u:%02u:%02u%c%02u",
              hh, mm, ss, drop ? ';' : ':', ff);
diff --git a/libavutil/timecode_internal.c b/libavutil/timecode_internal.c
new file mode 100644
index 0000000000..259ebf1664
--- /dev/null
+++ b/libavutil/timecode_internal.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
+ * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "timecode_internal.h"
+
+static unsigned bcd2uint(uint8_t bcd)
+{
+   unsigned low  = bcd & 0xf;
+   unsigned high = bcd >> 4;
+   if (low > 9 || high > 9)
+       return 0;
+   return low + 10*high;
+}
+
+void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff,
+                           AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
+{
+    *hh   = bcd2uint(tcsmpte     & 0x3f);    // 6-bit hours
+    *mm   = bcd2uint(tcsmpte>>8  & 0x7f);    // 7-bit minutes
+    *ss   = bcd2uint(tcsmpte>>16 & 0x7f);    // 7-bit seconds
+    *ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
+    *drop = tcsmpte & 1<<30 && !prevent_df;  // 1-bit drop if not arbitrary bit
+
+    if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
+        *ff <<= 1;
+        if (!skip_field) {
+            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
+                *ff += !!(tcsmpte & 1 << 7);
+            else
+                *ff += !!(tcsmpte & 1 << 23);
+        }
+    }
+}
diff --git a/libavutil/timecode_internal.h b/libavutil/timecode_internal.h
new file mode 100644
index 0000000000..8ef43d1f98
--- /dev/null
+++ b/libavutil/timecode_internal.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
+ * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Timecode helpers header
+ */
+
+#ifndef AVUTIL_TIMECODE_INTERNAL_H
+#define AVUTIL_TIMECODE_INTERNAL_H
+
+#include <stdint.h>
+#include "rational.h"
+
+/**
+ * Convert SMPTE 12M binary representation to sei info.
+ *
+ * @param drop       drop flag output
+ * @param hh         hour output
+ * @param mm         minute output
+ * @param ss         second output
+ * @param ff         frame number output
+ * @param rate       frame rate of the timecode
+ * @param tcsmpte    the 32-bit SMPTE timecode
+ * @param prevent_df prevent the use of a drop flag when it is known the DF bit
+ *                   is arbitrary
+ * @param skip_field prevent the use of a field flag when it is known the field
+ *                   bit is arbitrary (e.g. because it is used as PC flag)
+ */
+void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff,
+                           AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field);
+
+#endif /* AVUTIL_TIMECODE_INTERNAL_H */
-- 
2.45.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function
  2025-02-28 22:46 [FFmpeg-devel] [PATCH v2 1/3] avutil/timecode: add ff_timecode_set_smpte Timo Rothenpieler
@ 2025-02-28 22:46 ` Timo Rothenpieler
  2025-02-28 22:49   ` Timo Rothenpieler
  2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 3/3] avcodec/nvenc: add time code writing for h264 Timo Rothenpieler
  1 sibling, 1 reply; 4+ messages in thread
From: Timo Rothenpieler @ 2025-02-28 22:46 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Timo Rothenpieler

---
 libavcodec/Makefile            |  2 ++
 libavcodec/timecode_internal.c | 19 +++++++++++++++++++
 libavcodec/utils.c             | 29 +++--------------------------
 libavutil/Makefile             |  3 +++
 4 files changed, 27 insertions(+), 26 deletions(-)
 create mode 100644 libavcodec/timecode_internal.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 499f826635..e3ccbf1838 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -64,6 +64,8 @@ OBJS = ac3_parser.o                                                     \
        vorbis_parser.o                                                  \
        xiph.o                                                           \
 
+SHLIBOBJS = timecode_internal.o                                         \
+
 # subsystems
 include $(SRC_PATH)/libavcodec/aac/Makefile
 include $(SRC_PATH)/libavcodec/hevc/Makefile
diff --git a/libavcodec/timecode_internal.c b/libavcodec/timecode_internal.c
new file mode 100644
index 0000000000..8682bb1b2e
--- /dev/null
+++ b/libavcodec/timecode_internal.c
@@ -0,0 +1,19 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/timecode_internal.c"
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index dd846b4ae9..0aa5a6f55e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -33,6 +33,7 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/timecode_internal.h"
 #include "avcodec.h"
 #include "codec.h"
 #include "codec_desc.h"
@@ -968,15 +969,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size)
     return props;
 }
 
-static unsigned bcd2uint(uint8_t bcd)
-{
-    unsigned low  = bcd & 0xf;
-    unsigned high = bcd >> 4;
-    if (low > 9 || high > 9)
-        return 0;
-    return low + 10*high;
-}
-
 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
                      void **data, size_t *sei_size)
 {
@@ -1006,23 +998,8 @@ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_l
     put_bits(&pb, 2, m); // num_clock_ts
 
     for (int j = 1; j <= m; j++) {
-        uint32_t tcsmpte = tc[j];
-        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
-        unsigned ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
-        unsigned drop = tcsmpte & 1<<30 && !0;  // 1-bit drop if not arbitrary bit
-
-        /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
-        if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
-            unsigned pc;
-            ff *= 2;
-            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
-                pc = !!(tcsmpte & 1 << 7);
-            else
-                pc = !!(tcsmpte & 1 << 23);
-            ff = (ff + pc) & 0x7f;
-        }
+        unsigned hh, mm, ss, ff, drop;
+        ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tc[j], 0, 0);
 
         put_bits(&pb, 1, 1); // clock_timestamp_flag
         put_bits(&pb, 1, 1); // units_field_based_flag
diff --git a/libavutil/Makefile b/libavutil/Makefile
index b2b3b9c156..ad534a8acc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -180,6 +180,7 @@ OBJS = adler32.o                                                        \
        threadmessage.o                                                  \
        time.o                                                           \
        timecode.o                                                       \
+       timecode_internal.o                                              \
        timestamp.o                                                      \
        tree.o                                                           \
        twofish.o                                                        \
@@ -196,6 +197,8 @@ OBJS = adler32.o                                                        \
        video_enc_params.o                                               \
        video_hint.o                                                     \
 
+STLIBOBJS = timecode_internal.o                                         \
+
 
 OBJS-$(CONFIG_CUDA)                     += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)                  += hwcontext_d3d11va.o
-- 
2.45.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH v2 3/3] avcodec/nvenc: add time code writing for h264
  2025-02-28 22:46 [FFmpeg-devel] [PATCH v2 1/3] avutil/timecode: add ff_timecode_set_smpte Timo Rothenpieler
  2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function Timo Rothenpieler
@ 2025-02-28 22:46 ` Timo Rothenpieler
  1 sibling, 0 replies; 4+ messages in thread
From: Timo Rothenpieler @ 2025-02-28 22:46 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Timo Rothenpieler

---
 libavcodec/nvenc.c      | 62 +++++++++++++++++++++++++++++++++++++++--
 libavcodec/nvenc.h      |  1 +
 libavcodec/nvenc_h264.c |  3 ++
 3 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index f9221174f0..7ae1e7c8d7 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -34,6 +34,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/timecode_internal.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "atsc_a53.h"
@@ -1417,6 +1418,11 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
     }
 #endif
 
+#ifdef NVENC_HAVE_TIME_CODE
+    if (ctx->s12m_tc)
+        h264->enableTimeCode = 1;
+#endif
+
     return 0;
 }
 
@@ -2420,7 +2426,52 @@ static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame,
     }
 }
 
-static void nvenc_codec_specific_pic_params(AVCodecContext *avctx,
+#ifdef NVENC_HAVE_TIME_CODE
+static void nvenc_fill_time_code(AVCodecContext *avctx, const AVFrame *frame, NV_ENC_TIME_CODE *time_code)
+{
+    AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
+
+    if (sd) {
+        uint32_t *tc = (uint32_t*)sd->data;
+        int cnt = FFMIN(tc[0], FF_ARRAY_ELEMS(time_code->clockTimestamp));
+
+        switch (cnt) {
+            case 0:
+                time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME;
+                time_code->skipClockTimestampInsertion = 1;
+                break;
+            case 2:
+                time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME_DOUBLING;
+                break;
+            case 3:
+                time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME_TRIPLING;
+                break;
+            default:
+                time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME;
+                break;
+        }
+
+        for (int i = 0; i < cnt; i++) {
+            unsigned hh, mm, ss, ff, drop;
+            ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, avctx->framerate, tc[i + 1], 0, 0);
+
+            time_code->clockTimestamp[i].countingType = 0;
+            time_code->clockTimestamp[i].discontinuityFlag = 0;
+            time_code->clockTimestamp[i].cntDroppedFrames = drop;
+            time_code->clockTimestamp[i].nFrames = ff;
+            time_code->clockTimestamp[i].secondsValue = ss;
+            time_code->clockTimestamp[i].minutesValue = mm;
+            time_code->clockTimestamp[i].hoursValue = hh;
+            time_code->clockTimestamp[i].timeOffset = 0;
+        }
+    } else {
+        time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME;
+        time_code->skipClockTimestampInsertion = 1;
+    }
+}
+#endif
+
+static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, const AVFrame *frame,
                                             NV_ENC_PIC_PARAMS *params,
                                             NV_ENC_SEI_PAYLOAD *sei_data,
                                             int sei_count)
@@ -2438,6 +2489,11 @@ static void nvenc_codec_specific_pic_params(AVCodecContext *avctx,
             params->codecPicParams.h264PicParams.seiPayloadArrayCnt = sei_count;
         }
 
+#ifdef NVENC_HAVE_TIME_CODE
+        if (ctx->s12m_tc)
+            nvenc_fill_time_code(avctx, frame, &params->codecPicParams.h264PicParams.timeCode);
+#endif
+
       break;
     case AV_CODEC_ID_HEVC:
         params->codecPicParams.hevcPicParams.sliceMode =
@@ -2739,7 +2795,7 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame)
         }
     }
 
-    if (ctx->s12m_tc && av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE)) {
+    if (ctx->s12m_tc && avctx->codec->id != AV_CODEC_ID_H264 && av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE)) {
         void *tc_data = NULL;
         size_t tc_size = 0;
 
@@ -3046,7 +3102,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
         if (res < 0)
             return res;
 
-        nvenc_codec_specific_pic_params(avctx, &pic_params, ctx->sei_data, sei_count);
+        nvenc_codec_specific_pic_params(avctx, frame, &pic_params, ctx->sei_data, sei_count);
     } else {
         pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
     }
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index dbd18cac12..e035e123c6 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -96,6 +96,7 @@ typedef void ID3D11Device;
 #define NVENC_HAVE_LOOKAHEAD_LEVEL
 #define NVENC_HAVE_UHQ_TUNING
 #define NVENC_HAVE_UNIDIR_B
+#define NVENC_HAVE_TIME_CODE // added in 12.0, but incomplete until 12.2
 #endif
 
 // SDK 13.0 compile time feature checks
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index c7267a082a..c3396bde91 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -199,6 +199,9 @@ static const AVOption options[] = {
     { "middle",       "",                                   0,                    AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0,         VE, .unit = "b_ref_mode" },
 #endif
     { "a53cc",        "Use A53 Closed Captions (if available)", OFFSET(a53_cc),   AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0, 1, VE },
+#ifdef NVENC_HAVE_TIME_CODE
+    { "s12m_tc",      "Use timecode (if available)",        OFFSET(s12m_tc),      AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0, 1, VE },
+#endif
     { "dpb_size",     "Specifies the DPB size used for encoding (0 means automatic)",
                                                             OFFSET(dpb_size),     AV_OPT_TYPE_INT,   { .i64 = 0 }, 0, INT_MAX, VE },
 #ifdef NVENC_HAVE_MULTIPASS
-- 
2.45.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function
  2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function Timo Rothenpieler
@ 2025-02-28 22:49   ` Timo Rothenpieler
  0 siblings, 0 replies; 4+ messages in thread
From: Timo Rothenpieler @ 2025-02-28 22:49 UTC (permalink / raw)
  To: ffmpeg-devel

On 28.02.2025 23:46, Timo Rothenpieler wrote:
> ---
>   libavcodec/Makefile            |  2 ++
>   libavcodec/timecode_internal.c | 19 +++++++++++++++++++
>   libavcodec/utils.c             | 29 +++--------------------------
>   libavutil/Makefile             |  3 +++
>   4 files changed, 27 insertions(+), 26 deletions(-)
>   create mode 100644 libavcodec/timecode_internal.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 499f826635..e3ccbf1838 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -64,6 +64,8 @@ OBJS = ac3_parser.o                                                     \
>          vorbis_parser.o                                                  \
>          xiph.o                                                           \
>   
> +SHLIBOBJS = timecode_internal.o                                         \
> +
>   # subsystems
>   include $(SRC_PATH)/libavcodec/aac/Makefile
>   include $(SRC_PATH)/libavcodec/hevc/Makefile
> diff --git a/libavcodec/timecode_internal.c b/libavcodec/timecode_internal.c
> new file mode 100644
> index 0000000000..8682bb1b2e
> --- /dev/null
> +++ b/libavcodec/timecode_internal.c
> @@ -0,0 +1,19 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/timecode_internal.c"
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index dd846b4ae9..0aa5a6f55e 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -33,6 +33,7 @@
>   #include "libavutil/pixdesc.h"
>   #include "libavutil/imgutils.h"
>   #include "libavutil/pixfmt.h"
> +#include "libavutil/timecode_internal.h"
>   #include "avcodec.h"
>   #include "codec.h"
>   #include "codec_desc.h"
> @@ -968,15 +969,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size)
>       return props;
>   }
>   
> -static unsigned bcd2uint(uint8_t bcd)
> -{
> -    unsigned low  = bcd & 0xf;
> -    unsigned high = bcd >> 4;
> -    if (low > 9 || high > 9)
> -        return 0;
> -    return low + 10*high;
> -}
> -
>   int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
>                        void **data, size_t *sei_size)
>   {
> @@ -1006,23 +998,8 @@ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_l
>       put_bits(&pb, 2, m); // num_clock_ts
>   
>       for (int j = 1; j <= m; j++) {
> -        uint32_t tcsmpte = tc[j];
> -        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
> -        unsigned ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
> -        unsigned drop = tcsmpte & 1<<30 && !0;  // 1-bit drop if not arbitrary bit
> -
> -        /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
> -        if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
> -            unsigned pc;
> -            ff *= 2;
> -            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
> -                pc = !!(tcsmpte & 1 << 7);
> -            else
> -                pc = !!(tcsmpte & 1 << 23);
> -            ff = (ff + pc) & 0x7f;
> -        }
> +        unsigned hh, mm, ss, ff, drop;
> +        ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tc[j], 0, 0);
>   
>           put_bits(&pb, 1, 1); // clock_timestamp_flag
>           put_bits(&pb, 1, 1); // units_field_based_flag
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index b2b3b9c156..ad534a8acc 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -180,6 +180,7 @@ OBJS = adler32.o                                                        \
>          threadmessage.o                                                  \
>          time.o                                                           \
>          timecode.o                                                       \
> +       timecode_internal.o                                              \

This line belongs into the first patch, fixed locally.

>          timestamp.o                                                      \
>          tree.o                                                           \
>          twofish.o                                                        \
> @@ -196,6 +197,8 @@ OBJS = adler32.o                                                        \
>          video_enc_params.o                                               \
>          video_hint.o                                                     \
>   
> +STLIBOBJS = timecode_internal.o                                         \
> +
>   
>   OBJS-$(CONFIG_CUDA)                     += hwcontext_cuda.o
>   OBJS-$(CONFIG_D3D11VA)                  += hwcontext_d3d11va.o

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-28 22:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-28 22:46 [FFmpeg-devel] [PATCH v2 1/3] avutil/timecode: add ff_timecode_set_smpte Timo Rothenpieler
2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function Timo Rothenpieler
2025-02-28 22:49   ` Timo Rothenpieler
2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 3/3] avcodec/nvenc: add time code writing for h264 Timo Rothenpieler

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git