Skip to content

Commit 5b044ee

Browse files
authored
Add files via upload
1 parent 7ba09d1 commit 5b044ee

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

blog29-MoviePy/test05.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
from moviepy.editor import *
4+
5+
#递归获取文件名称
6+
def file_name(file_dir):
7+
L=[]
8+
for root, dirs, files in os.walk(file_dir):
9+
for file in files:
10+
if os.path.splitext(file)[1] == '.mp4':
11+
L.append(os.path.join(root, file))
12+
return L
13+
14+
#主函数
15+
if __name__ == '__main__':
16+
filePath = 'vedio'
17+
file_list = file_name(filePath)
18+
19+
k = 1
20+
for name in file_list:
21+
print(name)
22+
#获取视频总时间
23+
video = VideoFileClip(name)
24+
times = video.duration
25+
print(times)
26+
27+
#剪切视频广告 省略最后4秒
28+
video = VideoFileClip(name).subclip(0,times-4)
29+
result = "save" + str(k) + ".mp4"
30+
video.write_videofile(result)
31+
k = k + 1
32+

0 commit comments

Comments
 (0)