[Libav-user] AAC encoder not returning final samples

applemax82 applemax82 at 163.com
Fri Aug 21 19:35:12 CEST 2015


Hi,

I have the same issue.

At the beginning, aac encoder doesn't output coded data for the first two frames, which means encoder begins to output coded data from 3rd frame. In the end, all audio samples are sent to aac encoder, but coded data of last samples are not output yet.

I know how to flush delayed frames in h264 encoder, i.e. flush operation uses avcodec_encode_video()/avcodec_encode_video2() like encoding operation. But avcodec_encode_audio()/avcodec_encode_audio2()  can't flushed delayed samples in aac encoder, as aac encoder doesn't have the AV_CODEC_CAP_DELAY capability set.

'int avcodec_encode_audio2( AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr ) ' is the function of encoding a audio frame. If 3rd argument frame is set to NULL, aac encoder won't flush delayed samples, as aac encoder doesn't have the AV_CODEC_CAP_DELAY capability set.

Which ffmpeg function can flush delayed aac samples? How to flush those samples?

I have tried one way to flush those samples. Having sent all audio frames to aac encoder, I continue send to aac encoder several frames which have samples with zero value. AAC does send coded data of delayed samples, but I don't think it is good to flush aac encoder.

Is there better way to flush aac encoder?

andrew

From: Panicos Karkallis
Date: 2015-08-22 00:44
To: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
Subject: Re: [Libav-user] AAC encoder not returning final samples
I do flush the encoder by passing a null frame. it returns 2 packets that get appended at the beginning of my file and increase the padding instead of giving the end samples.
Panicos


On 17:34, Fri, 21 Aug 2015 Henry, David <David.Henry at echostar.com> wrote:

> I am new to ffmpeg/avlib and what I am trying to do is just decode and encode back again an aac file. I don't try to make any changes to the file although the avlib encoder is producing a file with more initial padding than expected and it is cropping the final frames of the audio clip.
> I exported the avframes created by the decoder and all the file information is there. It is at the encoding step that I am doing something wrong.


It sounds like you are not flushing the libfdk-aac encoder at the end.  The encoder holds on to audio samples internally while you are encoding and you need to flush those last samples
When you are finished encoding.
- David
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20150822/71a9eeba/attachment.html>


More information about the Libav-user mailing list