I have the following code to encode an audio stream and everything seems to be working fine until I get to the avcodec_encode_audio2 function, I am failing with -22 error code, and I dont know what that error code means. I verified that pFrame and out_fmt_ctx are allocated. Does anyone have an idea of what the problem might be?
Thanks in advance!
while( res = av_read_frame( pFormatCtx, &packet ) >=0 )
{
if ( packet.stream_index == audioStream )
{
avcodec_get_frame_defaults(pFrame);
ret = avcodec_decode_audio4(dec_ctx, pFrame, &got_frame, &packet);
if (ret < 0)
{
return ret;
}
/* Set frame pts */
pFrame->pts = av_frame_get_best_effort_timestamp(pFrame);
if (got_frame)
{
AVPacket audioEncodedPacket;
av_init_packet(&audioEncodedPacket);
ret = avcodec_encode_audio2(out_fmt_ctx->streams[0]->codec,
&audioEncodedPacket,
pFrame, &got_packet);
if ( ret < 0 )
{
//THIS IS WHERE I AM GOING WITH ERROR -22
}
}
...... // more code
}