[FFmpeg-devel] [PATCH] libavfilter/vf_subtitles: add options offset set subtitles time offset
qq2225936589
qq2225936589 at 163.com
Thu Feb 21 17:20:39 EET 2019
From: qq2225936589 <qq2225936589 at gmail.com>
---
doc/filters.texi | 3 +++
libavfilter/vf_subtitles.c | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 0ef6f56d5d..5dee472837 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16307,6 +16307,9 @@ useful if not UTF-8.
@item stream_index, si
Set subtitles stream index. @code{subtitles} filter only.
+ at item offset
+Set subtitles time offset. @code{subtitles} filter only.
+
@item force_style
Override default style or script info parameters of the subtitles. It accepts a
string containing ASS style format @code{KEY=VALUE} couples separated by ",".
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index a7b02461f2..ba6f03e385 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -27,6 +27,7 @@
* @see{http://www.matroska.org/technical/specs/subtitles/ssa.html}
*/
+#include <float.h>
#include <ass/ass.h>
#include "config.h"
@@ -52,6 +53,7 @@ typedef struct AssContext {
char *filename;
char *fontsdir;
char *charenc;
+ float offset;
char *force_style;
int stream_index;
int alpha;
@@ -266,6 +268,7 @@ static const AVOption subtitles_options[] = {
{"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
{"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
{"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
+ {"offset", "set subtitles time offset", OFFSET(offset), AV_OPT_TYPE_FLOAT, { .dbl = 0.0}, -600.0, 600.0, FLAGS},
{"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
{NULL},
};
@@ -458,7 +461,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
av_err2str(ret));
} else if (got_subtitle) {
- const int64_t start_time = av_rescale_q(sub.pts, AV_TIME_BASE_Q, av_make_q(1, 1000));
+ const int64_t start_time = av_rescale_q(sub.pts, AV_TIME_BASE_Q, av_make_q(1, 1000)) + ass->offset*1000;
const int64_t duration = sub.end_display_time;
for (i = 0; i < sub.num_rects; i++) {
char *ass_line = sub.rects[i]->ass;
--
2.13.0.windows.1
More information about the ffmpeg-devel
mailing list