URLからKivyのビデオプレイヤーに字幕を追加しようとしています。これは私がこれまで行ってきたことです。まず、私はちょうど私がPythonでKivy Videoplayerにアノテーション/サブタイトルを追加する
を仮定し、私はこのようなリストと「JSA」ファイルを必要と私はKivyのドキュメントによると、ビデオVideoPlayer:
source: root.vid_source
options: {'allow_stretch': True, 'eos': 'loop'}
annotations: root.subs_source ## This doesnt work
のソースリンクを追加するのと同じように、プロパティに字幕のリンクを追加しました
[
{"start": 0, "duration": 2,
"text": "This is an example of annotation"},
{"start": 2, "duration": 2,
"bgcolor": [0.5, 0.2, 0.4, 0.5],
"text": "You can change the background color"}
]
が、ソースリンクは、だから私は与えられた中で字幕を解析する新しいクラスを作成し、この形式のテキスト(「キャプション」キーは、私は必要なものであると辞書)
{"captions":[{"duration":1961,"content":"When you have 21 minutes to speak,","startOfParagraph":true,"startTime":1610},{"duration":2976,"content":"two million years seems\nlike a really long time.","startOfParagraph":false,"startTime":3595}
が含まれています私のKvファイルに次の変更
#:import playerapp playerapp
VideoPlayer:
.......
#### str conversion since it says it accepts only string####
annotations: str(playerapp.Subtitles(root.subs_source).get_subtitles())
とフォーマット
class Subtitles:
def __init__(self, url):
self.parsed_subs = []
req = UrlRequest(url, self.got_subtitles)
def got_subtitles(self, req, results):
self.parsed_subs = [{"start":sub["startTime"],"duration":sub["duration"], "text": sub["content"]} for sub in results['captions']]
def get_subtitles(self):
return self.parsed_subs
しかし、それは仕事をdidntの。
のVideoPlayerのためのソースコードを見に取った後、私はそれはそれはVideoAnnotationクラスによって返されるものと移入self._annotations_labels
を作成するVideoPlayerを、初期化中にので、多分何とか私はself._annotations_labels
が、私の内側に上記parsed_subs
を配置する必要があることを見ますここでは混乱しています。