python3--ffmpeg视频转换工具(一)
windows版本下需要先安装ffmpeg工具:
1:先下载指定(https://ffmpeg.zeranoe.com/builds/) 有Static,Shared,Dev三个版本,
可以下载了static版本(是个zip压缩包),解压到指定目录,去配置环境变量,比如d:\ffmpeg\bin,这样bin下面的ffmpeg.exe就可以在命令行中使用了,可以用ffmpeg -version测试一下:

3:需要注意一点的是,有的情况调用该库会报错(‘ffmpeg‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。),这时需要将python安装目录下Lib文件夹的subprocess.py文件中大概656行中的shell参数改为True


4:假如提示ffmpeg为外部命令错误时,将ffmpeg的路径带上:
代码如下:
def getImage(video_path): base_path = os.path.join(os.path.join(os.getcwd(), "mp4"), video_path) img_count = 1 crop_time = 0.0 try:while crop_time <= 22.0: #转化22s的视频 os.system(‘D:\\ffmpeg-20191210-e73688e-win64-static\\bin\\ffmpeg -i %s -y -f image2 -ss %s %s.jpg‘% (base_path, str(crop_time), str(img_count))) img_count += 1 crop_time += 0.01 #每0.01秒截取一张照片 print(‘视频转化完成!!!‘)except Exception as e:print(e)def save(): dir_s = os.path.join(os.getcwd(), "image")if os.path.exists(dir_s): shutil.rmtree(dir_s) os.mkdir(dir_s)for root, dirs, tmps in os.walk(os.getcwd()):for file in tmps:if file.endswith("jpg") and os.path.exists(os.path.join(dir_s, file)) is False: shutil.move(file, dir_s)video_path = "of2.mp4"getImage(video_path)save()
相关推荐
dingwun 2020-11-16
wangdaren 2020-08-15
wqiaofujiang 2020-07-05
PGzxc 2020-07-04
ShoppingChen 2020-06-25
cherayliu 2020-06-17
83096129 2020-06-08
83096129 2020-06-08
PGzxc 2020-06-01
ShoppingChen 2020-05-29
cherayliu 2020-05-11
ShoppingChen 2020-05-11
83096129 2020-05-10
PGzxc 2020-05-07
cherayliu 2020-04-27
cherayliu 2020-04-11