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
115115 {
116116 AVCodec *codec;
117117 AVCodecContext *c= NULL;
118− int out_size, size, len;
118+ int out_size, len;
119119 FILE *f, *outfile;
120120 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);
122125
123126 printf("Audio decoding\n");
124127
@@ -151,17 +154,16 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 26 unmodified lines
151154 }
152155
153156 /* decode until eof */
154− inbuf_ptr = inbuf;
157+ avpkt.data = inbuf;
155158 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)
158161 break;
159162
160− inbuf_ptr = inbuf;
161− while (size > 0) {
163+ avpkt.data = inbuf;
164+ while (avpkt.size > 0) {
162165 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);
165167 if (len < 0) {
166168 fprintf(stderr, "Error while decoding\n");
167169 exit(1);
@@ -170,8 +172,8 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 2 unmodified lines
170172 /* if a frame has been decoded, output it */
171173 fwrite(outbuf, 1, out_size, outfile);
172174 }
173− size -= len;
174− inbuf_ptr += len;
175+ avpkt.size -= len;
176+ avpkt.data += len;
175177 }
176178 }
177179
@@ -314,11 +316,14 @@ static void video_decode_example(const char *outfilename, const char *filename) · 136 unmodified lines
314316 {
315317 AVCodec *codec;
316318 AVCodecContext *c= NULL;
317− int frame, size, got_picture, len;
319+ int frame, got_picture, len;
318320 FILE *f;
319321 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];
321323 char buf[1024];
324+ AVPacket avpkt;
325+
326+ av_init_packet(&avpkt);
322327
323328 /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
324329 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
358363
359364 frame = 0;
360365 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)
363368 break;
364369
365370 /* 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
377382
378383 /* here, we use a stream based decoder (mpeg1video), so we
379384 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);
384388 if (len < 0) {
385389 fprintf(stderr, "Error while decoding frame %d\n", frame);
386390 exit(1);
@@ -396,16 +400,17 @@ static void video_decode_example(const char *outfilename, const char *filename) · 9 unmodified lines
396400 c->width, c->height, buf);
397401 frame++;
398402 }
399− size -= len;
400− inbuf_ptr += len;
403+ avpkt.size -= len;
404+ avpkt.data += len;
401405 }
402406 }
403407
404408 /* some codecs, such as MPEG, transmit the I and P frame with a
405409 latency of one frame. You must do the following to have a
406410 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);
409414 if (got_picture) {
410415 printf("saving last frame %3d\n", frame);
411416 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