Browse code

lavfi/subtitles: introduce stream_index

Signed-off-by: ValdikSS <iam@valdikss.org.ru>

ValdikSS authored on 2014/05/01 19:51:17
Showing 2 changed files
... ...
@@ -7725,6 +7725,9 @@ changed.
7725 7725
 @item charenc
7726 7726
 Set subtitles input character encoding. @code{subtitles} filter only. Only
7727 7727
 useful if not UTF-8.
7728
+
7729
+@item stream_index, si
7730
+Set subtitles stream index. @code{subtitles} filter only.
7728 7731
 @end table
7729 7732
 
7730 7733
 If the first key is not specified, it is assumed that the first value
... ...
@@ -7741,6 +7744,16 @@ which is equivalent to:
7741 7741
 subtitles=filename=sub.srt
7742 7742
 @end example
7743 7743
 
7744
+To render the default subtitles stream from file @file{video.mkv}, use:
7745
+@example
7746
+subtitles=video.mkv
7747
+@end example
7748
+
7749
+To render the second subtitles stream from that file, use:
7750
+@example
7751
+subtitles=video.mkv:si=1
7752
+@end example
7753
+
7744 7754
 @section super2xsai
7745 7755
 
7746 7756
 Scale the input by 2x and smooth using the Super2xSaI (Scale and
... ...
@@ -51,6 +51,7 @@ typedef struct {
51 51
     ASS_Track    *track;
52 52
     char *filename;
53 53
     char *charenc;
54
+    int stream_index;
54 55
     uint8_t rgba_map[4];
55 56
     int     pix_step[4];       ///< steps per pixel for each plane of the main output
56 57
     int original_w, original_h;
... ...
@@ -247,7 +248,9 @@ AVFilter ff_vf_ass = {
247 247
 
248 248
 static const AVOption subtitles_options[] = {
249 249
     COMMON_OPTIONS
250
-    {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
250
+    {"charenc",      "set input character encoding", OFFSET(charenc),      AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
251
+    {"stream_index", "set stream index",             OFFSET(stream_index), AV_OPT_TYPE_INT,    { .i64 = -1 }, -1,       INT_MAX,  FLAGS},
252
+    {"si",           "set stream index",             OFFSET(stream_index), AV_OPT_TYPE_INT,    { .i64 = -1 }, -1,       INT_MAX,  FLAGS},
251 253
     {NULL},
252 254
 };
253 255
 
... ...
@@ -279,6 +282,7 @@ AVFILTER_DEFINE_CLASS(subtitles);
279 279
 static av_cold int init_subtitles(AVFilterContext *ctx)
280 280
 {
281 281
     int j, ret, sid;
282
+    int k = 0;
282 283
     AVDictionary *codec_opts = NULL;
283 284
     AVFormatContext *fmt = NULL;
284 285
     AVCodecContext *dec_ctx = NULL;
... ...
@@ -309,7 +313,23 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
309 309
         goto end;
310 310
 
311 311
     /* Locate subtitles stream */
312
-    ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0);
312
+    if (ass->stream_index < 0)
313
+        ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0);
314
+    else {
315
+        ret = -1;
316
+        if (ass->stream_index < fmt->nb_streams) {
317
+            for (j = 0; j < fmt->nb_streams; j++) {
318
+                if (fmt->streams[j]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
319
+                    if (ass->stream_index == k) {
320
+                        ret = j;
321
+                        break;
322
+                    }
323
+                    k++;
324
+                }
325
+            }
326
+        }
327
+    }
328
+
313 329
     if (ret < 0) {
314 330
         av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n",
315 331
                ass->filename);