摘要:
Python腳本,它將遍歷指定目錄下的所有.srt文件,移除其中的不必要的英文字符、不必要的空行以及不必要的空格。該腳本會(huì)保留字幕索引、字幕時(shí)間線以及字幕中的中文內(nèi)容,并且只保留字幕中的中文內(nèi)容。它還會(huì)保留字幕行與字幕之間的換行符,同時(shí)去掉字幕與字幕之間的不必要的換行符。處理后的內(nèi)容將被保存為新的.
閱讀全文
posted @ 2024-10-23 13:08
大話人生
閱讀(73)
推薦(0)
摘要:
去掉時(shí)間線代碼: import os import re def remove_timestamps(content): """ 移除srt文件內(nèi)容中的時(shí)間線行。 :param content: srt文件的內(nèi)容 :return: 移除時(shí)間線后的srt內(nèi)容 """ # 使用正則表達(dá)式匹配時(shí)間線行 p
閱讀全文
posted @ 2024-10-09 09:57
大話人生
閱讀(102)
推薦(0)
摘要:
代碼: import subprocess def replace_audio_with_ffmpeg(video_path, audio_path, output_path): # 構(gòu)建ffmpeg命令 command = [ 'ffmpeg', '-i', video_path, # 輸入視頻文
閱讀全文
posted @ 2024-10-04 23:24
大話人生
閱讀(84)
推薦(0)
摘要:
代碼: import os from moviepy.editor import VideoFileClip def split_video(video_path, output_dir): # 加載視頻文件 clip = VideoFileClip(video_path) duration = c
閱讀全文
posted @ 2024-10-04 09:41
大話人生
閱讀(43)
推薦(0)
摘要:
代碼: import os import re def replace_text_in_srt(file_path, replacements): with open(file_path, 'r', encoding='utf-8') as file: content = file.read() f
閱讀全文
posted @ 2024-09-26 06:09
大話人生
閱讀(33)
推薦(0)
摘要:
代碼: import os import re def remove_korean_text(srt_content): # 定義韓文字符的Unicode范圍 pattern = re.compile(r'[\uac00-\ud7a3]+', re.UNICODE) # 使用正則表達(dá)式替換韓文字符為
閱讀全文
posted @ 2024-09-25 22:22
大話人生
閱讀(60)
推薦(0)
摘要:
from PIL import Image from collections import Counter import numpy as np def save_colors_to_file(image_path, output_file): # 打開圖片文件 image = Image.open
閱讀全文
posted @ 2024-09-16 19:45
大話人生
閱讀(229)
推薦(0)
摘要:
import os import shutil def organize_files_by_prefix(folder_path): # 遍歷指定文件夾 for filename in os.listdir(folder_path): # 檢查是否為文件 if os.path.isfile(os.p
閱讀全文
posted @ 2024-08-26 09:07
大話人生
閱讀(16)
推薦(0)
摘要:
代碼: # 定義一個(gè)函數(shù)來處理文件 def process_file(src_filename, unique_filename): seen = set() duplicates = set() with open(src_filename, 'r', encoding='utf-8') as f
閱讀全文
posted @ 2024-07-09 20:31
大話人生
閱讀(65)
推薦(0)
摘要:
代碼: def is_line_with_only_digits(line): # 檢查一行是否只包含數(shù)字 return line.strip().isdigit() def process_file(input_file_path, output_file_path): with open(inp
閱讀全文
posted @ 2024-07-09 14:10
大話人生
閱讀(24)
推薦(0)