OSDN Git Service

Merge commit '59ab9e8ba1df7e3347a4cd2bd56c32e74aede802'
authorClément Bœsch <cboesch@gopro.com>
Tue, 4 Apr 2017 09:48:23 +0000 (11:48 +0200)
committerClément Bœsch <cboesch@gopro.com>
Tue, 4 Apr 2017 09:48:23 +0000 (11:48 +0200)
* commit '59ab9e8ba1df7e3347a4cd2bd56c32e74aede802':
  examples/encode_video: allocate the packet dynamically

Merged-by: Clément Bœsch <cboesch@gopro.com>
1  2 
doc/examples/encode_video.c

@@@ -70,12 -68,12 +70,12 @@@ int main(int argc, char **argv
      AVCodecContext *c= NULL;
      int i, ret, x, y;
      FILE *f;
 -    AVFrame *picture;
 +    AVFrame *frame;
-     AVPacket pkt;
+     AVPacket *pkt;
      uint8_t endcode[] = { 0, 0, 1, 0xb7 };
  
 -    if (argc <= 1) {
 -        fprintf(stderr, "Usage: %s <output file>\n", argv[0]);
 +    if (argc <= 2) {
 +        fprintf(stderr, "Usage: %s <output file> <codec name>\n", argv[0]);
          exit(0);
      }
      filename = argv[1];
      }
  
      c = avcodec_alloc_context3(codec);
 -    picture = av_frame_alloc();
 +    if (!c) {
 +        fprintf(stderr, "Could not allocate video codec context\n");
 +        exit(1);
 +    }
  
+     pkt = av_packet_alloc();
+     if (!pkt)
+         exit(1);
      /* put sample parameters */
      c->bit_rate = 400000;
      /* resolution must be a multiple of two */
      }
  
      /* encode 1 second of video */
 -    for(i=0;i<25;i++) {
 +    for (i = 0; i < 25; i++) {
-         av_init_packet(&pkt);
-         pkt.data = NULL;    // packet data will be allocated by the encoder
-         pkt.size = 0;
          fflush(stdout);
  
          /* make sure the frame data is writable */
              }
          }
  
 -        picture->pts = i;
 +        frame->pts = i;
  
          /* encode the image */
-         encode(c, frame, &pkt, f);
 -        encode(c, picture, pkt, f);
++        encode(c, frame, pkt, f);
      }
  
      /* flush the encoder */
      fclose(f);
  
      avcodec_free_context(&c);
 -    av_frame_free(&picture);
 +    av_frame_free(&frame);
+     av_packet_free(&pkt);
  
      return 0;
  }