[Libav-user] Extract AVFrameSideData

lyncher at sapo.pt lyncher at sapo.pt
Fri Jun 7 19:42:18 EEST 2019


The code that I have:

>
>
> #include "libavutil/opt.h"
> #include "avcodec.h"
> #include "internal.h"
>
> typedef struct A53EncodeContext {
>     const AVClass *class;
> } A53EncodeContext;
>
>
> static int a53cc_encode(AVCodecContext *avctx, AVPacket *avpkt, const 
> AVFrame *frame, int *got_packet_ptr)
> {
>     A53EncodeContext *ctx = avctx->priv_data;
>
>     int ret;
>
>     for (int i = 0; i < frame->nb_side_data; i++) {
>         AVFrameSideData *sd = frame->side_data[i];
>
>         av_log(ctx, AV_LOG_INFO, "  side data - ");
>         if (sd->type == AV_FRAME_DATA_A53_CC) {
>
>             //Create AVPacket to hold extracted CC
>             if ((ret = ff_alloc_packet2(avctx, avpkt, sd->size, 0)) < 0) {
>                 *got_packet_ptr = 0;
>                 return ret;
>             }
>
>             //Copy CC packet
>             memcpy(avpkt->data, sd->data, sd->size);
>             avpkt->stream_index = 0;
>             avpkt->pts = frame->pts;
>             avpkt->pos = frame->pkt_pos;
>
>             av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d 
> bytes)\n", sd->size);
>             for (int offset = 0; offset < sd->size; offset++) {
>                 av_log(ctx, AV_LOG_INFO, "%0x", sd->data[offset]);
>             }
>
>             *got_packet_ptr = 1;
>             return 0;
>         }
>
>         av_log(ctx, AV_LOG_INFO, "\n");
>     }
>
>
>     *got_packet_ptr = 0;
>     return 0;
> }
>
>
> #define OFFSET(x) offsetof(A53EncodeContext, x)
> #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> static const AVOption a53cc_options[] = {
>     { NULL },
> };
>
> static const AVClass a53ccenc_class = {
>     .class_name = "A53 caption encoder",
>     .item_name  = av_default_item_name,
>     .option     = a53cc_options,
>     .version    = LIBAVUTIL_VERSION_INT,
> };
>
> AVCodec ff_a53cc_encoder = {
>     .name           = "a53cc",
>     .long_name      = NULL_IF_CONFIG_SMALL("A/53 captions"),
>     .type           = AVMEDIA_TYPE_VIDEO,
>     .id             = AV_CODEC_ID_EIA_608,
>     //.init           = a53cc_init,
>     .encode2        = a53cc_encode,
>     .priv_class     = &a53ccenc_class,
>     .priv_data_size = sizeof(A53EncodeContext),
> };
>

lyncher

On 07-06-2019 17:16, Devin Heitmueller wrote:
> Hi Lyncher,
>
> On Fri, Jun 7, 2019 at 11:48 AM <lyncher at sapo.pt> wrote:
>> I'm not getting how can I define the codec ID to an AVPacket.....
>> Should I set something at AVCodecContext?
> So those fields are not describing the AVPacket.  They're describing
> the codec.  That said, the codec itself has three different references
> to the AVMediaType (the codec description, codec context, and codec
> parameters).  While I know it uses at least one of those to know what
> type of AVFrames can be dispatched to it (e.g. to prevent you from
> sending audio AVFrames to a video encoder), I'm not sure which the .id
> field ties directly to, or what happens if all three of those values
> aren't the same.  At least the codec parameters needs to reflect the
> subtitle type in order for subtitle decoders such as ccaption_dec to
> be able to accept packets from it.
>
> Interesting.  I would have to do some experimentation to see what the
> right path is here.
>
> Devin
>



More information about the Libav-user mailing list