gpt4 book ai didi

python - 使用时间戳修剪一批视频

转载 作者:行者123 更新时间:2023-12-04 23:21:03 26 4
gpt4 key购买 nike

我想根据存储在 csv 文件中的开始和结束时间在文件夹中剪切多个视频:annotations.csv
csv文件的格式为:
视频名 |开始时间 |结束时间
我认为伪代码可能看起来像这样:

`for i in video_names
do: cut video according to time frame`
ffmpeg -ss 00:01:00 -i input.mp4 -to 00:02:00 -c copy output.mp4这是我在硬编码输入名称以及开始和结束时间时为单个视频找到的。
如何使这个动态与我的注释文件相对应?

最佳答案

弄清楚了。在下面的代码片段中,只需添加您的路径而不是“your_file_path/annotations.csv”

pip install moviepy
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
import csv
# name of output file
naming = 'trim_'
def get_sec(time_str):
"""Get Seconds from time."""
h, m, s = time_str.split(':')
return int(h) * 3600 + int(m) * 60 + int(s)

sample = open('your_file_path/annotations.csv', 'r')
csv1 = csv.reader(sample,delimiter=',')
next(csv1, None)
for eachline in csv1:
file_name = str(eachline[0])
out_file = naming + file_name
start = eachline[1]
start = get_sec(start)
end = eachline[2]
end = get_sec(end)

ffmpeg_extract_subclip(file_name, start, end, targetname=out_file)

关于python - 使用时间戳修剪一批视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66363548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com