Fixes Ticket3355
Showing the changes to doc/examples/decoding_encoding.c (1 of 1 file). Show all
Unified · Split
| @@ -288,6 +288,7 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 287 unmodified lines | |||
| 288 | avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); | 288 | avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); |
| 289 | 289 | ||
| 290 | while (avpkt.size > 0) { | 290 | while (avpkt.size > 0) { |
| 291 | int i, ch; | ||
| 291 | int got_frame = 0; | 292 | int got_frame = 0; |
| 292 | 293 | ||
| 293 | if (!decoded_frame) { | 294 | if (!decoded_frame) { |
| @@ -304,15 +305,15 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 10 unmodified lines | |||
| 304 | } | 305 | } |
| 305 | if (got_frame) { | 306 | if (got_frame) { |
| 306 | /* if a frame has been decoded, output it */ | 307 | /* if a frame has been decoded, output it */ |
| 307 | int data_size = av_samples_get_buffer_size(NULL, c->channels, | 308 | int data_size = av_get_bytes_per_sample(c->sample_fmt); |
| 308 | decoded_frame->nb_samples, | ||
| 309 | c->sample_fmt, 1); | ||
| 310 | if (data_size < 0) { | 309 | if (data_size < 0) { |
| 311 | /* This should not occur, checking just for paranoia */ | 310 | /* This should not occur, checking just for paranoia */ |
| 312 | fprintf(stderr, "Failed to calculate data size\n"); | 311 | fprintf(stderr, "Failed to calculate data size\n"); |
| 313 | exit(1); | 312 | exit(1); |
| 314 | } | 313 | } |
| 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); | ||
| 316 | } | 317 | } |
| 317 | avpkt.size -= len; | 318 | avpkt.size -= len; |
| 318 | avpkt.data += len; | 319 | avpkt.data += len; |
| @@ -650,7 +651,7 @@ int main(int argc, char **argv) · 331 unmodified lines | |||
| 650 | video_encode_example("test.h264", AV_CODEC_ID_H264); | 651 | video_encode_example("test.h264", AV_CODEC_ID_H264); |
| 651 | } else if (!strcmp(output_type, "mp2")) { | 652 | } else if (!strcmp(output_type, "mp2")) { |
| 652 | audio_encode_example("test.mp2"); | 653 | audio_encode_example("test.mp2"); |
| 653 | audio_decode_example("test.sw", "test.mp2"); | 654 | audio_decode_example("test.pcm", "test.mp2"); |
| 654 | } else if (!strcmp(output_type, "mpg")) { | 655 | } else if (!strcmp(output_type, "mpg")) { |
| 655 | video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO); | 656 | video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO); |
| 656 | video_decode_example("test%02d.pgm", "test.mpg"); | 657 | video_decode_example("test%02d.pgm", "test.mpg"); |