import os
src_path = r"H:\video\死神-全集 1080P 日语中字\主线\主线初现篇 2\117.mp4"
def format(src, begin_str, end_str):
bname_raw = os.path.basename(src)
src_dir = os.path.dirname(src)
bname, ext = os.path.splitext(bname_raw)
to = os.path.join(src_dir, "{}_split{}".format(bname, ext))
begin = str_seconds(begin_str)
end = str_seconds(end_str)
begin_str_ffmpeg = seconds_str(begin)
end_str_ffmpeg = seconds_str(end)
command = f'ffmpeg -i "{src}" -ss {begin_str_ffmpeg} -to {end_str_ffmpeg} -c copy "{to}"'
os.system(command)
print("{}->{}".format(os.path.basename(src), os.path.basename(to)))
def str_seconds(para):
arr = para.split(":")
arr = [int(v) for v in arr]
mul = [60, 1]
return sum([k*v for (k, v) in zip(mul, arr)])
def seconds_str(seconds):
minutes = seconds // 60
seconds = seconds % 60
return f"{minutes:02}:{seconds:02}"
# 调用函数进行视频裁剪
format(src_path, "01:30", "21:54")
# 使用 ffmpeg 的-c copy 选项,这意味着视频和音频流不会被重新编码,从而大大提高处理速度。