-
-
Save ValdikSS/0068854fa8a8525922c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 97adf4976eb4b511006b611d64a89d544c3d724a Mon Sep 17 00:00:00 2001 | |
| From: ValdikSS <iam@valdikss.org.ru> | |
| Date: Thu, 1 May 2014 14:51:17 +0400 | |
| Subject: [PATCH] lavfi/subtitles: introduce stream_index | |
| Signed-off-by: ValdikSS <iam@valdikss.org.ru> | |
| --- | |
| doc/filters.texi | 13 +++++++++++++ | |
| libavfilter/vf_subtitles.c | 24 ++++++++++++++++++++++-- | |
| 2 files changed, 35 insertions(+), 2 deletions(-) | |
| diff --git a/doc/filters.texi b/doc/filters.texi | |
| index a8b2668..d53f645 100644 | |
| --- a/doc/filters.texi | |
| +++ b/doc/filters.texi | |
| @@ -7725,6 +7725,9 @@ changed. | |
| @item charenc | |
| Set subtitles input character encoding. @code{subtitles} filter only. Only | |
| useful if not UTF-8. | |
| + | |
| +@item stream_index, si | |
| +Set subtitles stream index. @code{subtitles} filter only. | |
| @end table | |
| If the first key is not specified, it is assumed that the first value | |
| @@ -7741,6 +7744,16 @@ which is equivalent to: | |
| subtitles=filename=sub.srt | |
| @end example | |
| +To render the default subtitles stream from file @file{video.mkv}, use: | |
| +@example | |
| +subtitles=video.mkv | |
| +@end example | |
| + | |
| +To render the second subtitles stream from that file, use: | |
| +@example | |
| +subtitles=video.mkv:si=1 | |
| +@end example | |
| + | |
| @section super2xsai | |
| Scale the input by 2x and smooth using the Super2xSaI (Scale and | |
| diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c | |
| index bce0e9f..558e509 100644 | |
| --- a/libavfilter/vf_subtitles.c | |
| +++ b/libavfilter/vf_subtitles.c | |
| @@ -51,6 +51,7 @@ typedef struct { | |
| ASS_Track *track; | |
| char *filename; | |
| char *charenc; | |
| + int stream_index; | |
| uint8_t rgba_map[4]; | |
| int pix_step[4]; ///< steps per pixel for each plane of the main output | |
| int original_w, original_h; | |
| @@ -247,7 +248,9 @@ AVFilter ff_vf_ass = { | |
| static const AVOption subtitles_options[] = { | |
| COMMON_OPTIONS | |
| - {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS}, | |
| + {"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}, | |
| {NULL}, | |
| }; | |
| @@ -279,6 +282,7 @@ AVFILTER_DEFINE_CLASS(subtitles); | |
| static av_cold int init_subtitles(AVFilterContext *ctx) | |
| { | |
| int j, ret, sid; | |
| + int k = 0; | |
| AVDictionary *codec_opts = NULL; | |
| AVFormatContext *fmt = NULL; | |
| AVCodecContext *dec_ctx = NULL; | |
| @@ -309,7 +313,23 @@ static av_cold int init_subtitles(AVFilterContext *ctx) | |
| goto end; | |
| /* Locate subtitles stream */ | |
| - ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0); | |
| + if (ass->stream_index < 0) | |
| + ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0); | |
| + else { | |
| + ret = -1; | |
| + if (ass->stream_index < fmt->nb_streams) { | |
| + for (j = 0; j < fmt->nb_streams; j++) { | |
| + if (fmt->streams[j]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { | |
| + if (ass->stream_index == k) { | |
| + ret = j; | |
| + break; | |
| + } | |
| + k++; | |
| + } | |
| + } | |
| + } | |
| + } | |
| + | |
| if (ret < 0) { | |
| av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n", | |
| ass->filename); | |
| -- | |
| 1.9.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment