Python3中ffmpeg视频转换工具使用方法的案例分析(ffmpeg,python,视频,开发技术)

时间:2024-04-29 15:52:50 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

windows版本下需要先安装ffmpeg工具:

1:先下载指定(https://ffmpeg.zeranoe.com/builds/) 有Static,Shared,Dev三个版本,

可以下载了static版本(是个zip压缩包),解压到指定目录,去配置环境变量,比如d:\ffmpeg\bin,这样bin下面的ffmpeg.exe就可以在命令行中使用了,可以用ffmpeg -version测试一下:

Python3中ffmpeg视频转换工具使用方法的案例分析

2:安装ffmpeg的python扩展,该扩展可以让你直接在python脚本中直接调用,而不需要单独运行命令: pip install ffmpeg-python

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

Python3中ffmpeg视频转换工具使用方法的案例分析Python3中ffmpeg视频转换工具使用方法的案例分析

4:假如提示ffmpeg为外部命令错误时,将ffmpeg的路径带上:

Python3中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()
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Python3中ffmpeg视频转换工具使用方法的案例分析的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:PHP中Header用于页面跳转需要注意哪些地方下一篇:

7 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18