Python3 ffmpeg视频转换工具使用方法解析
作者:Yi_warmth 时间:2021-07-28 15:00:30
windows版本下需要先安装ffmpeg工具:
1:先下载指定(https://ffmpeg.zeranoe.com/builds/) 有Static,Shared,Dev三个版本,
可以下载了static版本(是个zip压缩包),解压到指定目录,去配置环境变量,比如d:\ffmpeg\bin,这样bin下面的ffmpeg.exe就可以在命令行中使用了,可以用ffmpeg -version测试一下:
2:安装ffmpeg的python扩展,该扩展可以让你直接在python脚本中直接调用,而不需要单独运行命令: pip install ffmpeg-python
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()
来源:https://www.cnblogs.com/zhouzetian/p/12028805.html
标签:Python,ffmpeg,视频,转换,工具
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
聊聊通过celery_one避免Celery定时任务重复执行的问题
2021-05-20 13:19:12
JS实现css边框样式设置工具
2008-05-25 16:22:00
![](https://img.aspxhome.com/file/UploadPic/20085/25/border-style-tool_82s.gif)
CSS 的模块化思想
2009-02-03 12:52:00
Python中使用scapy模拟数据包实现arp攻击、dns放大攻击例子
2021-12-04 12:15:05
SQL提供的进行数据传输的实用程序—BCP
2009-01-23 13:45:00
python实现Virginia无密钥解密
2023-07-25 10:56:49
Python PIL库图片灰化处理
2022-08-18 20:57:30
![](https://img.aspxhome.com/file/2023/7/64617_0s.png)
Python实现线程状态监测简单示例
2023-12-07 20:31:25
![](https://img.aspxhome.com/file/2023/6/94056_0s.png)
Jquery实现div模拟Select控件
2008-12-01 15:47:00
python 网络编程要点总结
2023-09-30 06:15:38
14条最佳JS代码编写技巧[译]
2009-11-09 19:37:00
Python绘制简单散点图的方法
2023-02-22 02:01:07
![](https://img.aspxhome.com/file/2023/8/87768_0s.jpg)
在Python运行时动态查看进程内部信息的方法
2021-06-09 09:15:40
用Python写一个简易版弹球游戏
2022-02-14 04:03:55
![](https://img.aspxhome.com/file/2023/9/97179_0s.jpg)
keras模型可视化,层可视化及kernel可视化实例
2021-02-20 00:45:25
![](https://img.aspxhome.com/file/2023/5/88915_0s.jpg)
python调用Delphi写的Dll代码示例
2023-07-25 09:33:53
如何得到数据库中所有表名 表字段及字段中文描述
2012-01-05 18:56:44
使用Python将xmind脑图转成excel用例的实现代码(一)
2021-11-10 12:35:42
![](https://img.aspxhome.com/file/2023/7/79717_0s.png)
解决php-fpm.service not found问题的办法
2023-11-21 14:26:21
opencv实现简单人脸识别
2021-08-26 07:49:06
![](https://img.aspxhome.com/file/2023/6/75096_0s.jpg)