2017-09-22 10 views
1

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を配置する必要があることを見ますここでは混乱しています。

答えて

0

問題の回避策を管理しました。まず、UrlRequestは私がKivy Appの外でこれを使用していたので動作しませんでした。だから、私はurllibライブラリを使用した、または多分あなたはリクエストライブラリを使用することができ、それはかなり、私が作っていた間違いだった。 また、解析した後、私はsubtitles.jsaファイルにファイルを保存しました。これは '注釈'のプロパティに必要なもので、現在は動作しています。

関連する問題