summaryrefslogtreecommitdiff
path: root/doc/examples/decoding_encoding.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-12-06 01:37:27 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-12-06 01:37:27 +0100
commitb404ab9e74d3bca12d5989c366f5cfd746279067 (patch)
treefdbba6fdf7a4694fe7b7ecda6401ea6a2e01f95e /doc/examples/decoding_encoding.c
parenta448a5d1c4620aa58ec138fbffd46d18d42d53e0 (diff)
parent52401b82bd2ed30d4c4353cb084bf4ee679d0c22 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: mov: Don't av_malloc(0). avconv: only allocate 1 AVFrame per input stream avconv: fix memleaks due to not freeing the AVFrame for audio h264-fate: remove -strict 1 except where necessary (mr4/5-tandberg). misc Doxygen markup improvements doxygen: eliminate Qt-style doxygen syntax g722: Add a regression test for muxing/demuxing in wav g722: Change bits per sample to 4 g722dec: Signal skipping the lower bits via AVOptions instead of bits_per_coded_sample api-example: update to use avcodec_decode_audio4() avplay: use avcodec_decode_audio4() avplay: use a separate buffer for playing silence avformat: use avcodec_decode_audio4() in avformat_find_stream_info() avconv: use avcodec_decode_audio4() instead of avcodec_decode_audio3() mov: Allow empty stts atom. doc: document preferred Doxygen syntax and make patcheck detect it Conflicts: avconv.c ffplay.c libavcodec/mlpdec.c libavcodec/version.h libavformat/mov.c tests/codec-regression.sh tests/fate/h264.mak Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'doc/examples/decoding_encoding.c')
-rw-r--r--doc/examples/decoding_encoding.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/doc/examples/decoding_encoding.c b/doc/examples/decoding_encoding.c
index ee0cb585f5..f87a8c9c41 100644
--- a/doc/examples/decoding_encoding.c
+++ b/doc/examples/decoding_encoding.c
@@ -33,6 +33,7 @@
#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavutil/mathematics.h"
+#include "libavutil/samplefmt.h"
#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
@@ -114,11 +115,11 @@ 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;
+ AVFrame *decoded_frame = NULL;
av_init_packet(&avpkt);
@@ -139,8 +140,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);
@@ -157,15 +156,27 @@ 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);
+ int got_frame = 0;
+
+ if (!decoded_frame) {
+ if (!(decoded_frame = avcodec_alloc_frame())) {
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+ }
+ } else
+ avcodec_get_frame_defaults(decoded_frame);
+
+ 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 = av_samples_get_buffer_size(NULL, c->channels,
+ decoded_frame->nb_samples,
+ c->sample_fmt, 1);
+ fwrite(decoded_frame->data[0], 1, data_size, outfile);
}
avpkt.size -= len;
avpkt.data += len;
@@ -185,10 +196,10 @@ static void audio_decode_example(const char *outfilename, const char *filename)
fclose(outfile);
fclose(f);
- free(outbuf);
avcodec_close(c);
av_free(c);
+ av_free(decoded_frame);
}
/*