]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/nvenc: support for HEVC timecode passthrough
authorLimin Wang <lance.lmwang@gmail.com>
Sun, 28 Jun 2020 02:34:12 +0000 (10:34 +0800)
committerLimin Wang <lance.lmwang@gmail.com>
Sun, 28 Jun 2020 13:40:49 +0000 (21:40 +0800)
Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
libavcodec/nvenc.c
libavcodec/nvenc.h
libavcodec/nvenc_hevc.c

index de6b0eaa449cf158c90e0bd84ade113f8d5843db..b957b9cb7ca71ca70a15501c12b3927fcb30c7df 100644 (file)
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include "nvenc.h"
+#include "hevc_sei.h"
 
 #include "libavutil/hwcontext_cuda.h"
 #include "libavutil/hwcontext.h"
@@ -2153,6 +2154,22 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
             }
         }
 
+        if (ctx->tc && av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE)) {
+            void *tc_data = NULL;
+            size_t tc_size = 0;
+
+            if (ff_alloc_timecode_sei(frame, 0, (void**)&tc_data, &tc_size) < 0) {
+                av_log(ctx, AV_LOG_ERROR, "Not enough memory for timecode sei, skipping\n");
+            }
+
+            if (tc_data) {
+                sei_data[sei_count].payloadSize = (uint32_t)tc_size;
+                sei_data[sei_count].payloadType = HEVC_SEI_TYPE_TIME_CODE;
+                sei_data[sei_count].payload = (uint8_t*)tc_data;
+                sei_count ++;
+            }
+        }
+
         nvenc_codec_specific_pic_params(avctx, &pic_params, sei_data, sei_count);
     } else {
         pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
index 007721aa66785bf901ffa2b3df60bc8ac132f2d9..b67abcaf184176cd752c6b032145ea6f45f5110c 100644 (file)
@@ -196,6 +196,7 @@ typedef struct NvencContext
     int coder;
     int b_ref_mode;
     int a53_cc;
+    int tc;
     int dpb_size;
 } NvencContext;
 
index 434dc6679e182748ecb3778439f29c1517fd0b2a..45dda3daac60cd4e4afc3f38a203032baf9c2700 100644 (file)
@@ -129,6 +129,7 @@ static const AVOption options[] = {
     { "each",         "",                                   0,                    AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0,       VE, "b_ref_mode" },
     { "middle",       "",                                   0,                    AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0,       VE, "b_ref_mode" },
 #endif
+    { "tc",           "Use timecode (if available)",        OFFSET(tc),           AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0, 1,       VE },
     { "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 },
     { NULL }