使用 gst-discoverer 我可以获得 mkv 文件中可用的字幕列表,但它们以随机顺序出现。
有谁知道,使用 python,如何获取每个字幕流的索引。
一旦知道索引,一个简单的
self.pipeline.set_property("current-text",subno)
将更改正在使用的字幕流。
这是一个播放 mkv 并列出可用字幕的简单模型:
#!/usr/bin/env python
import time
from gi.repository import Gst
from gi.repository import GstPbutils
Gst.init(None)
discoverer = GstPbutils.Discoverer()
uri='file:///home/rolf/H.mkv'
info = discoverer.discover_uri(uri)
for x in info.get_subtitle_streams():
print x.get_language()
pipeline=Gst.ElementFactory.make("playbin", "playbin")
pipeline.set_property('uri',uri)
pipeline.set_state(Gst.State.PLAYING)
time.sleep(2)
subs = pipeline.get_property('n-text')
print "there are ", subs, " Subtitles"
auds = pipeline.get_property('n-audio')
print "there are ", auds, " Audio streams"
vids = pipeline.get_property('n-video')
print "there are ", vids, " Video Streams"
subc = pipeline.get_property('current-text')
print "Currently using ", subc, " Subtitle set"
dur = int(info.get_duration())/Gst.SECOND
hh = int(dur/3600)
mm, ss = (divmod(int(divmod(dur,3600)[1]),60))
print("Duration : %02d:%02d:%02d" % (hh,mm,ss))
time.sleep(dur)