History

Use the new avcodec_decode_* API.

Patch by Thilo Borgmann name.surname AT googlemail.com. Originally committed as revision 18409 to svn://svn.ffmpeg.org/ffmpeg/trunk

Thilo Borgmann committed 17 years ago

Commit 4f313921 parent 655d47c1 file · +28 −23Browse files

Showing the changes to libavcodec/api-example.c (1 of 1 file). Show all

Unified · Split

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

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