gpt4 book ai didi

python - 一次将多个视频拆分为较短的视频

转载 作者:行者123 更新时间:2023-12-04 23:18:00 25 4
gpt4 key购买 nike

我正在尝试将我的视频分成多个较短的视频,我已经设法使它适用于一个视频,代码如下,但我有多个视频保存在一个文件夹中,我希望代码通过所有这些视频一次,所以我不必为每个视频手动更改路径,有人可以帮忙吗?

required_video_file = 'Videos/Logitech/LogiCapture/1_stresni.mp4'

with open("times.txt") as f:
times = f.readlines()

times = [x.strip() for x in times]

for time in times:
starttime = int(time.split('-')[0])
endtime = int(time.split("-")[1])
ffmpeg_extract_subclip(required_video_file, starttime, endtime, targetname=str(times.index(time)+1)+".mp4")```

最佳答案

如果您的所有视频文件都将位于特定文件夹中

folder_path = input ("enter the folder path : ")
file_extn = input ("enter the video file extension like mp4 or mov or avi : ")

complete_video_file = []

#Below loop will iterate over the folder and get the list of video files
#and append the details into a list

for video_file in os.listdir(folder_path):
if video_file.endswith(file_extn):
complete_video_file.append(os.path.join(folder_path,video_file))
for required_video_file in complete_video_file:
#have your code below
with open("times.txt") as f:
times = f.readlines()

times = [x.strip() for x in times]

for time in times:
starttime = int(time.split('-')[0])
endtime = int(time.split("-")[1])
ffmpeg_extract_subclip(required_video_file, starttime, endtime, targetname=str(times.index(time)+1)+".mp4")

关于python - 一次将多个视频拆分为较短的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72518224/

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