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
.
위해 VideoPlayer의 소스 코드를 살펴에서 복용 후 나는 그것이 VideoAnnotation 클래스에 의해 반환 무슨으로 채 웁니다 self._annotations_labels
를 생성 위해 VideoPlayer를 초기화하는 동안 그래서 아마 어떻게 든 내가 self._annotations_labels
하지만 내부에 위의 parsed_subs
를 넣을 필요가 참조 여기 혼란스러워.