Patch by Thilo Borgmann name.surname AT googlemail.com. Originally committed as revision 18409 to svn://svn.ffmpeg.org/ffmpeg/trunk
Showing the changes to libavcodec/api-example.c (1 of 1 file). Show all
Unified · Split
| @@ -115,10 +115,13 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 114 unmodified lines | ||
| 115 | 115 | { |
| 116 | 116 | AVCodec *codec; |
| 117 | 117 | AVCodecContext *c= NULL; |
| 118 | − int out_size, size, len; | |
| 118 | + int out_size, len; | |
| 119 | 119 | FILE *f, *outfile; |
| 120 | 120 | uint8_t *outbuf; |
| 121 | − uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr; | |
| 121 | + uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; | |
| 122 | + AVPacket avpkt; | |
| 123 | + | |
| 124 | + av_init_packet(&avpkt); | |
| 122 | 125 | |
| 123 | 126 | printf("Audio decoding\n"); |
| 124 | 127 | |
| @@ -151,17 +154,16 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 26 unmodified lines | ||
| 151 | 154 | } |
| 152 | 155 | |
| 153 | 156 | /* decode until eof */ |
| 154 | − inbuf_ptr = inbuf; | |
| 157 | + avpkt.data = inbuf; | |
| 155 | 158 | for(;;) { |
| 156 | − size = fread(inbuf, 1, INBUF_SIZE, f); | |
| 157 | − if (size == 0) | |
| 159 | + avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); | |
| 160 | + if (avpkt.size == 0) | |
| 158 | 161 | break; |
| 159 | 162 | |
| 160 | − inbuf_ptr = inbuf; | |
| 161 | − while (size > 0) { | |
| 163 | + avpkt.data = inbuf; | |
| 164 | + while (avpkt.size > 0) { | |
| 162 | 165 | out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; |
| 163 | − len = avcodec_decode_audio2(c, (short *)outbuf, &out_size, | |
| 164 | − inbuf_ptr, size); | |
| 166 | + len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt); | |
| 165 | 167 | if (len < 0) { |
| 166 | 168 | fprintf(stderr, "Error while decoding\n"); |
| 167 | 169 | exit(1); |
| @@ -170,8 +172,8 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 2 unmodified lines | ||
| 170 | 172 | /* if a frame has been decoded, output it */ |
| 171 | 173 | fwrite(outbuf, 1, out_size, outfile); |
| 172 | 174 | } |
| 173 | − size -= len; | |
| 174 | − inbuf_ptr += len; | |
| 175 | + avpkt.size -= len; | |
| 176 | + avpkt.data += len; | |
| 175 | 177 | } |
| 176 | 178 | } |
| 177 | 179 | |
| @@ -314,11 +316,14 @@ static void video_decode_example(const char *outfilename, const char *filename) · 136 unmodified lines | ||
| 314 | 316 | { |
| 315 | 317 | AVCodec *codec; |
| 316 | 318 | AVCodecContext *c= NULL; |
| 317 | − int frame, size, got_picture, len; | |
| 319 | + int frame, got_picture, len; | |
| 318 | 320 | FILE *f; |
| 319 | 321 | AVFrame *picture; |
| 320 | − uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr; | |
| 322 | + uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; | |
| 321 | 323 | char buf[1024]; |
| 324 | + AVPacket avpkt; | |
| 325 | + | |
| 326 | + av_init_packet(&avpkt); | |
| 322 | 327 | |
| 323 | 328 | /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */ |
| 324 | 329 | memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
| @@ -358,8 +363,8 @@ static void video_decode_example(const char *outfilename, const char *filename) · 33 unmodified lines | ||
| 358 | 363 | |
| 359 | 364 | frame = 0; |
| 360 | 365 | for(;;) { |
| 361 | − size = fread(inbuf, 1, INBUF_SIZE, f); | |
| 362 | − if (size == 0) | |
| 366 | + avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); | |
| 367 | + if (avpkt.size == 0) | |
| 363 | 368 | break; |
| 364 | 369 | |
| 365 | 370 | /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio) |
| @@ -377,10 +382,9 @@ static void video_decode_example(const char *outfilename, const char *filename) · 11 unmodified lines | ||
| 377 | 382 | |
| 378 | 383 | /* here, we use a stream based decoder (mpeg1video), so we |
| 379 | 384 | feed decoder and see if it could decode a frame */ |
| 380 | − inbuf_ptr = inbuf; | |
| 381 | − while (size > 0) { | |
| 382 | − len = avcodec_decode_video(c, picture, &got_picture, | |
| 383 | − inbuf_ptr, size); | |
| 385 | + avpkt.data = inbuf; | |
| 386 | + while (avpkt.size > 0) { | |
| 387 | + len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); | |
| 384 | 388 | if (len < 0) { |
| 385 | 389 | fprintf(stderr, "Error while decoding frame %d\n", frame); |
| 386 | 390 | exit(1); |
| @@ -396,16 +400,17 @@ static void video_decode_example(const char *outfilename, const char *filename) · 9 unmodified lines | ||
| 396 | 400 | c->width, c->height, buf); |
| 397 | 401 | frame++; |
| 398 | 402 | } |
| 399 | − size -= len; | |
| 400 | − inbuf_ptr += len; | |
| 403 | + avpkt.size -= len; | |
| 404 | + avpkt.data += len; | |
| 401 | 405 | } |
| 402 | 406 | } |
| 403 | 407 | |
| 404 | 408 | /* some codecs, such as MPEG, transmit the I and P frame with a |
| 405 | 409 | latency of one frame. You must do the following to have a |
| 406 | 410 | chance to get the last frame of the video */ |
| 407 | − len = avcodec_decode_video(c, picture, &got_picture, | |
| 408 | − NULL, 0); | |
| 411 | + avpkt.data = NULL; | |
| 412 | + avpkt.size = 0; | |
| 413 | + len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); | |
| 409 | 414 | if (got_picture) { |
| 410 | 415 | printf("saving last frame %3d\n", frame); |
| 411 | 416 | fflush(stdout); |