* 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
*/
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);
c->width = 352;
c->height = 288;
/* frames per second */
- c->frame_rate = 25 * FRAME_RATE_BASE;
+ 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) {
/* encode 1 second of video */
for(i=0;i<25;i++) {
- printf("encoding frame %3d\r", i);
fflush(stdout);
/* prepare a dummy image */
/* Y */
/* 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);
}
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 */
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
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
int depth = 0;
for (;;) {
if (!c->name) {
- if (c->sub) {
+ if (c->help) {
stack[depth++] = c;
- c = c->sub;
+ c = (const AVOption*)c->help;
} else {
if (depth == 0)
break; // finished