---
libavcodec/api-example.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/libavcodec/api-example.c b/libavcodec/api-example.c
index ec71b0d..d9472b9 100644
--- a/libavcodec/api-example.c
+++ b/libavcodec/api-example.c
@@ -118,9 +118,8 @@ static void audio_decode_example(const char *outfilename,
const char *filename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
- int out_size, len;
+ int len;
FILE *f, *outfile;
- uint8_t *outbuf;
uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
@@ -143,8 +142,6 @@ static void audio_decode_example(const char *outfilename,
const char *filename)
exit(1);
}
- outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
-
f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "could not open %s\n", filename);
@@ -161,15 +158,19 @@ static void audio_decode_example(const char *outfilename,
const char *filename)
avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
while (avpkt.size > 0) {
- out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
- len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);
+ AVFrame decoded_frame;
+ int got_frame = 0;
+
+ len = avcodec_decode_audio4(c, &decoded_frame, &got_frame, &avpkt);
if (len < 0) {
fprintf(stderr, "Error while decoding\n");
exit(1);
}
- if (out_size > 0) {
+ if (got_frame) {
/* if a frame has been decoded, output it */
- fwrite(outbuf, 1, out_size, outfile);
+ int data_size = decoded_frame.nb_samples * c->channels *
+ av_get_bytes_per_sample(c->sample_fmt);
+ fwrite(decoded_frame.data[0], 1, data_size, outfile);
}
avpkt.size -= len;
avpkt.data += len;
@@ -189,7 +190,6 @@ static void audio_decode_example(const char *outfilename,
const char *filename)
fclose(outfile);
fclose(f);
- free(outbuf);
avcodec_close(c);
av_free(c);
--
1.7.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel