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;
}