---
libavformat/output-example.c | 43 +++++++++++++++++++++++++++--------------
1 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/libavformat/output-example.c b/libavformat/output-example.c
index 96bbd11..6d7d624 100644
--- a/libavformat/output-example.c
+++ b/libavformat/output-example.c
@@ -40,9 +40,7 @@
#undef exit
/* 5 seconds stream duration */
-#define STREAM_DURATION 5.0
-#define STREAM_FRAME_RATE 25 /* 25 images/s */
-#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
+#define STREAM_NB_FRAMES(DURATION, F_RATE) ((int)(DURATION * F_RATE))
#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
static int sws_flags = SWS_BICUBIC;
@@ -203,7 +201,7 @@ typedef struct {
/* add a video output stream */
static AVStream *add_video_stream(AVFormatContext *oc,
- enum CodecID codec_id, float scale)
+ enum CodecID codec_id, float scale, int
framerate)
{
AVCodecContext *c;
AVStream *st;
@@ -227,7 +225,7 @@ static AVStream *add_video_stream(AVFormatContext *oc,
of which frame timestamps are represented. for fixed-fps content,
timebase should be 1/framerate and timestamp increments should be
identically 1. */
- c->time_base.den = STREAM_FRAME_RATE;
+ c->time_base.den = framerate;
c->time_base.num = 1;
c->gop_size = 12; /* emit one intra frame every twelve frames at most */
c->pix_fmt = STREAM_PIX_FMT;
@@ -346,7 +344,7 @@ static void fill_yuv_image(AVFrame *pict, int frame_index,
int width, int height
}
}
-static void write_video_frame(AVFormatContext *oc, VideoOut *out, char *hidden)
+static void write_video_frame(AVFormatContext *oc, VideoOut *out, char
*hidden, int tot_frames)
{
int out_size, ret = 0;
AVPacket pkt;
@@ -357,7 +355,7 @@ static void write_video_frame(AVFormatContext *oc, VideoOut
*out, char *hidden)
c = out->st->codec;
- if (frame_count >= STREAM_NB_FRAMES) {
+ if (frame_count >= tot_frames) {
/* no more frame to compress. The codec has a latency of a few
frames if using B frames, so we get the last frames by
passing the same picture again */
@@ -454,20 +452,35 @@ int main(int argc, char **argv)
double audio_pts, video_pts;
VideoOut *out, *out2;
AudioOut *aout;
+ int opt;
+ float duration = 5.0; /* 5 secs stream */
+ int framerate = 25; /* 25 images/sec */
+ int tot_frames;
int i;
/* initialize libavcodec, and register all codecs and formats */
av_register_all();
- if (argc != 2) {
- printf("usage: %s output_file\n"
+ if (argc < 2) {
+ printf("usage: %s output_file\n [-d stream_duration] [-r frame_rate]"
"API example program to output a media file with libavformat.\n"
"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);
}
+ while ((opt = getopt(argc, argv, "d:r:")) != -1) {
+ switch(opt) {
+ case 'd':
+ duration = atof(optarg);
+ break;
+ case 'r':
+ framerate = atoi(optarg);
+ break;
+ }
+ }
+ tot_frames = STREAM_NB_FRAMES(duration, framerate);
filename = argv[1];
/* auto detect the output format from the name. default is
@@ -496,13 +509,13 @@ int main(int argc, char **argv)
video_st = NULL;
audio_st = NULL;
if (fmt->video_codec != CODEC_ID_NONE) {
- video_st = add_video_stream(oc, fmt->video_codec, 1);
+ video_st = add_video_stream(oc, fmt->video_codec, 1, framerate);
}
if (fmt->audio_codec != CODEC_ID_NONE) {
audio_st = add_audio_stream(oc, fmt->audio_codec);
}
- video_st2 = add_video_stream(oc, CODEC_ID_MPEG2VIDEO, 0.5);
+ video_st2 = add_video_stream(oc, CODEC_ID_MPEG2VIDEO, 0.5, framerate);
/* set the output parameters (must be done even if no
parameters). */
@@ -544,16 +557,16 @@ int main(int argc, char **argv)
else
video_pts = 0.0;
- if ((!audio_st || audio_pts >= STREAM_DURATION) &&
- (!video_st || video_pts >= STREAM_DURATION))
+ if ((!audio_st || audio_pts >= duration) &&
+ (!video_st || video_pts >= duration))
break;
/* write interleaved audio and video frames */
if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
write_audio_frame(oc, audio_st, aout);
} else {
- write_video_frame(oc, out, NULL);
- write_video_frame(oc, out2, "Test");
+ write_video_frame(oc, out, NULL, tot_frames);
+ write_video_frame(oc, out2, "Test", tot_frames);
frame_count++;
}
}
--
1.7.4.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel