[FFmpeg-devel] How to make a mp4 file have AVCC box

Yufei He yhe at matrox.com
Thu Mar 7 19:38:23 EET 2019


Hi

I have a problem that the trancoded MP4 file does not have valid AVCC box. It's supposed to have the extradata from the codec.

I can only get the extradata after I receive the first encoded frame, while I don't have any frame in my encoder's init function.

It seems ffmpeg can only generate AVCC box if I set extradata in my encoder's init function, it does not take the extradata if I make it in receive_packet function.

Please help.

Thanks.

Yufei.
if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER && !avctx->extradata) {
const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
ret = av_bsf_alloc(filter, &ctx);
if (ret < 0)
return ret;
ret = avcodec_parameters_from_context(ctx->par_in, avctx);
if (ret < 0)
return ret;
ret = av_bsf_init(ctx);
if (ret < 0)
return ret;
ctx->time_base_in = avctx->time_base;
ret = av_bsf_send_packet(ctx, avpkt);
if (ret < 0)
return ret;
ret = av_bsf_receive_packet(ctx, avpkt);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return 0;
if (avpkt->side_data_elems > 0 )
{
avctx->extradata = av_mallocz(avpkt->side_data->size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);
memcpy(avctx->extradata, avpkt->side_data->data, avpkt->side_data->size);
avctx->extradata_size = avpkt->side_data->size;
}
av_bsf_free(&ctx);
}

On 03/06/2019 02:10 PM, James Almer wrote:

On 3/6/2019 4:04 PM, Yufei He wrote:


Hi

I want to use   ff_extract_extradata_bsf to get extradata from a h.264 frame.

Here is the code.

AVPacket *avpkt; // there is valid data.
AVBSFContext *ctx = NULL;
ret = av_bsf_alloc(&ff_extract_extradata_bsf, &ctx);
ret = ff_extract_extradata_bsf.init(ctx);
ret = ff_extract_extradata_bsf.filter(ctx, avpkt);

ff_extract_extradata_bsf.filter failed on calling ff_bsf_get_packet_ref because  ctx->internal->buffer+pkt->data is NULL.

int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
{
AVBSFInternal *in = ctx->internal;
if (in->eof)
return AVERROR_EOF;
if (!ctx->internal->buffer_pkt->data &&
!ctx->internal->buffer_pkt->side_data_elems)
return AVERROR(EAGAIN);

How should ctx->internal->buffer+pkt->data be set?

Thanks.

Yufei.


You're not using the bsf API correctly. You're accessing internal
callbacks like init() and filter() directly. Use the public functions
defined in avcodec.h, and look at usage examples like in ffmpeg.c if needed.

Also, any further questions or emails about this should go to the
libav-user list at https://lists.ffmpeg.org/mailman/listinfo/libav-user/
This list is for actual ffmpeg development, not for usage questions.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org<mailto:ffmpeg-devel at ffmpeg.org>
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel




More information about the ffmpeg-devel mailing list