Commit 98f753ec authored by Stefano Sabatini's avatar Stefano Sabatini

lavfi/testsrc: increase precision of the duration parameter

Compute duration in microseconds, rather than in timebase units. Decrease
approximation errors.
parent 16e52c86
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 16 #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, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \ LIBAVFILTER_VERSION_MINOR, \
......
...@@ -51,9 +51,10 @@ typedef struct { ...@@ -51,9 +51,10 @@ typedef struct {
int w, h; int w, h;
unsigned int nb_frame; unsigned int nb_frame;
AVRational time_base, frame_rate; AVRational time_base, frame_rate;
int64_t pts, max_pts; int64_t pts;
char *frame_rate_str; ///< video frame rate 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 AVRational sar; ///< sample aspect ratio
int nb_decimals; int nb_decimals;
int draw_once; ///< draw only the first frame, always put out the same picture int draw_once; ///< draw only the first frame, always put out the same picture
...@@ -79,8 +80,8 @@ static const AVOption options[] = { ...@@ -79,8 +80,8 @@ static const AVOption options[] = {
{ "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS }, { "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 }, { "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 }, { "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 }, { "duration", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "d", "set video duration", OFFSET(duration), 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 }, { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
/* only used by color */ /* only used by color */
...@@ -96,7 +97,6 @@ static const AVOption options[] = { ...@@ -96,7 +97,6 @@ static const AVOption options[] = {
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
TestSourceContext *test = ctx->priv; TestSourceContext *test = ctx->priv;
int64_t duration = -1;
int ret = 0; int ret = 0;
av_opt_set_defaults(test); av_opt_set_defaults(test);
...@@ -109,8 +109,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args) ...@@ -109,8 +109,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
return ret; return ret;
} }
if (test->duration && (ret = av_parse_time(&duration, test->duration, 1)) < 0) { if (test->duration_str &&
av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration); (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; return ret;
} }
...@@ -133,14 +134,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args) ...@@ -133,14 +134,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
} }
test->time_base = av_inv_q(test->frame_rate); 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->nb_frame = 0;
test->pts = 0; test->pts = 0;
av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n", 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, 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); test->sar.num, test->sar.den);
return 0; return 0;
} }
...@@ -172,7 +171,8 @@ static int request_frame(AVFilterLink *outlink) ...@@ -172,7 +171,8 @@ static int request_frame(AVFilterLink *outlink)
AVFilterBufferRef *outpicref; AVFilterBufferRef *outpicref;
int ret = 0; 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; return AVERROR_EOF;
if (test->draw_once) { if (test->draw_once) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment