History

doc/examples/decoding_encoding: fix storing all channels

Fixes Ticket3355

Michael Niedermayer committed 11 years ago

Commit e6ea75c1 parent 9e1cfbd1 file · +6 −5Browse files

Showing the changes to doc/examples/decoding_encoding.c (1 of 1 file). Show all

Unified · Split

doc/examples/decoding_encoding.c+6−5
@@ -288,6 +288,7 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 287 unmodified lines
288288 avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
289289
290290 while (avpkt.size > 0) {
291+ int i, ch;
291292 int got_frame = 0;
292293
293294 if (!decoded_frame) {
@@ -304,15 +305,15 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 10 unmodified lines
304305 }
305306 if (got_frame) {
306307 /* if a frame has been decoded, output it */
307− int data_size = av_samples_get_buffer_size(NULL, c->channels,
308− decoded_frame->nb_samples,
309− c->sample_fmt, 1);
308+ int data_size = av_get_bytes_per_sample(c->sample_fmt);
310309 if (data_size < 0) {
311310 /* This should not occur, checking just for paranoia */
312311 fprintf(stderr, "Failed to calculate data size\n");
313312 exit(1);
314313 }
315− fwrite(decoded_frame->data[0], 1, data_size, outfile);
314+ for (i=0; i<decoded_frame->nb_samples; i++)
315+ for (ch=0; ch<c->channels; ch++)
316+ fwrite(decoded_frame->data[ch] + data_size*i, 1, data_size, outfile);
316317 }
317318 avpkt.size -= len;
318319 avpkt.data += len;
@@ -650,7 +651,7 @@ int main(int argc, char **argv) · 331 unmodified lines
650651 video_encode_example("test.h264", AV_CODEC_ID_H264);
651652 } else if (!strcmp(output_type, "mp2")) {
652653 audio_encode_example("test.mp2");
653− audio_decode_example("test.sw", "test.mp2");
654+ audio_decode_example("test.pcm", "test.mp2");
654655 } else if (!strcmp(output_type, "mpg")) {
655656 video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO);
656657 video_decode_example("test%02d.pgm", "test.mpg");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t