Skip to content

Commit

Permalink
Make correct webvtt files, fixes #531
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 7, 2024
1 parent 1ab6094 commit 714cdc6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions auto_editor/render/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ def edit(self, chunks: Chunks) -> None:
self.contents = new_content

def write(self, file_path: str) -> None:
codec = self.codec
with open(file_path, "w", encoding="utf-8") as file:
file.write(self.header)
for c in self.contents:
file.write(
f"{c.before}{to_timecode(c.start / self.tb, self.codec)}"
f"{c.middle}{to_timecode(c.end / self.tb, self.codec)}"
f"{c.after}"
f"{c.before}{to_timecode(c.start / self.tb, codec)}"
+ f"{c.middle}{to_timecode(c.end / self.tb, codec)}"
+ c.after
+ ("\n" if codec == "webvtt" else "")
)
file.write(self.footer)

Expand Down
13 changes: 10 additions & 3 deletions auto_editor/subcommands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def fileinfo(path: str) -> FileInfo:
"wav/pcm-f32le.wav",
"wav/pcm-s32le.wav",
"multi-track.mov",
"subtitle.mp4",
"mov_text.mp4",
"testsrc.mkv",
)

Expand Down Expand Up @@ -222,7 +222,8 @@ def levels():
run.raw(["levels", "resources/new-commentary.mp3"])

def subdump():
run.raw(["subdump", "resources/subtitle.mp4"])
run.raw(["subdump", "resources/mov_text.mp4"])
run.raw(["subdump", "resources/webvtt.mkv"])

def desc():
run.raw(["desc", "example.mp4"])
Expand Down Expand Up @@ -357,7 +358,13 @@ def premiere_named_export():
run.main(["example.mp4"], ["--export", 'premiere:name="Foo Bar"'])

def export_subtitles():
cn = fileinfo(run.main(["resources/subtitle.mp4"], []))
cn = fileinfo(run.main(["resources/mov_text.mp4"], []))

assert len(cn.videos) == 1
assert len(cn.audios) == 1
assert len(cn.subtitles) == 1

cn = fileinfo(run.main(["resources/webvtt.mkv"], []))

assert len(cn.videos) == 1
assert len(cn.audios) == 1
Expand Down
Binary file added resources/mov_text.mp4
Binary file not shown.
Binary file removed resources/subtitle.mp4
Binary file not shown.
Binary file added resources/webvtt.mkv
Binary file not shown.

0 comments on commit 714cdc6

Please sign in to comment.