[FFmpeg-devel] [PATCH 2/2] avcodec/realtime_bsf: add option to scale speed
Moritz Barsnick
barsnick at gmx.net
Tue Dec 25 22:41:39 EET 2018
Signed-off-by: Moritz Barsnick <barsnick at gmx.net>
---
doc/bitstream_filters.texi | 4 ++++
libavcodec/realtime_bsf.c | 7 +++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8c71100460..860c555c3f 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -610,6 +610,10 @@ It accepts the following options:
@item limit
Time limit for the pauses. Any pause longer than that will be considered
a timestamp discontinuity and reset the timer. Default is 2 seconds.
+ at item speed
+Speed factor for processing. The value must be a float larger than zero.
+Values larger than 1.0 will speed up processing, smaller will slow it down.
+The @var{limit} is automatically adapted accordingly. Default is 1.0.
@end table
@section remove_extra
diff --git a/libavcodec/realtime_bsf.c b/libavcodec/realtime_bsf.c
index eb4b0b69ed..31a648f96c 100644
--- a/libavcodec/realtime_bsf.c
+++ b/libavcodec/realtime_bsf.c
@@ -24,11 +24,13 @@
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bsf.h"
+#include <float.h>
typedef struct RealtimeContext {
const AVClass *class;
int64_t delta;
int64_t limit;
+ double speed;
unsigned inited;
} RealtimeContext;
@@ -42,7 +44,7 @@ static int realtime_filter(AVBSFContext *bsf, AVPacket *pkt)
return ret;
if (pkt->pts != AV_NOPTS_VALUE) {
- int64_t pts = av_rescale_q(pkt->pts, bsf->time_base_in, AV_TIME_BASE_Q);
+ int64_t pts = av_rescale_q(pkt->pts, bsf->time_base_in, AV_TIME_BASE_Q) / ctx->speed;
int64_t now = av_gettime_relative();
int64_t sleep = pts - now + ctx->delta;
if (!ctx->inited) {
@@ -50,7 +52,7 @@ static int realtime_filter(AVBSFContext *bsf, AVPacket *pkt)
sleep = 0;
ctx->delta = now - pts;
}
- if (sleep > ctx->limit || sleep < -ctx->limit) {
+ if (sleep > ctx->limit / ctx->speed || sleep < -ctx->limit / ctx->speed) {
av_log(ctx, AV_LOG_WARNING,
"time discontinuity detected: %"PRIi64" us, resetting\n",
sleep);
@@ -72,6 +74,7 @@ static int realtime_filter(AVBSFContext *bsf, AVPacket *pkt)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_BSF_PARAM)
static const AVOption options[] = {
{ "limit", "sleep time limit", OFFSET(limit), AV_OPT_TYPE_DURATION, { .i64 = 2000000 }, 0, INT64_MAX, FLAGS },
+ { "speed", "speed factor", OFFSET(speed), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, DBL_MIN, DBL_MAX, FLAGS },
{ NULL },
};
--
2.14.5
More information about the ffmpeg-devel
mailing list