[FFmpeg-cvslog] lavfi/testsrc: increase precision of the duration parameter
Stefano Sabatini
git at videolan.org
Thu Sep 20 12:48:46 CEST 2012
ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Thu Sep 20 10:57:00 2012 +0200| [98f753ec5198d4f74ba9f68cc85badf8a6257547] | committer: Stefano Sabatini
lavfi/testsrc: increase precision of the duration parameter
Compute duration in microseconds, rather than in timebase units. Decrease
approximation errors.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=98f753ec5198d4f74ba9f68cc85badf8a6257547
---
libavfilter/version.h | 2 +-
libavfilter/vsrc_testsrc.c | 22 +++++++++++-----------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 7bb91c0..e83593e 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 16
-#define LIBAVFILTER_VERSION_MICRO 104
+#define LIBAVFILTER_VERSION_MICRO 105
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index 28d114e..1fe64fa 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -51,9 +51,10 @@ typedef struct {
int w, h;
unsigned int nb_frame;
AVRational time_base, frame_rate;
- int64_t pts, max_pts;
+ int64_t pts;
char *frame_rate_str; ///< video frame rate
- char *duration; ///< total duration of the generated video
+ char *duration_str; ///< total duration of the generated video
+ int64_t duration; ///< duration expressed in microseconds
AVRational sar; ///< sample aspect ratio
int nb_decimals;
int draw_once; ///< draw only the first frame, always put out the same picture
@@ -79,8 +80,8 @@ static const AVOption options[] = {
{ "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },
{ "rate", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
{ "r", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
- { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
- { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
+ { "duration", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
+ { "d", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
/* only used by color */
@@ -96,7 +97,6 @@ static const AVOption options[] = {
static av_cold int init(AVFilterContext *ctx, const char *args)
{
TestSourceContext *test = ctx->priv;
- int64_t duration = -1;
int ret = 0;
av_opt_set_defaults(test);
@@ -109,8 +109,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
return ret;
}
- if (test->duration && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
- av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
+ if (test->duration_str &&
+ (ret = av_parse_time(&test->duration, test->duration_str, 1)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration_str);
return ret;
}
@@ -133,14 +134,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
}
test->time_base = av_inv_q(test->frame_rate);
- test->max_pts = duration >= 0 ?
- av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
test->nb_frame = 0;
test->pts = 0;
av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
test->w, test->h, test->frame_rate.num, test->frame_rate.den,
- duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base),
+ test->duration < 0 ? -1 : (double)test->duration/1000000,
test->sar.num, test->sar.den);
return 0;
}
@@ -172,7 +171,8 @@ static int request_frame(AVFilterLink *outlink)
AVFilterBufferRef *outpicref;
int ret = 0;
- if (test->max_pts >= 0 && test->pts >= test->max_pts)
+ if (test->duration >= 0 &&
+ av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
return AVERROR_EOF;
if (test->draw_once) {
More information about the ffmpeg-cvslog
mailing list