From: Clément Bœsch Date: Wed, 29 Mar 2017 11:31:44 +0000 (+0200) Subject: Merge commit 'f76698e759a08e8d3b629c06edb0439f474e7fee' X-Git-Tag: n3.4-dev~209 X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/commitdiff_plain/780cc080d85656429ba97426f35c7bc1f7f201bb Merge commit 'f76698e759a08e8d3b629c06edb0439f474e7fee' * commit 'f76698e759a08e8d3b629c06edb0439f474e7fee': examples/encode_audio: use the AVFrame API for allocating the data Merged-by: Clément Bœsch --- 780cc080d85656429ba97426f35c7bc1f7f201bb diff --cc doc/examples/encode_audio.c index b788775,db2440f..f3bb102 --- a/doc/examples/encode_audio.c +++ b/doc/examples/encode_audio.c @@@ -165,25 -158,10 +164,10 @@@ int main(int argc, char **argv frame->format = c->sample_fmt; frame->channel_layout = c->channel_layout; - /* the codec gives us the frame size, in samples, - * we calculate the size of the samples buffer in bytes */ - buffer_size = av_samples_get_buffer_size(NULL, c->channels, c->frame_size, - c->sample_fmt, 0); - if (buffer_size < 0) { - fprintf(stderr, "Could not get sample buffer size\n"); - exit(1); - } - samples = av_malloc(buffer_size); - if (!samples) { - fprintf(stderr, "Could not allocate %d bytes for samples buffer\n", - buffer_size); - exit(1); - } - /* setup the data pointers in the AVFrame */ - ret = avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, - (const uint8_t*)samples, buffer_size, 0); + /* allocate the data buffers */ + ret = av_frame_get_buffer(frame, 0); if (ret < 0) { - fprintf(stderr, "Could not setup audio frame\n"); - fprintf(stderr, "could not allocate audio data buffers\n"); ++ fprintf(stderr, "Could not allocate audio data buffers\n"); exit(1); } @@@ -213,23 -198,8 +204,22 @@@ av_packet_unref(&pkt); } } + + /* get the delayed frames */ + for (got_output = 1; got_output; i++) { + ret = avcodec_encode_audio2(c, &pkt, NULL, &got_output); + if (ret < 0) { + fprintf(stderr, "Error encoding frame\n"); + exit(1); + } + + if (got_output) { + fwrite(pkt.data, 1, pkt.size, f); + av_packet_unref(&pkt); + } + } fclose(f); - av_freep(&samples); av_frame_free(&frame); avcodec_free_context(&c); }