diff mbox series

[FFmpeg-devel,v4,7/7] avcodec/nvenc: support for HEVC timecode passthrough

Message ID 1593006200-23911-7-git-send-email-lance.lmwang@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v4,1/7] FATE: add h264 timecode side data test | expand

Checks

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

Commit Message

Lance Wang June 24, 2020, 1:43 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/nvenc.c      | 17 +++++++++++++++++
 libavcodec/nvenc.h      |  1 +
 libavcodec/nvenc_hevc.c |  1 +
 3 files changed, 19 insertions(+)

Comments

Lance Wang June 26, 2020, 2:03 p.m. UTC | #1
On Wed, Jun 24, 2020 at 09:43:20PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/nvenc.c      | 17 +++++++++++++++++
>  libavcodec/nvenc.h      |  1 +
>  libavcodec/nvenc_hevc.c |  1 +
>  3 files changed, 19 insertions(+)
> 
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index 22c19f3..4efd532 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -22,6 +22,7 @@
>  #include "config.h"
>  
>  #include "nvenc.h"
> +#include "hevc_sei.h"
>  
>  #include "libavutil/hwcontext_cuda.h"
>  #include "libavutil/hwcontext.h"
> @@ -2147,6 +2148,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);
>      } else {
>          pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
> diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
> index 007721a..b67abca 100644
> --- a/libavcodec/nvenc.h
> +++ b/libavcodec/nvenc.h
> @@ -196,6 +196,7 @@ typedef struct NvencContext
>      int coder;
>      int b_ref_mode;
>      int a53_cc;
> +    int tc;
>      int dpb_size;
>  } NvencContext;
>  
> diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
> index 434dc66..45dda3d 100644
> --- a/libavcodec/nvenc_hevc.c
> +++ b/libavcodec/nvenc_hevc.c
> @@ -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 }
> -- 
> 1.8.3.1
> 

will apply the patchset(except #1 fate testing) tomorrow if no objections.
Josh Dekker June 26, 2020, 2:11 p.m. UTC | #2
On 26/06/2020 15:03, lance.lmwang@gmail.com wrote:
> On Wed, Jun 24, 2020 at 09:43:20PM +0800, lance.lmwang@gmail.com wrote:
>> From: Limin Wang <lance.lmwang@gmail.com>
>>
>> Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> ---
>>   libavcodec/nvenc.c      | 17 +++++++++++++++++
>>   libavcodec/nvenc.h      |  1 +
>>   libavcodec/nvenc_hevc.c |  1 +
>>   3 files changed, 19 insertions(+)
>>
>> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
>> index 22c19f3..4efd532 100644
>> --- a/libavcodec/nvenc.c
>> +++ b/libavcodec/nvenc.c
>> @@ -22,6 +22,7 @@
>>   #include "config.h"
>>   
>>   #include "nvenc.h"
>> +#include "hevc_sei.h"
>>   
>>   #include "libavutil/hwcontext_cuda.h"
>>   #include "libavutil/hwcontext.h"
>> @@ -2147,6 +2148,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);
>>       } else {
>>           pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
>> diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
>> index 007721a..b67abca 100644
>> --- a/libavcodec/nvenc.h
>> +++ b/libavcodec/nvenc.h
>> @@ -196,6 +196,7 @@ typedef struct NvencContext
>>       int coder;
>>       int b_ref_mode;
>>       int a53_cc;
>> +    int tc;
>>       int dpb_size;
>>   } NvencContext;
>>   
>> diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
>> index 434dc66..45dda3d 100644
>> --- a/libavcodec/nvenc_hevc.c
>> +++ b/libavcodec/nvenc_hevc.c
>> @@ -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 }
>> -- 
>> 1.8.3.1
>>
> 
> will apply the patchset(except #1 fate testing) tomorrow if no objections.

Thanks for updating the set, this is what I had in mind. I can't 
properly LGTM it since I haven't tested it myself but it looks mostly 
fine with a precursory glance.
Lance Wang June 26, 2020, 2:39 p.m. UTC | #3
On Fri, Jun 26, 2020 at 03:11:39PM +0100, Josh de Kock wrote:
> On 26/06/2020 15:03, lance.lmwang@gmail.com wrote:
> > On Wed, Jun 24, 2020 at 09:43:20PM +0800, lance.lmwang@gmail.com wrote:
> > > From: Limin Wang <lance.lmwang@gmail.com>
> > > 
> > > Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
> > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > > ---
> > >   libavcodec/nvenc.c      | 17 +++++++++++++++++
> > >   libavcodec/nvenc.h      |  1 +
> > >   libavcodec/nvenc_hevc.c |  1 +
> > >   3 files changed, 19 insertions(+)
> > > 
> > > diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> > > index 22c19f3..4efd532 100644
> > > --- a/libavcodec/nvenc.c
> > > +++ b/libavcodec/nvenc.c
> > > @@ -22,6 +22,7 @@
> > >   #include "config.h"
> > >   #include "nvenc.h"
> > > +#include "hevc_sei.h"
> > >   #include "libavutil/hwcontext_cuda.h"
> > >   #include "libavutil/hwcontext.h"
> > > @@ -2147,6 +2148,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);
> > >       } else {
> > >           pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
> > > diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
> > > index 007721a..b67abca 100644
> > > --- a/libavcodec/nvenc.h
> > > +++ b/libavcodec/nvenc.h
> > > @@ -196,6 +196,7 @@ typedef struct NvencContext
> > >       int coder;
> > >       int b_ref_mode;
> > >       int a53_cc;
> > > +    int tc;
> > >       int dpb_size;
> > >   } NvencContext;
> > > diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
> > > index 434dc66..45dda3d 100644
> > > --- a/libavcodec/nvenc_hevc.c
> > > +++ b/libavcodec/nvenc_hevc.c
> > > @@ -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 }
> > > -- 
> > > 1.8.3.1
> > > 
> > 
> > will apply the patchset(except #1 fate testing) tomorrow if no objections.
> 
> Thanks for updating the set, this is what I had in mind. I can't properly
> LGTM it since I haven't tested it myself but it looks mostly fine with a
> precursory glance.

Josh, thanks for review and feedback.  


> 
> -- 
> Josh
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 22c19f3..4efd532 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -22,6 +22,7 @@ 
 #include "config.h"
 
 #include "nvenc.h"
+#include "hevc_sei.h"
 
 #include "libavutil/hwcontext_cuda.h"
 #include "libavutil/hwcontext.h"
@@ -2147,6 +2148,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);
     } else {
         pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 007721a..b67abca 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -196,6 +196,7 @@  typedef struct NvencContext
     int coder;
     int b_ref_mode;
     int a53_cc;
+    int tc;
     int dpb_size;
 } NvencContext;
 
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index 434dc66..45dda3d 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -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 }