Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-24 Thread Aman Gupta
On Monday, September 19, 2016, Richard Kern  wrote:

>
> On Sep 10, 2016, at 10:33 PM, Aman Gupta  > wrote:
>
>
>
> On Sunday, September 11, 2016, Richard Kern  > wrote:
>
>>
>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta  wrote:
>> >
>> > From: Aman Gupta 
>> >
>> > ---
>> > libavcodec/videotoolboxenc.c | 76 ++
>> --
>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> > index 4345ca3..859dde9 100644
>> > --- a/libavcodec/videotoolboxenc.c
>> > +++ b/libavcodec/videotoolboxenc.c
>> > @@ -32,6 +32,7 @@
>> > #include "libavutil/pixdesc.h"
>> > #include "internal.h"
>> > #include 
>> > +#include "h264.h"
>> >
>> > #if !CONFIG_VT_BT2020
>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>> >
>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>> >
>> > +typedef struct ExtraSEI {
>> > +  void *data;
>> > +  size_t size;
>> > +} ExtraSEI;
>> > +
>> > typedef struct BufNode {
>> > CMSampleBufferRef cm_buffer;
>> > +ExtraSEI *sei;
>> > struct BufNode* next;
>> > int error;
>> > } BufNode;
>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>> > bool flushing;
>> > bool has_b_frames;
>> > bool warned_color_range;
>> > +bool a53_cc;
>> > } VTEncContext;
>> >
>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>> int err)
>> > pthread_mutex_unlock(>lock);
>> > }
>> >
>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf)
>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf, ExtraSEI **sei)
>> > {
>> > BufNode *info;
>> >
>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > pthread_mutex_unlock(>lock);
>> >
>> > *buf = info->cm_buffer;
>> > +if (sei && *buf) {
>> > +*sei = info->sei;
>> > +} else if (info->sei) {
>> > +if (info->sei->data) av_free(info->sei->data);
>> > +av_free(info->sei);
>> > +}
>> > av_free(info);
>> >
>> > vtctx->frame_ct_out++;
>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > return 0;
>> > }
>> >
>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>> buffer, ExtraSEI *sei)
>> > {
>> > BufNode *info = av_malloc(sizeof(BufNode));
>> > if (!info) {
>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>> CMSampleBufferRef buffer)
>> >
>> > CFRetain(buffer);
>> > info->cm_buffer = buffer;
>> > +info->sei = sei;
>> > info->next = NULL;
>> >
>> > pthread_mutex_lock(>lock);
>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>> > {
>> > AVCodecContext *avctx = ctx;
>> > VTEncContext   *vtctx = avctx->priv_data;
>> > +ExtraSEI *sei = sourceFrameCtx;
>> >
>> > if (vtctx->async_error) {
>> > if(sample_buffer) CFRelease(sample_buffer);
>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>> > }
>> > }
>> >
>> > -vtenc_q_push(vtctx, sample_buffer);
>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>> > }
>> >
>> > static int get_length_code_size(
>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>> > static int vtenc_cm_to_avpacket(
>> > AVCodecContext*avctx,
>> > CMSampleBufferRef sample_buffer,
>> > -AVPacket  *pkt)
>> > +AVPacket  *pkt,
>> > +ExtraSEI  *sei)
>> > {
>> > VTEncContext *vtctx = avctx->priv_data;
>> >
>> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
>> > size_t  header_size = 0;
>> > size_t  in_buf_size;
>> > size_t  out_buf_size;
>> > +size_t  sei_nalu_size = 0;
>> > int64_t dts_delta;
>> > int64_t time_base_num;
>> > int nalu_count;
>> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
>> > if(status)
>> > return status;
>> >
>> > +if (sei) {
>> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
>> > +}
>> > +
>> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
>> > out_buf_size = header_size +
>> >in_buf_size +
>> > +   sei_nalu_size +
>> >nalu_count * ((int)sizeof(start_code) -
>> (int)length_code_size);
>> >
>> > status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
>> > @@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
>> > length_code_size,
>> > sample_buffer,
>> > 

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-18 Thread Richard Kern

> On Oct 18, 2016, at 2:30 PM, Aman Gupta  wrote:
> 
> 
> 
> On Mon, Oct 17, 2016 at 6:03 PM, Aman Gupta  > wrote:
> 
> 
> On Mon, Oct 17, 2016 at 5:51 PM, Richard Kern  > wrote:
> 
>> On Oct 17, 2016, at 8:47 PM, Aman Gupta > > wrote:
>> 
>> 
>> 
>> On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern > > wrote:
>> 
>>> On Sep 19, 2016, at 10:30 AM, Aman Gupta >> > wrote:
>>> 
>>> 
>>> 
>>> On Monday, September 19, 2016, Richard Kern >> > wrote:
>>> 
 On Sep 10, 2016, at 10:33 PM, Aman Gupta > wrote:
 
 
 
 On Sunday, September 11, 2016, Richard Kern > wrote:
 
 > On Sep 8, 2016, at 4:19 AM, Aman Gupta > wrote:
 >
 > From: Aman Gupta >
 >
 > ---
 > libavcodec/videotoolboxenc.c | 76 
 > ++--
 > 1 file changed, 67 insertions(+), 9 deletions(-)
 >
 > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
 > index 4345ca3..859dde9 100644
 > --- a/libavcodec/videotoolboxenc.c
 > +++ b/libavcodec/videotoolboxenc.c
 > @@ -32,6 +32,7 @@
 > #include "libavutil/pixdesc.h"
 > #include "internal.h"
 > #include 
 > +#include "h264.h"
 >
 > #if !CONFIG_VT_BT2020
 > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
 > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
 >
 > static const uint8_t start_code[] = { 0, 0, 0, 1 };
 >
 > +typedef struct ExtraSEI {
 > +  void *data;
 > +  size_t size;
 > +} ExtraSEI;
 > +
 > typedef struct BufNode {
 > CMSampleBufferRef cm_buffer;
 > +ExtraSEI *sei;
 > struct BufNode* next;
 > int error;
 > } BufNode;
 > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
 > bool flushing;
 > bool has_b_frames;
 > bool warned_color_range;
 > +bool a53_cc;
 > } VTEncContext;
 >
 > static int vtenc_populate_extradata(AVCodecContext   *avctx,
 > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int 
 > err)
 > pthread_mutex_unlock(>lock);
 > }
 >
 > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
 > CMSampleBufferRef *buf)
 > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
 > CMSampleBufferRef *buf, ExtraSEI **sei)
 > {
 > BufNode *info;
 >
 > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool 
 > wait, CMSampleBufferRef *buf)
 > pthread_mutex_unlock(>lock);
 >
 > *buf = info->cm_buffer;
 > +if (sei && *buf) {
 > +*sei = info->sei;
 > +} else if (info->sei) {
 > +if (info->sei->data) av_free(info->sei->data);
 > +av_free(info->sei);
 > +}
 > av_free(info);
 >
 > vtctx->frame_ct_out++;
 > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool 
 > wait, CMSampleBufferRef *buf)
 > return 0;
 > }
 >
 > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
 > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
 > ExtraSEI *sei)
 > {
 > BufNode *info = av_malloc(sizeof(BufNode));
 > if (!info) {
 > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
 > CMSampleBufferRef buffer)
 >
 > CFRetain(buffer);
 > info->cm_buffer = buffer;
 > +info->sei = sei;
 > info->next = NULL;
 >
 > pthread_mutex_lock(>lock);
 > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
 > {
 > AVCodecContext *avctx = ctx;
 > VTEncContext   *vtctx = avctx->priv_data;
 > +ExtraSEI *sei = sourceFrameCtx;
 >
 > if (vtctx->async_error) {
 > if(sample_buffer) CFRelease(sample_buffer);
 > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
 > }
 > }
 >
 > -vtenc_q_push(vtctx, sample_buffer);
 > +vtenc_q_push(vtctx, sample_buffer, sei);
 > }
 >
 > static int get_length_code_size(
 > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
 > static int vtenc_cm_to_avpacket(
 > AVCodecContext*avctx,
 > CMSampleBufferRef sample_buffer,
 > -AVPacket  *pkt)
 > +AVPacket  *pkt,
 > +ExtraSEI  *sei)
 > {
 > VTEncContext *vtctx = avctx->priv_data;
 >
 > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
 > size_t  header_size = 0;
 > size_t  in_buf_size;
 > size_t  

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-18 Thread Aman Gupta
On Mon, Oct 17, 2016 at 6:03 PM, Aman Gupta  wrote:

>
>
> On Mon, Oct 17, 2016 at 5:51 PM, Richard Kern  wrote:
>
>>
>> On Oct 17, 2016, at 8:47 PM, Aman Gupta  wrote:
>>
>>
>>
>> On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern  wrote:
>>
>>>
>>> On Sep 19, 2016, at 10:30 AM, Aman Gupta  wrote:
>>>
>>>
>>>
>>> On Monday, September 19, 2016, Richard Kern  wrote:
>>>

 On Sep 10, 2016, at 10:33 PM, Aman Gupta  wrote:



 On Sunday, September 11, 2016, Richard Kern  wrote:

>
> > On Sep 8, 2016, at 4:19 AM, Aman Gupta  wrote:
> >
> > From: Aman Gupta 
> >
> > ---
> > libavcodec/videotoolboxenc.c | 76 ++
> --
> > 1 file changed, 67 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/videotoolboxenc.c
> b/libavcodec/videotoolboxenc.c
> > index 4345ca3..859dde9 100644
> > --- a/libavcodec/videotoolboxenc.c
> > +++ b/libavcodec/videotoolboxenc.c
> > @@ -32,6 +32,7 @@
> > #include "libavutil/pixdesc.h"
> > #include "internal.h"
> > #include 
> > +#include "h264.h"
> >
> > #if !CONFIG_VT_BT2020
> > # define kCVImageBufferColorPrimaries_ITU_R_2020
>  CFSTR("ITU_R_2020")
> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
> >
> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
> >
> > +typedef struct ExtraSEI {
> > +  void *data;
> > +  size_t size;
> > +} ExtraSEI;
> > +
> > typedef struct BufNode {
> > CMSampleBufferRef cm_buffer;
> > +ExtraSEI *sei;
> > struct BufNode* next;
> > int error;
> > } BufNode;
> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
> > bool flushing;
> > bool has_b_frames;
> > bool warned_color_range;
> > +bool a53_cc;
> > } VTEncContext;
> >
> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
> int err)
> > pthread_mutex_unlock(>lock);
> > }
> >
> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
> CMSampleBufferRef *buf)
> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
> CMSampleBufferRef *buf, ExtraSEI **sei)
> > {
> > BufNode *info;
> >
> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx,
> bool wait, CMSampleBufferRef *buf)
> > pthread_mutex_unlock(>lock);
> >
> > *buf = info->cm_buffer;
> > +if (sei && *buf) {
> > +*sei = info->sei;
> > +} else if (info->sei) {
> > +if (info->sei->data) av_free(info->sei->data);
> > +av_free(info->sei);
> > +}
> > av_free(info);
> >
> > vtctx->frame_ct_out++;
> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
> wait, CMSampleBufferRef *buf)
> > return 0;
> > }
> >
> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
> buffer)
> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
> buffer, ExtraSEI *sei)
> > {
> > BufNode *info = av_malloc(sizeof(BufNode));
> > if (!info) {
> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
> CMSampleBufferRef buffer)
> >
> > CFRetain(buffer);
> > info->cm_buffer = buffer;
> > +info->sei = sei;
> > info->next = NULL;
> >
> > pthread_mutex_lock(>lock);
> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
> > {
> > AVCodecContext *avctx = ctx;
> > VTEncContext   *vtctx = avctx->priv_data;
> > +ExtraSEI *sei = sourceFrameCtx;
> >
> > if (vtctx->async_error) {
> > if(sample_buffer) CFRelease(sample_buffer);
> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
> > }
> > }
> >
> > -vtenc_q_push(vtctx, sample_buffer);
> > +vtenc_q_push(vtctx, sample_buffer, sei);
> > }
> >
> > static int get_length_code_size(
> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
> > static int vtenc_cm_to_avpacket(
> > AVCodecContext*avctx,
> > CMSampleBufferRef sample_buffer,
> > -AVPacket  *pkt)
> > +AVPacket  *pkt,
> > +ExtraSEI  *sei)
> > {
> > VTEncContext *vtctx = avctx->priv_data;
> >
> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
> > size_t  header_size = 0;
> > size_t  in_buf_size;
> > size_t  out_buf_size;
> > +size_t  sei_nalu_size = 0;
> > int64_t dts_delta;
> > int64_t time_base_num;
> > int nalu_count;
> 

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-17 Thread Aman Gupta
On Mon, Oct 17, 2016 at 5:51 PM, Richard Kern  wrote:

>
> On Oct 17, 2016, at 8:47 PM, Aman Gupta  wrote:
>
>
>
> On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern  wrote:
>
>>
>> On Sep 19, 2016, at 10:30 AM, Aman Gupta  wrote:
>>
>>
>>
>> On Monday, September 19, 2016, Richard Kern  wrote:
>>
>>>
>>> On Sep 10, 2016, at 10:33 PM, Aman Gupta  wrote:
>>>
>>>
>>>
>>> On Sunday, September 11, 2016, Richard Kern  wrote:
>>>

 > On Sep 8, 2016, at 4:19 AM, Aman Gupta  wrote:
 >
 > From: Aman Gupta 
 >
 > ---
 > libavcodec/videotoolboxenc.c | 76 ++
 --
 > 1 file changed, 67 insertions(+), 9 deletions(-)
 >
 > diff --git a/libavcodec/videotoolboxenc.c
 b/libavcodec/videotoolboxenc.c
 > index 4345ca3..859dde9 100644
 > --- a/libavcodec/videotoolboxenc.c
 > +++ b/libavcodec/videotoolboxenc.c
 > @@ -32,6 +32,7 @@
 > #include "libavutil/pixdesc.h"
 > #include "internal.h"
 > #include 
 > +#include "h264.h"
 >
 > #if !CONFIG_VT_BT2020
 > # define kCVImageBufferColorPrimaries_ITU_R_2020
  CFSTR("ITU_R_2020")
 > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
 >
 > static const uint8_t start_code[] = { 0, 0, 0, 1 };
 >
 > +typedef struct ExtraSEI {
 > +  void *data;
 > +  size_t size;
 > +} ExtraSEI;
 > +
 > typedef struct BufNode {
 > CMSampleBufferRef cm_buffer;
 > +ExtraSEI *sei;
 > struct BufNode* next;
 > int error;
 > } BufNode;
 > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
 > bool flushing;
 > bool has_b_frames;
 > bool warned_color_range;
 > +bool a53_cc;
 > } VTEncContext;
 >
 > static int vtenc_populate_extradata(AVCodecContext   *avctx,
 > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
 int err)
 > pthread_mutex_unlock(>lock);
 > }
 >
 > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
 CMSampleBufferRef *buf)
 > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
 CMSampleBufferRef *buf, ExtraSEI **sei)
 > {
 > BufNode *info;
 >
 > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
 wait, CMSampleBufferRef *buf)
 > pthread_mutex_unlock(>lock);
 >
 > *buf = info->cm_buffer;
 > +if (sei && *buf) {
 > +*sei = info->sei;
 > +} else if (info->sei) {
 > +if (info->sei->data) av_free(info->sei->data);
 > +av_free(info->sei);
 > +}
 > av_free(info);
 >
 > vtctx->frame_ct_out++;
 > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
 wait, CMSampleBufferRef *buf)
 > return 0;
 > }
 >
 > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
 buffer)
 > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
 buffer, ExtraSEI *sei)
 > {
 > BufNode *info = av_malloc(sizeof(BufNode));
 > if (!info) {
 > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
 CMSampleBufferRef buffer)
 >
 > CFRetain(buffer);
 > info->cm_buffer = buffer;
 > +info->sei = sei;
 > info->next = NULL;
 >
 > pthread_mutex_lock(>lock);
 > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
 > {
 > AVCodecContext *avctx = ctx;
 > VTEncContext   *vtctx = avctx->priv_data;
 > +ExtraSEI *sei = sourceFrameCtx;
 >
 > if (vtctx->async_error) {
 > if(sample_buffer) CFRelease(sample_buffer);
 > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
 > }
 > }
 >
 > -vtenc_q_push(vtctx, sample_buffer);
 > +vtenc_q_push(vtctx, sample_buffer, sei);
 > }
 >
 > static int get_length_code_size(
 > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
 > static int vtenc_cm_to_avpacket(
 > AVCodecContext*avctx,
 > CMSampleBufferRef sample_buffer,
 > -AVPacket  *pkt)
 > +AVPacket  *pkt,
 > +ExtraSEI  *sei)
 > {
 > VTEncContext *vtctx = avctx->priv_data;
 >
 > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
 > size_t  header_size = 0;
 > size_t  in_buf_size;
 > size_t  out_buf_size;
 > +size_t  sei_nalu_size = 0;
 > int64_t dts_delta;
 > int64_t time_base_num;
 > int nalu_count;
 > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
 > if(status)
 > return status;
 >
 > +if (sei) {
 > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
 > +}

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-17 Thread Aman Gupta
On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern  wrote:

>
> On Sep 19, 2016, at 10:30 AM, Aman Gupta  wrote:
>
>
>
> On Monday, September 19, 2016, Richard Kern  wrote:
>
>>
>> On Sep 10, 2016, at 10:33 PM, Aman Gupta  wrote:
>>
>>
>>
>> On Sunday, September 11, 2016, Richard Kern  wrote:
>>
>>>
>>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta  wrote:
>>> >
>>> > From: Aman Gupta 
>>> >
>>> > ---
>>> > libavcodec/videotoolboxenc.c | 76 ++
>>> --
>>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>>> >
>>> > diff --git a/libavcodec/videotoolboxenc.c
>>> b/libavcodec/videotoolboxenc.c
>>> > index 4345ca3..859dde9 100644
>>> > --- a/libavcodec/videotoolboxenc.c
>>> > +++ b/libavcodec/videotoolboxenc.c
>>> > @@ -32,6 +32,7 @@
>>> > #include "libavutil/pixdesc.h"
>>> > #include "internal.h"
>>> > #include 
>>> > +#include "h264.h"
>>> >
>>> > #if !CONFIG_VT_BT2020
>>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>>> >
>>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>>> >
>>> > +typedef struct ExtraSEI {
>>> > +  void *data;
>>> > +  size_t size;
>>> > +} ExtraSEI;
>>> > +
>>> > typedef struct BufNode {
>>> > CMSampleBufferRef cm_buffer;
>>> > +ExtraSEI *sei;
>>> > struct BufNode* next;
>>> > int error;
>>> > } BufNode;
>>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>>> > bool flushing;
>>> > bool has_b_frames;
>>> > bool warned_color_range;
>>> > +bool a53_cc;
>>> > } VTEncContext;
>>> >
>>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>>> int err)
>>> > pthread_mutex_unlock(>lock);
>>> > }
>>> >
>>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>>> CMSampleBufferRef *buf)
>>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>>> CMSampleBufferRef *buf, ExtraSEI **sei)
>>> > {
>>> > BufNode *info;
>>> >
>>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>>> wait, CMSampleBufferRef *buf)
>>> > pthread_mutex_unlock(>lock);
>>> >
>>> > *buf = info->cm_buffer;
>>> > +if (sei && *buf) {
>>> > +*sei = info->sei;
>>> > +} else if (info->sei) {
>>> > +if (info->sei->data) av_free(info->sei->data);
>>> > +av_free(info->sei);
>>> > +}
>>> > av_free(info);
>>> >
>>> > vtctx->frame_ct_out++;
>>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>>> wait, CMSampleBufferRef *buf)
>>> > return 0;
>>> > }
>>> >
>>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>>> buffer)
>>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>>> buffer, ExtraSEI *sei)
>>> > {
>>> > BufNode *info = av_malloc(sizeof(BufNode));
>>> > if (!info) {
>>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>>> CMSampleBufferRef buffer)
>>> >
>>> > CFRetain(buffer);
>>> > info->cm_buffer = buffer;
>>> > +info->sei = sei;
>>> > info->next = NULL;
>>> >
>>> > pthread_mutex_lock(>lock);
>>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>>> > {
>>> > AVCodecContext *avctx = ctx;
>>> > VTEncContext   *vtctx = avctx->priv_data;
>>> > +ExtraSEI *sei = sourceFrameCtx;
>>> >
>>> > if (vtctx->async_error) {
>>> > if(sample_buffer) CFRelease(sample_buffer);
>>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>>> > }
>>> > }
>>> >
>>> > -vtenc_q_push(vtctx, sample_buffer);
>>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>>> > }
>>> >
>>> > static int get_length_code_size(
>>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>>> > static int vtenc_cm_to_avpacket(
>>> > AVCodecContext*avctx,
>>> > CMSampleBufferRef sample_buffer,
>>> > -AVPacket  *pkt)
>>> > +AVPacket  *pkt,
>>> > +ExtraSEI  *sei)
>>> > {
>>> > VTEncContext *vtctx = avctx->priv_data;
>>> >
>>> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
>>> > size_t  header_size = 0;
>>> > size_t  in_buf_size;
>>> > size_t  out_buf_size;
>>> > +size_t  sei_nalu_size = 0;
>>> > int64_t dts_delta;
>>> > int64_t time_base_num;
>>> > int nalu_count;
>>> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
>>> > if(status)
>>> > return status;
>>> >
>>> > +if (sei) {
>>> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
>>> > +}
>>> > +
>>> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
>>> > out_buf_size = header_size +
>>> >in_buf_size +
>>> > +   sei_nalu_size +
>>> >nalu_count * ((int)sizeof(start_code) -
>>> (int)length_code_size);
>>> >
>>> > 

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-17 Thread Richard Kern

> On Oct 17, 2016, at 8:47 PM, Aman Gupta  wrote:
> 
> 
> 
> On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern  > wrote:
> 
>> On Sep 19, 2016, at 10:30 AM, Aman Gupta > > wrote:
>> 
>> 
>> 
>> On Monday, September 19, 2016, Richard Kern > > wrote:
>> 
>>> On Sep 10, 2016, at 10:33 PM, Aman Gupta > wrote:
>>> 
>>> 
>>> 
>>> On Sunday, September 11, 2016, Richard Kern > wrote:
>>> 
>>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta > wrote:
>>> >
>>> > From: Aman Gupta >
>>> >
>>> > ---
>>> > libavcodec/videotoolboxenc.c | 76 
>>> > ++--
>>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>>> >
>>> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>>> > index 4345ca3..859dde9 100644
>>> > --- a/libavcodec/videotoolboxenc.c
>>> > +++ b/libavcodec/videotoolboxenc.c
>>> > @@ -32,6 +32,7 @@
>>> > #include "libavutil/pixdesc.h"
>>> > #include "internal.h"
>>> > #include 
>>> > +#include "h264.h"
>>> >
>>> > #if !CONFIG_VT_BT2020
>>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>>> >
>>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>>> >
>>> > +typedef struct ExtraSEI {
>>> > +  void *data;
>>> > +  size_t size;
>>> > +} ExtraSEI;
>>> > +
>>> > typedef struct BufNode {
>>> > CMSampleBufferRef cm_buffer;
>>> > +ExtraSEI *sei;
>>> > struct BufNode* next;
>>> > int error;
>>> > } BufNode;
>>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>>> > bool flushing;
>>> > bool has_b_frames;
>>> > bool warned_color_range;
>>> > +bool a53_cc;
>>> > } VTEncContext;
>>> >
>>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int 
>>> > err)
>>> > pthread_mutex_unlock(>lock);
>>> > }
>>> >
>>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
>>> > *buf)
>>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
>>> > *buf, ExtraSEI **sei)
>>> > {
>>> > BufNode *info;
>>> >
>>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool 
>>> > wait, CMSampleBufferRef *buf)
>>> > pthread_mutex_unlock(>lock);
>>> >
>>> > *buf = info->cm_buffer;
>>> > +if (sei && *buf) {
>>> > +*sei = info->sei;
>>> > +} else if (info->sei) {
>>> > +if (info->sei->data) av_free(info->sei->data);
>>> > +av_free(info->sei);
>>> > +}
>>> > av_free(info);
>>> >
>>> > vtctx->frame_ct_out++;
>>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool 
>>> > wait, CMSampleBufferRef *buf)
>>> > return 0;
>>> > }
>>> >
>>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
>>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
>>> > ExtraSEI *sei)
>>> > {
>>> > BufNode *info = av_malloc(sizeof(BufNode));
>>> > if (!info) {
>>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
>>> > CMSampleBufferRef buffer)
>>> >
>>> > CFRetain(buffer);
>>> > info->cm_buffer = buffer;
>>> > +info->sei = sei;
>>> > info->next = NULL;
>>> >
>>> > pthread_mutex_lock(>lock);
>>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>>> > {
>>> > AVCodecContext *avctx = ctx;
>>> > VTEncContext   *vtctx = avctx->priv_data;
>>> > +ExtraSEI *sei = sourceFrameCtx;
>>> >
>>> > if (vtctx->async_error) {
>>> > if(sample_buffer) CFRelease(sample_buffer);
>>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>>> > }
>>> > }
>>> >
>>> > -vtenc_q_push(vtctx, sample_buffer);
>>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>>> > }
>>> >
>>> > static int get_length_code_size(
>>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>>> > static int vtenc_cm_to_avpacket(
>>> > AVCodecContext*avctx,
>>> > CMSampleBufferRef sample_buffer,
>>> > -AVPacket  *pkt)
>>> > +AVPacket  *pkt,
>>> > +ExtraSEI  *sei)
>>> > {
>>> > VTEncContext *vtctx = avctx->priv_data;
>>> >
>>> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
>>> > size_t  header_size = 0;
>>> > size_t  in_buf_size;
>>> > size_t  out_buf_size;
>>> > +size_t  sei_nalu_size = 0;
>>> > int64_t dts_delta;
>>> > int64_t time_base_num;
>>> > int nalu_count;
>>> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
>>> > if(status)
>>> > return status;
>>> >
>>> > +if (sei) {
>>> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
>>> > +}
>>> > +
>>> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
>>> > 

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-17 Thread Richard Kern

> On Sep 19, 2016, at 10:30 AM, Aman Gupta  wrote:
> 
> 
> 
> On Monday, September 19, 2016, Richard Kern  > wrote:
> 
>> On Sep 10, 2016, at 10:33 PM, Aman Gupta > wrote:
>> 
>> 
>> 
>> On Sunday, September 11, 2016, Richard Kern > wrote:
>> 
>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta > wrote:
>> >
>> > From: Aman Gupta >
>> >
>> > ---
>> > libavcodec/videotoolboxenc.c | 76 
>> > ++--
>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> > index 4345ca3..859dde9 100644
>> > --- a/libavcodec/videotoolboxenc.c
>> > +++ b/libavcodec/videotoolboxenc.c
>> > @@ -32,6 +32,7 @@
>> > #include "libavutil/pixdesc.h"
>> > #include "internal.h"
>> > #include 
>> > +#include "h264.h"
>> >
>> > #if !CONFIG_VT_BT2020
>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>> >
>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>> >
>> > +typedef struct ExtraSEI {
>> > +  void *data;
>> > +  size_t size;
>> > +} ExtraSEI;
>> > +
>> > typedef struct BufNode {
>> > CMSampleBufferRef cm_buffer;
>> > +ExtraSEI *sei;
>> > struct BufNode* next;
>> > int error;
>> > } BufNode;
>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>> > bool flushing;
>> > bool has_b_frames;
>> > bool warned_color_range;
>> > +bool a53_cc;
>> > } VTEncContext;
>> >
>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int 
>> > err)
>> > pthread_mutex_unlock(>lock);
>> > }
>> >
>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
>> > *buf)
>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
>> > *buf, ExtraSEI **sei)
>> > {
>> > BufNode *info;
>> >
>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool 
>> > wait, CMSampleBufferRef *buf)
>> > pthread_mutex_unlock(>lock);
>> >
>> > *buf = info->cm_buffer;
>> > +if (sei && *buf) {
>> > +*sei = info->sei;
>> > +} else if (info->sei) {
>> > +if (info->sei->data) av_free(info->sei->data);
>> > +av_free(info->sei);
>> > +}
>> > av_free(info);
>> >
>> > vtctx->frame_ct_out++;
>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
>> > CMSampleBufferRef *buf)
>> > return 0;
>> > }
>> >
>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
>> > ExtraSEI *sei)
>> > {
>> > BufNode *info = av_malloc(sizeof(BufNode));
>> > if (!info) {
>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
>> > CMSampleBufferRef buffer)
>> >
>> > CFRetain(buffer);
>> > info->cm_buffer = buffer;
>> > +info->sei = sei;
>> > info->next = NULL;
>> >
>> > pthread_mutex_lock(>lock);
>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>> > {
>> > AVCodecContext *avctx = ctx;
>> > VTEncContext   *vtctx = avctx->priv_data;
>> > +ExtraSEI *sei = sourceFrameCtx;
>> >
>> > if (vtctx->async_error) {
>> > if(sample_buffer) CFRelease(sample_buffer);
>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>> > }
>> > }
>> >
>> > -vtenc_q_push(vtctx, sample_buffer);
>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>> > }
>> >
>> > static int get_length_code_size(
>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>> > static int vtenc_cm_to_avpacket(
>> > AVCodecContext*avctx,
>> > CMSampleBufferRef sample_buffer,
>> > -AVPacket  *pkt)
>> > +AVPacket  *pkt,
>> > +ExtraSEI  *sei)
>> > {
>> > VTEncContext *vtctx = avctx->priv_data;
>> >
>> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
>> > size_t  header_size = 0;
>> > size_t  in_buf_size;
>> > size_t  out_buf_size;
>> > +size_t  sei_nalu_size = 0;
>> > int64_t dts_delta;
>> > int64_t time_base_num;
>> > int nalu_count;
>> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
>> > if(status)
>> > return status;
>> >
>> > +if (sei) {
>> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
>> > +}
>> > +
>> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
>> > out_buf_size = header_size +
>> >in_buf_size +
>> > +   sei_nalu_size +
>> >nalu_count * ((int)sizeof(start_code) - 
>> > (int)length_code_size);
>> >
>> > status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
>> > @@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
>> > 

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-19 Thread Aman Gupta
On Monday, September 19, 2016, Richard Kern  wrote:

>
> On Sep 10, 2016, at 10:33 PM, Aman Gupta  > wrote:
>
>
>
> On Sunday, September 11, 2016, Richard Kern  > wrote:
>
>>
>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta  wrote:
>> >
>> > From: Aman Gupta 
>> >
>> > ---
>> > libavcodec/videotoolboxenc.c | 76 ++
>> --
>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> > index 4345ca3..859dde9 100644
>> > --- a/libavcodec/videotoolboxenc.c
>> > +++ b/libavcodec/videotoolboxenc.c
>> > @@ -32,6 +32,7 @@
>> > #include "libavutil/pixdesc.h"
>> > #include "internal.h"
>> > #include 
>> > +#include "h264.h"
>> >
>> > #if !CONFIG_VT_BT2020
>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>> >
>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>> >
>> > +typedef struct ExtraSEI {
>> > +  void *data;
>> > +  size_t size;
>> > +} ExtraSEI;
>> > +
>> > typedef struct BufNode {
>> > CMSampleBufferRef cm_buffer;
>> > +ExtraSEI *sei;
>> > struct BufNode* next;
>> > int error;
>> > } BufNode;
>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>> > bool flushing;
>> > bool has_b_frames;
>> > bool warned_color_range;
>> > +bool a53_cc;
>> > } VTEncContext;
>> >
>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>> int err)
>> > pthread_mutex_unlock(>lock);
>> > }
>> >
>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf)
>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf, ExtraSEI **sei)
>> > {
>> > BufNode *info;
>> >
>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > pthread_mutex_unlock(>lock);
>> >
>> > *buf = info->cm_buffer;
>> > +if (sei && *buf) {
>> > +*sei = info->sei;
>> > +} else if (info->sei) {
>> > +if (info->sei->data) av_free(info->sei->data);
>> > +av_free(info->sei);
>> > +}
>> > av_free(info);
>> >
>> > vtctx->frame_ct_out++;
>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > return 0;
>> > }
>> >
>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>> buffer, ExtraSEI *sei)
>> > {
>> > BufNode *info = av_malloc(sizeof(BufNode));
>> > if (!info) {
>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>> CMSampleBufferRef buffer)
>> >
>> > CFRetain(buffer);
>> > info->cm_buffer = buffer;
>> > +info->sei = sei;
>> > info->next = NULL;
>> >
>> > pthread_mutex_lock(>lock);
>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>> > {
>> > AVCodecContext *avctx = ctx;
>> > VTEncContext   *vtctx = avctx->priv_data;
>> > +ExtraSEI *sei = sourceFrameCtx;
>> >
>> > if (vtctx->async_error) {
>> > if(sample_buffer) CFRelease(sample_buffer);
>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>> > }
>> > }
>> >
>> > -vtenc_q_push(vtctx, sample_buffer);
>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>> > }
>> >
>> > static int get_length_code_size(
>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>> > static int vtenc_cm_to_avpacket(
>> > AVCodecContext*avctx,
>> > CMSampleBufferRef sample_buffer,
>> > -AVPacket  *pkt)
>> > +AVPacket  *pkt,
>> > +ExtraSEI  *sei)
>> > {
>> > VTEncContext *vtctx = avctx->priv_data;
>> >
>> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
>> > size_t  header_size = 0;
>> > size_t  in_buf_size;
>> > size_t  out_buf_size;
>> > +size_t  sei_nalu_size = 0;
>> > int64_t dts_delta;
>> > int64_t time_base_num;
>> > int nalu_count;
>> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
>> > if(status)
>> > return status;
>> >
>> > +if (sei) {
>> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
>> > +}
>> > +
>> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
>> > out_buf_size = header_size +
>> >in_buf_size +
>> > +   sei_nalu_size +
>> >nalu_count * ((int)sizeof(start_code) -
>> (int)length_code_size);
>> >
>> > status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
>> > @@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
>> > length_code_size,
>> > sample_buffer,
>> > 

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-19 Thread Richard Kern

> On Sep 10, 2016, at 10:33 PM, Aman Gupta  wrote:
> 
> 
> 
> On Sunday, September 11, 2016, Richard Kern  > wrote:
> 
> > On Sep 8, 2016, at 4:19 AM, Aman Gupta > wrote:
> >
> > From: Aman Gupta >
> >
> > ---
> > libavcodec/videotoolboxenc.c | 76 
> > ++--
> > 1 file changed, 67 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> > index 4345ca3..859dde9 100644
> > --- a/libavcodec/videotoolboxenc.c
> > +++ b/libavcodec/videotoolboxenc.c
> > @@ -32,6 +32,7 @@
> > #include "libavutil/pixdesc.h"
> > #include "internal.h"
> > #include 
> > +#include "h264.h"
> >
> > #if !CONFIG_VT_BT2020
> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
> >
> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
> >
> > +typedef struct ExtraSEI {
> > +  void *data;
> > +  size_t size;
> > +} ExtraSEI;
> > +
> > typedef struct BufNode {
> > CMSampleBufferRef cm_buffer;
> > +ExtraSEI *sei;
> > struct BufNode* next;
> > int error;
> > } BufNode;
> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
> > bool flushing;
> > bool has_b_frames;
> > bool warned_color_range;
> > +bool a53_cc;
> > } VTEncContext;
> >
> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int 
> > err)
> > pthread_mutex_unlock(>lock);
> > }
> >
> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> > *buf)
> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> > *buf, ExtraSEI **sei)
> > {
> > BufNode *info;
> >
> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
> > CMSampleBufferRef *buf)
> > pthread_mutex_unlock(>lock);
> >
> > *buf = info->cm_buffer;
> > +if (sei && *buf) {
> > +*sei = info->sei;
> > +} else if (info->sei) {
> > +if (info->sei->data) av_free(info->sei->data);
> > +av_free(info->sei);
> > +}
> > av_free(info);
> >
> > vtctx->frame_ct_out++;
> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
> > CMSampleBufferRef *buf)
> > return 0;
> > }
> >
> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
> > ExtraSEI *sei)
> > {
> > BufNode *info = av_malloc(sizeof(BufNode));
> > if (!info) {
> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
> > CMSampleBufferRef buffer)
> >
> > CFRetain(buffer);
> > info->cm_buffer = buffer;
> > +info->sei = sei;
> > info->next = NULL;
> >
> > pthread_mutex_lock(>lock);
> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
> > {
> > AVCodecContext *avctx = ctx;
> > VTEncContext   *vtctx = avctx->priv_data;
> > +ExtraSEI *sei = sourceFrameCtx;
> >
> > if (vtctx->async_error) {
> > if(sample_buffer) CFRelease(sample_buffer);
> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
> > }
> > }
> >
> > -vtenc_q_push(vtctx, sample_buffer);
> > +vtenc_q_push(vtctx, sample_buffer, sei);
> > }
> >
> > static int get_length_code_size(
> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
> > static int vtenc_cm_to_avpacket(
> > AVCodecContext*avctx,
> > CMSampleBufferRef sample_buffer,
> > -AVPacket  *pkt)
> > +AVPacket  *pkt,
> > +ExtraSEI  *sei)
> > {
> > VTEncContext *vtctx = avctx->priv_data;
> >
> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
> > size_t  header_size = 0;
> > size_t  in_buf_size;
> > size_t  out_buf_size;
> > +size_t  sei_nalu_size = 0;
> > int64_t dts_delta;
> > int64_t time_base_num;
> > int nalu_count;
> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
> > if(status)
> > return status;
> >
> > +if (sei) {
> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
> > +}
> > +
> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
> > out_buf_size = header_size +
> >in_buf_size +
> > +   sei_nalu_size +
> >nalu_count * ((int)sizeof(start_code) - 
> > (int)length_code_size);
> >
> > status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
> > @@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
> > length_code_size,
> > sample_buffer,
> > pkt->data + header_size,
> > -pkt->size - header_size
> > +pkt->size - header_size - sei_nalu_size
> > );
> >
> > if (status) {
> > @@ -1325,6 +1348,19 @@ static int vtenc_cm_to_avpacket(
> > return status;
> > }
> >
> > +   

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-10 Thread Aman Gupta
On Sunday, September 11, 2016, Richard Kern  wrote:

>
> > On Sep 8, 2016, at 4:19 AM, Aman Gupta >
> wrote:
> >
> > From: Aman Gupta >
> >
> > ---
> > libavcodec/videotoolboxenc.c | 76 ++
> --
> > 1 file changed, 67 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> > index 4345ca3..859dde9 100644
> > --- a/libavcodec/videotoolboxenc.c
> > +++ b/libavcodec/videotoolboxenc.c
> > @@ -32,6 +32,7 @@
> > #include "libavutil/pixdesc.h"
> > #include "internal.h"
> > #include 
> > +#include "h264.h"
> >
> > #if !CONFIG_VT_BT2020
> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
> >
> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
> >
> > +typedef struct ExtraSEI {
> > +  void *data;
> > +  size_t size;
> > +} ExtraSEI;
> > +
> > typedef struct BufNode {
> > CMSampleBufferRef cm_buffer;
> > +ExtraSEI *sei;
> > struct BufNode* next;
> > int error;
> > } BufNode;
> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
> > bool flushing;
> > bool has_b_frames;
> > bool warned_color_range;
> > +bool a53_cc;
> > } VTEncContext;
> >
> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int
> err)
> > pthread_mutex_unlock(>lock);
> > }
> >
> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
> CMSampleBufferRef *buf)
> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
> CMSampleBufferRef *buf, ExtraSEI **sei)
> > {
> > BufNode *info;
> >
> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
> wait, CMSampleBufferRef *buf)
> > pthread_mutex_unlock(>lock);
> >
> > *buf = info->cm_buffer;
> > +if (sei && *buf) {
> > +*sei = info->sei;
> > +} else if (info->sei) {
> > +if (info->sei->data) av_free(info->sei->data);
> > +av_free(info->sei);
> > +}
> > av_free(info);
> >
> > vtctx->frame_ct_out++;
> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
> wait, CMSampleBufferRef *buf)
> > return 0;
> > }
> >
> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer,
> ExtraSEI *sei)
> > {
> > BufNode *info = av_malloc(sizeof(BufNode));
> > if (!info) {
> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
> CMSampleBufferRef buffer)
> >
> > CFRetain(buffer);
> > info->cm_buffer = buffer;
> > +info->sei = sei;
> > info->next = NULL;
> >
> > pthread_mutex_lock(>lock);
> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
> > {
> > AVCodecContext *avctx = ctx;
> > VTEncContext   *vtctx = avctx->priv_data;
> > +ExtraSEI *sei = sourceFrameCtx;
> >
> > if (vtctx->async_error) {
> > if(sample_buffer) CFRelease(sample_buffer);
> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
> > }
> > }
> >
> > -vtenc_q_push(vtctx, sample_buffer);
> > +vtenc_q_push(vtctx, sample_buffer, sei);
> > }
> >
> > static int get_length_code_size(
> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
> > static int vtenc_cm_to_avpacket(
> > AVCodecContext*avctx,
> > CMSampleBufferRef sample_buffer,
> > -AVPacket  *pkt)
> > +AVPacket  *pkt,
> > +ExtraSEI  *sei)
> > {
> > VTEncContext *vtctx = avctx->priv_data;
> >
> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
> > size_t  header_size = 0;
> > size_t  in_buf_size;
> > size_t  out_buf_size;
> > +size_t  sei_nalu_size = 0;
> > int64_t dts_delta;
> > int64_t time_base_num;
> > int nalu_count;
> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
> > if(status)
> > return status;
> >
> > +if (sei) {
> > +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
> > +}
> > +
> > in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
> > out_buf_size = header_size +
> >in_buf_size +
> > +   sei_nalu_size +
> >nalu_count * ((int)sizeof(start_code) -
> (int)length_code_size);
> >
> > status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
> > @@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
> > length_code_size,
> > sample_buffer,
> > pkt->data + header_size,
> > -pkt->size - header_size
> > +pkt->size - header_size - sei_nalu_size
> > );
> >
> > if (status) {
> > @@ -1325,6 +1348,19 @@ static int vtenc_cm_to_avpacket(
> > return status;
> > }
> >
> > +if (sei_nalu_size > 0) {
> > +uint8_t *sei_nalu = pkt->data + pkt->size - sei_nalu_size;
> > +  

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-10 Thread Richard Kern

> On Sep 8, 2016, at 4:19 AM, Aman Gupta  wrote:
> 
> From: Aman Gupta 
> 
> ---
> libavcodec/videotoolboxenc.c | 76 ++--
> 1 file changed, 67 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index 4345ca3..859dde9 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -32,6 +32,7 @@
> #include "libavutil/pixdesc.h"
> #include "internal.h"
> #include 
> +#include "h264.h"
> 
> #if !CONFIG_VT_BT2020
> # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
> @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
> 
> static const uint8_t start_code[] = { 0, 0, 0, 1 };
> 
> +typedef struct ExtraSEI {
> +  void *data;
> +  size_t size;
> +} ExtraSEI;
> +
> typedef struct BufNode {
> CMSampleBufferRef cm_buffer;
> +ExtraSEI *sei;
> struct BufNode* next;
> int error;
> } BufNode;
> @@ -94,6 +101,7 @@ typedef struct VTEncContext {
> bool flushing;
> bool has_b_frames;
> bool warned_color_range;
> +bool a53_cc;
> } VTEncContext;
> 
> static int vtenc_populate_extradata(AVCodecContext   *avctx,
> @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int err)
> pthread_mutex_unlock(>lock);
> }
> 
> -static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> *buf)
> +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> *buf, ExtraSEI **sei)
> {
> BufNode *info;
> 
> @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
> CMSampleBufferRef *buf)
> pthread_mutex_unlock(>lock);
> 
> *buf = info->cm_buffer;
> +if (sei && *buf) {
> +*sei = info->sei;
> +} else if (info->sei) {
> +if (info->sei->data) av_free(info->sei->data);
> +av_free(info->sei);
> +}
> av_free(info);
> 
> vtctx->frame_ct_out++;
> @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
> CMSampleBufferRef *buf)
> return 0;
> }
> 
> -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
> +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
> ExtraSEI *sei)
> {
> BufNode *info = av_malloc(sizeof(BufNode));
> if (!info) {
> @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
> CMSampleBufferRef buffer)
> 
> CFRetain(buffer);
> info->cm_buffer = buffer;
> +info->sei = sei;
> info->next = NULL;
> 
> pthread_mutex_lock(>lock);
> @@ -420,6 +435,7 @@ static void vtenc_output_callback(
> {
> AVCodecContext *avctx = ctx;
> VTEncContext   *vtctx = avctx->priv_data;
> +ExtraSEI *sei = sourceFrameCtx;
> 
> if (vtctx->async_error) {
> if(sample_buffer) CFRelease(sample_buffer);
> @@ -440,7 +456,7 @@ static void vtenc_output_callback(
> }
> }
> 
> -vtenc_q_push(vtctx, sample_buffer);
> +vtenc_q_push(vtctx, sample_buffer, sei);
> }
> 
> static int get_length_code_size(
> @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
> static int vtenc_cm_to_avpacket(
> AVCodecContext*avctx,
> CMSampleBufferRef sample_buffer,
> -AVPacket  *pkt)
> +AVPacket  *pkt,
> +ExtraSEI  *sei)
> {
> VTEncContext *vtctx = avctx->priv_data;
> 
> @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
> size_t  header_size = 0;
> size_t  in_buf_size;
> size_t  out_buf_size;
> +size_t  sei_nalu_size = 0;
> int64_t dts_delta;
> int64_t time_base_num;
> int nalu_count;
> @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
> if(status)
> return status;
> 
> +if (sei) {
> +sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
> +}
> +
> in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
> out_buf_size = header_size +
>in_buf_size +
> +   sei_nalu_size +
>nalu_count * ((int)sizeof(start_code) - 
> (int)length_code_size);
> 
> status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
> @@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
> length_code_size,
> sample_buffer,
> pkt->data + header_size,
> -pkt->size - header_size
> +pkt->size - header_size - sei_nalu_size
> );
> 
> if (status) {
> @@ -1325,6 +1348,19 @@ static int vtenc_cm_to_avpacket(
> return status;
> }
> 
> +if (sei_nalu_size > 0) {
> +uint8_t *sei_nalu = pkt->data + pkt->size - sei_nalu_size;
> +memcpy(sei_nalu, start_code, sizeof(start_code));
> +sei_nalu += sizeof(start_code);
> +sei_nalu[0] = NAL_SEI;
> +sei_nalu[1] = SEI_TYPE_USER_DATA_REGISTERED;
> +sei_nalu[2] = sei->size;
> +sei_nalu += 3;
> +memcpy(sei_nalu, sei->data, sei->size);
> +sei_nalu += sei->size;
> +sei_nalu[0] = 1; // RBSP
> +

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Aman Gupta
On Thu, Sep 8, 2016 at 9:18 AM, Carl Eugen Hoyos  wrote:

> 2016-09-08 15:48 GMT+02:00 Aman Gupta :
> > On Thursday, September 8, 2016, Carl Eugen Hoyos 
> wrote:
> >
> >> 2016-09-08 10:19 GMT+02:00 Aman Gupta >:
> >>
> >> > +{ "a53cc", "Use A53 Closed Captions (if available)",
> >> OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE },
> >>
> >> Why is this disabled by default?
> >
> > I copied this from the libx264 and qsv encoders, which also disable by
> > default. Not sure why.
>
> If you believe it should be enabled by default, please send a patch that
> enables the function by default.
> (If there is no issue, the others can be fixed.)
>

I don't have a good enough understanding of the possible consequences to
feel comfortable enabling it by default yet.


>
> Thank you, Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Carl Eugen Hoyos
2016-09-08 15:48 GMT+02:00 Aman Gupta :
> On Thursday, September 8, 2016, Carl Eugen Hoyos  wrote:
>
>> 2016-09-08 10:19 GMT+02:00 Aman Gupta >:
>>
>> > +{ "a53cc", "Use A53 Closed Captions (if available)",
>> OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE },
>>
>> Why is this disabled by default?
>
> I copied this from the libx264 and qsv encoders, which also disable by
> default. Not sure why.

If you believe it should be enabled by default, please send a patch that
enables the function by default.
(If there is no issue, the others can be fixed.)

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Aman Gupta
On Thursday, September 8, 2016, Carl Eugen Hoyos  wrote:

> 2016-09-08 10:19 GMT+02:00 Aman Gupta >:
>
> > +{ "a53cc", "Use A53 Closed Captions (if available)",
> OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE },
>
> Why is this disabled by default?


I copied this from the libx264 and qsv encoders, which also disable by
default. Not sure why.


>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org 
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Carl Eugen Hoyos
2016-09-08 10:19 GMT+02:00 Aman Gupta :

> +{ "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), 
> AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE },

Why is this disabled by default?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Aman Gupta
From: Aman Gupta 

---
 libavcodec/videotoolboxenc.c | 76 ++--
 1 file changed, 67 insertions(+), 9 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 4345ca3..859dde9 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -32,6 +32,7 @@
 #include "libavutil/pixdesc.h"
 #include "internal.h"
 #include 
+#include "h264.h"
 
 #if !CONFIG_VT_BT2020
 # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
@@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
 
 static const uint8_t start_code[] = { 0, 0, 0, 1 };
 
+typedef struct ExtraSEI {
+  void *data;
+  size_t size;
+} ExtraSEI;
+
 typedef struct BufNode {
 CMSampleBufferRef cm_buffer;
+ExtraSEI *sei;
 struct BufNode* next;
 int error;
 } BufNode;
@@ -94,6 +101,7 @@ typedef struct VTEncContext {
 bool flushing;
 bool has_b_frames;
 bool warned_color_range;
+bool a53_cc;
 } VTEncContext;
 
 static int vtenc_populate_extradata(AVCodecContext   *avctx,
@@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int err)
 pthread_mutex_unlock(>lock);
 }
 
-static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf)
+static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, 
ExtraSEI **sei)
 {
 BufNode *info;
 
@@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
CMSampleBufferRef *buf)
 pthread_mutex_unlock(>lock);
 
 *buf = info->cm_buffer;
+if (sei && *buf) {
+*sei = info->sei;
+} else if (info->sei) {
+if (info->sei->data) av_free(info->sei->data);
+av_free(info->sei);
+}
 av_free(info);
 
 vtctx->frame_ct_out++;
@@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
CMSampleBufferRef *buf)
 return 0;
 }
 
-static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
+static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
ExtraSEI *sei)
 {
 BufNode *info = av_malloc(sizeof(BufNode));
 if (!info) {
@@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
CMSampleBufferRef buffer)
 
 CFRetain(buffer);
 info->cm_buffer = buffer;
+info->sei = sei;
 info->next = NULL;
 
 pthread_mutex_lock(>lock);
@@ -420,6 +435,7 @@ static void vtenc_output_callback(
 {
 AVCodecContext *avctx = ctx;
 VTEncContext   *vtctx = avctx->priv_data;
+ExtraSEI *sei = sourceFrameCtx;
 
 if (vtctx->async_error) {
 if(sample_buffer) CFRelease(sample_buffer);
@@ -440,7 +456,7 @@ static void vtenc_output_callback(
 }
 }
 
-vtenc_q_push(vtctx, sample_buffer);
+vtenc_q_push(vtctx, sample_buffer, sei);
 }
 
 static int get_length_code_size(
@@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
 static int vtenc_cm_to_avpacket(
 AVCodecContext*avctx,
 CMSampleBufferRef sample_buffer,
-AVPacket  *pkt)
+AVPacket  *pkt,
+ExtraSEI  *sei)
 {
 VTEncContext *vtctx = avctx->priv_data;
 
@@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
 size_t  header_size = 0;
 size_t  in_buf_size;
 size_t  out_buf_size;
+size_t  sei_nalu_size = 0;
 int64_t dts_delta;
 int64_t time_base_num;
 int nalu_count;
@@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
 if(status)
 return status;
 
+if (sei) {
+sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
+}
+
 in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
 out_buf_size = header_size +
in_buf_size +
+   sei_nalu_size +
nalu_count * ((int)sizeof(start_code) - 
(int)length_code_size);
 
 status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
@@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
 length_code_size,
 sample_buffer,
 pkt->data + header_size,
-pkt->size - header_size
+pkt->size - header_size - sei_nalu_size
 );
 
 if (status) {
@@ -1325,6 +1348,19 @@ static int vtenc_cm_to_avpacket(
 return status;
 }
 
+if (sei_nalu_size > 0) {
+uint8_t *sei_nalu = pkt->data + pkt->size - sei_nalu_size;
+memcpy(sei_nalu, start_code, sizeof(start_code));
+sei_nalu += sizeof(start_code);
+sei_nalu[0] = NAL_SEI;
+sei_nalu[1] = SEI_TYPE_USER_DATA_REGISTERED;
+sei_nalu[2] = sei->size;
+sei_nalu += 3;
+memcpy(sei_nalu, sei->data, sei->size);
+sei_nalu += sei->size;
+sei_nalu[0] = 1; // RBSP
+}
+
 if (is_key_frame) {
 pkt->flags |= AV_PKT_FLAG_KEY;
 }
@@ -1707,6 +1743,7 @@ static int vtenc_send_frame(AVCodecContext *avctx,
 CMTime time;
 CFDictionaryRef frame_dict;
 CVPixelBufferRef cv_img = NULL;
+ExtraSEI *sei = NULL;
 int status =