国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Python實現(xiàn)視頻字幕時間軸格式轉(zhuǎn)換

這篇具有很好參考價值的文章主要介紹了Python實現(xiàn)視頻字幕時間軸格式轉(zhuǎn)換。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

自己喜歡收藏電影,有時網(wǎng)上能找到的中文字幕文件都不滿足自己電影版本。在自己下載的壓制版電影中已內(nèi)封非中文srt字幕時,可以選擇自己將srt的時間軸轉(zhuǎn)為ass并替換ass中的時間軸。自己在頻繁
復制粘貼改格式的時候想起可以用Python代碼完成轉(zhuǎn)換這一操作,借助ChatGPT并自己稍作修改后用代碼實現(xiàn)了。自己測試可用。

沒指定srt文件的路徑,使用前首先需要將srt后綴先改為txt文本格式,代碼默認輸入為“input.txt”,輸出“output.txt”。運行時待轉(zhuǎn)換的txt文件需要和py文件在同一目錄內(nèi)。
?

import re

def convert_timecode(line):
    if "-->" in line:
        # Split the line into two parts using the arrow
        parts = line.strip().split(" --> ")

        # Process each part separately
        new_parts = []
        for i, part in enumerate(parts):
            if i == 0:
                # For the first timecode, insert a comma between the first two characters
                part = part[0] + "," + part[1:]
            else:
                # For the second timecode, remove the first character
                part = part[1:]

            # Remove the last digit from the milliseconds part
            hours, minutes, seconds_milliseconds = part.split(":")
            seconds, milliseconds = seconds_milliseconds.split(",")
            milliseconds = milliseconds[:-1]  # Remove the last digit

            # Replace the last colon before the milliseconds part with a dot
            new_part = f"{hours}:{minutes}:{seconds}.{milliseconds}"
            new_parts.append(new_part)

        # Join the parts back together using a comma
        new_line = ",".join(new_parts)
        return new_line + "\n"
    else:
        # If the line doesn't contain an arrow, return it unchanged
        return line

# Replace 'input.txt' with the name of your input file, and 'output.txt' with the name of your output file.
with open('input.txt', 'r', encoding='utf-8') as infile, open('output.txt', 'w', encoding='utf-8') as outfile:
    for line in infile:
        outfile.write(convert_timecode(line))

不過還是需要手動對照翻譯復制粘貼進行調(diào)軸,就是比以前手動改時間軸格式方便了些。不知道有沒有一鍵將srt直接按照格式轉(zhuǎn)為ass的軟件,甚至實現(xiàn)普通字幕改特效字幕。

轉(zhuǎn)換前srt格式時間軸

字幕文件時間軸格式,Python,音視頻

轉(zhuǎn)換后ass格式時間軸

字幕文件時間軸格式,Python,音視頻文章來源地址http://www.zghlxwxcb.cn/news/detail-817038.html

到了這里,關于Python實現(xiàn)視頻字幕時間軸格式轉(zhuǎn)換的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包