]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/apiexample.c
AltiVec optimized fdct patch by (James Klicman <james at klicman dot org>)
[ffmpeg] / libavcodec / apiexample.c
index 27ec8241e1e817c9c51ed377b3c3d2017e634088..dd4d6dfd4de18218c706ebf897919e1cc1ffd9fb 100644 (file)
@@ -3,7 +3,7 @@
  * avcodec API use example.
  *
  * Note that this library only handles codecs (mpeg, mpeg4, etc...),
- * not file formats (avi, vob, etc...). See library 'libav' for the
+ * not file formats (avi, vob, etc...). See library 'libavformat' for the
  * format handling 
  */
 
@@ -98,9 +98,12 @@ void audio_decode_example(const char *outfilename, const char *filename)
     int out_size, size, len;
     FILE *f, *outfile;
     uint8_t *outbuf;
-    uint8_t inbuf[INBUF_SIZE], *inbuf_ptr;
+    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
 
     printf("Audio decoding\n");
+    
+    /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
+    memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 
     /* find the mpeg audio decoder */
     codec = avcodec_find_decoder(CODEC_ID_MP2);
@@ -195,6 +198,7 @@ void video_encode_example(const char *filename)
     c->frame_rate = 25;  
     c->frame_rate_base= 1;
     c->gop_size = 10; /* emit one intra frame every ten frames */
+    c->max_b_frames=1;
 
     /* open it */
     if (avcodec_open(c, codec) < 0) {
@@ -225,7 +229,6 @@ void video_encode_example(const char *filename)
 
     /* encode 1 second of video */
     for(i=0;i<25;i++) {
-        printf("encoding frame %3d\r", i);
         fflush(stdout);
         /* prepare a dummy image */
         /* Y */
@@ -245,6 +248,16 @@ void video_encode_example(const char *filename)
 
         /* encode the image */
         out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
+        printf("encoding frame %3d (size=%5d)\n", i, out_size);
+        fwrite(outbuf, 1, out_size, f);
+    }
+
+    /* get the delayed frames */
+    for(; out_size; i++) {
+        fflush(stdout);
+        
+        out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
+        printf("write frame %3d (size=%5d)\n", i, out_size);
         fwrite(outbuf, 1, out_size, f);
     }
 
@@ -287,9 +300,12 @@ void video_decode_example(const char *outfilename, const char *filename)
     int frame, size, got_picture, len;
     FILE *f;
     AVFrame *picture;
-    uint8_t inbuf[INBUF_SIZE], *inbuf_ptr;
+    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
     char buf[1024];
 
+    /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
+    memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+
     printf("Video decoding\n");
 
     /* find the mpeg1 video decoder */
@@ -353,7 +369,7 @@ void video_decode_example(const char *outfilename, const char *filename)
                 exit(1);
             }
             if (got_picture) {
-                printf("saving frame %3d\r", frame);
+                printf("saving frame %3d\n", frame);
                 fflush(stdout);
 
                 /* the picture is allocated by the decoder. no need to
@@ -374,7 +390,7 @@ void video_decode_example(const char *outfilename, const char *filename)
     len = avcodec_decode_video(c, picture, &got_picture, 
                                NULL, 0);
     if (got_picture) {
-        printf("saving frame %3d\r", frame);
+        printf("saving last frame %3d\n", frame);
         fflush(stdout);
         
         /* the picture is allocated by the decoder. no need to