/**************************************************************/
/* audio output */
-float t, tincr, tincr2;
-int16_t *samples;
-uint8_t *audio_outbuf;
-int audio_outbuf_size;
-int audio_input_frame_size;
+static float t, tincr, tincr2;
+static int16_t *samples;
+static uint8_t *audio_outbuf;
+static int audio_outbuf_size;
+static int audio_input_frame_size;
/*
* add an audio output stream
AVCodecContext *c;
AVStream *st;
- st = av_new_stream(oc, 1);
+ st = avformat_new_stream(oc, NULL);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
+ st->id = 1;
c = st->codec;
c->codec_id = codec_id;
/**************************************************************/
/* video output */
-AVFrame *picture, *tmp_picture;
-uint8_t *video_outbuf;
-int frame_count, video_outbuf_size;
+static AVFrame *picture, *tmp_picture;
+static uint8_t *video_outbuf;
+static int frame_count, video_outbuf_size;
/* add a video output stream */
static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
{
AVCodecContext *c;
AVStream *st;
+ AVCodec *codec;
st = avformat_new_stream(oc, NULL);
if (!st) {
}
c = st->codec;
+
+ /* find the video encoder */
+ codec = avcodec_find_encoder(codec_id);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+ avcodec_get_context_defaults3(c, codec);
+
c->codec_id = codec_id;
- c->codec_type = AVMEDIA_TYPE_VIDEO;
/* put sample parameters */
c->bit_rate = 400000;
"The output format is automatically guessed according to the file extension.\n"
"Raw images can also be output by using '%%d' in the filename\n"
"\n", argv[0]);
- exit(1);
+ return 1;
}
filename = argv[1];
avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);
}
if (!oc) {
- exit(1);
+ return 1;
}
fmt = oc->oformat;
if (!(fmt->flags & AVFMT_NOFILE)) {
if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
- exit(1);
+ return 1;
}
}
/* write the stream header, if any */
av_write_header(oc);
-
+ picture->pts = 0;
for(;;) {
/* compute current audio and video time */
if (audio_st)
write_audio_frame(oc, audio_st);
} else {
write_video_frame(oc, video_st);
+ picture->pts++;
}
}