用 Python 檢查時間軸編輯後的字幕時間
Check a caption cue after a timeline edit with Python
一段 Python 腳本比對旁白與字幕的開始時間,標示時間軸編輯後偏移的字幕。示例中,result 字幕早了 0.45s,容差設為 0.05s;腳本需以 Python 3.10 或更新版本執行。更新時間後,還要播放匯出的影片,確認畫面動作清晰可見,原有音訊連貫。
A reviewer asks you to hold a tutorial shot long enough for the result to appear. You move the next narration line later, and its caption remains where it was. This small script flags caption starts that have drifted from their corresponding spoken line. Use times from the latest sequence or export.
from dataclasses import dataclass
from decimal import Decimal
@dataclass
class Cue:
label: str
voice_start: Decimal
caption_start: Decimal
cues = [
Cue("setup", Decimal("8.45"), Decimal("8.45")),
Cue("result", Decimal("10.60"), Decimal("10.15")),
Cue("next", Decimal("12.20"), Decimal("12.20")),
]
tolerance = Decimal("0.05")
for cue in cues:
offset = cue.caption_start - cue.voice_start
if abs(offset) <= tolerance:
continue
direction = "late" if offset > 0 else "early"
print(f"{cue.label}: caption starts {abs(offset):.2f}s {direction}")
Run it with Python 3.10 or later. It prints:
result: caption starts 0.45s early
To adapt it to a new revision, enter the times for the changed line and one line on either side. Check the affected cue in your editor and run it again with the new time. Finally, play the exported video through the change. Make sure the action is visible and the source audio sounds continuous.
AI assistance was used to draft and edit this tutorial. The example was run locally.
來源:DEV Community · dev.to