学python没多久,发现OpenCV做的视频截取出来的视频无声的 水平有限也没搞明白怎么处理,后面用FFmpeg整了个,如学弟、学妹有用到我这个自行百度怎么配置FFmpeg环境配置,配置好再测试代码,话不多说直接上代码。。如有问题请多指教
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @version : Python 3.6.6
# @Time : 2019/6/13 11:20
import subprocess
import os
def cutVideo():
# file_time = ffmpeg.probe(file_name)['format']['duration'] # 视频总时长 秒
subprocess.call('ffmpeg.exe -y -i ' + file_name + ' -ss ' + start_time + ' -t '+ lasts_time + ' -acodec copy -vcodec copy -async 1 ' + save_name)
if __name__ == '__main__':
iPath = r'G:\test\python\\'
start_time = '00:02:20' # 开始时间
lasts_time = '00:02:00' # 截取多长时间
file_Suffix = ['.mp4', '.MP4']
file_names = [name for name in os.listdir(iPath) for item in file_Suffix if
os.path.splitext(name)[1] == item]
for i in file_names:
file_name = iPath + i
save_name = iPath + '截取' + i
cutVideo()
print('完成')