[Libav-user] Error DNxHD encoding with libavcodec 57.107.100
Francesco, Cuzzocrea
francesco at bltitalia.com
Tue Nov 14 16:33:35 EET 2017
Hi to all
anyone experienced and error encodinc with latest version of
libavcodec? The code that works perfectly with
version 57.24.102 doesn't work with latest one. The error is "Invalid
argument": Here is the code:
AVCodec *pcodec_xd;
AVCodecContext *pCodecCtx_xd;
AVFrame *pFrame_xd;
AVFormatContext* _avFormatContext_xd;
AVDictionary *av_option=NULL;
AVPacket thpkt;
int smerr=0, gotp;
AnsiString str1,stre;
AVRational vform;
unsigned long drt= 120000000;
int xd_pkt_mxf_pts=0;
char str_err[256];
pcodec_xd = avcodec_find_encoder(AV_CODEC_ID_DNXHD);
if (!pcodec_xd) { stre.printf("Unable to find codec MPEG2"); smerr =
-4; goto stp_b2mx;}
pCodecCtx_xd = avcodec_alloc_context3(pcodec_xd);
if (pCodecCtx_xd==NULL) { stre.printf("Unable to alloc codec
context");smerr = -5; goto stp_b2mx;}
pFrame_xd = av_frame_alloc();
if (pFrame_xd==NULL) { stre.printf("Unable to alloc frame");smerr =
-6; goto stp_b2mx;}
if(av_image_alloc(pFrame_xd->data,
pFrame_xd->linesize,1920,1080,AV_PIX_FMT_YUV422P,16)<0)
{ stre.printf("Unable to alloc image");goto stp_b2mx;}
pFrame_xd->interlaced_frame = 1; pFrame_xd->top_field_first = 1;
pFrame_xd->qscale_type = 1;
pCodecCtx_xd->flags = CODEC_FLAG_INTERLACED_DCT;
pCodecCtx_xd->gop_size=1; pCodecCtx_xd->max_b_frames=0;
pCodecCtx_xd->height =1080;
vform.num=1;vform.den=1;
pCodecCtx_xd->sample_aspect_ratio = vform;
pCodecCtx_xd->rc_max_rate=pCodecCtx_xd->rc_min_rate=pCodecCtx_xd->bit_rate=drt;
pCodecCtx_xd->time_base.num= 1;
pCodecCtx_xd->time_base.den== 25;
pCodecCtx_xd->pix_fmt=AV_PIX_FMT_YUV422P; ///< planar YUV 4:2:2,
16bpp, (1 Cr & Cb sample per 2x1 Y samples)
pCodecCtx_xd->thread_count=4;
pCodecCtx_xd->width=1920;
pCodecCtx_xd->framerate.num = 25;
pCodecCtx_xd->framerate.den = 1;
smerr =
av_opt_set(pCodecCtx_xd->priv_data,"profile","dnxhd",AV_OPT_SEARCH_CHILDREN);
if(smerr<0)
{ if(av_strerror(smerr,str_err,256)==0){ stre.printf("Error (%s)
setting option",str_err); }
else { stre.printf("Error (%d) returned from
av_opt_set",smerr); }
goto stp_b2mx;
}
if (!avcodec_is_open(pCodecCtx_xd))
{
smerr = avcodec_open2(pCodecCtx_xd, pcodec_xd,&av_option);
if ( smerr < 0)
{
if(av_strerror(smerr,str_err,256)==0){ stre.printf("Error opening
codec : %s",str_err); }
else { stre.printf("Error (%d) opening codec",smerr); }
goto stp_b2mx;
}
}
av_init_packet(&thpkt);
smerr = avcodec_send_frame(pCodecCtx_xd, pFrame_xd);
if(smerr<0)
{
if(av_strerror(smerr,str_err,256)==0){ stre.printf("Error returned
from avcodec_send_frame (%s)",str_err); }
else { stre.printf("Error (%d) returned from
avcodec_send_frame",smerr); }
goto stp_b2mx;
}
smerr = avcodec_receive_packet(pCodecCtx_xd, &thpkt);
if(smerr<0)
{
if(av_strerror(smerr,str_err,256)==0){ stre.printf("Error returned
from avcodec_receive_packet (%s)",str_err); }
else { stre.printf("Error (%d) returned from
avcodec_receive_packet",smerr); }
goto stp_b2mx;
}
All works fine till sending packet. At thispoint the error returned is
invalid data. Same code works with previous versions.
Any suggestions ?
regards
Francesco
More information about the Libav-user
mailing list