python如何调用ffprobe_我如何获得Python查找ffprobe?

这篇博客讲述了作者在MacOS环境下遇到的问题,即在Python中调用ffprobe获取视频文件的宽度和高度时遇到'FileNotFoundError'。通过检查环境变量'PATH',作者发现Python的路径与Shell路径不一致。解决方法是在Python程序中添加一行代码更新'PATH',使其包含ffprobe的路径。
摘要由CSDN通过智能技术生成

我ffmpeg和ffprobe安装在我的MAC(MacOS的塞拉利昂),我也加入他们的PATH路径。我可以从终端运行它们。

我正在尝试使用ffprobe以下代码来获取视频文件的宽度和高度:

importsubprocessimportshleximportjson# function to find the resolution of the input video filedeffindVideoResolution(pathToInputVideo):cmd="ffprobe -v quiet -print_format json -show_streams"args=shlex.split(cmd)args.append(pathToInputVideo)# run the ffprobe process, decode stdout into utf-8 & convert to JSONffprobeOutput=subprocess.check_output(args).decode('utf-8')ffprobeOutput=json.loads(ffprobeOutput)# find height and widthheight=ffprobeOutput['streams'][0]['height']width=ffprobeOutput['streams'][0]['width']returnheight,width

h,w=findVideoResolution("/Users/tomburrows/Documents/qfpics/user1/order1/movie.mov")print(h,w)

很抱歉,我无法提供MCVE,因为我没有编写此代码,而且我真的不知道它是如何工作的。

它给出以下错误:

Traceback (most recent call last):

File "/Users/tomburrows/Dropbox/Moviepy Tests/get_dimensions.py", line 21, in

h, w = findVideoResolution("/Users/tomburrows/Documents/qfpics/user1/order1/movie.mov")

File "/Users/tomburrows/Dropbox/Moviepy Tests/get_dimensions.py", line 12, in findVideoResolution

ffprobeOutput = subprocess.check_output(args).decode('utf-8')

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 626, in check_output

**kwargs).stdout

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 693, in run

with Popen(*popenargs, **kwargs) as process:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__

restore_signals, start_new_session)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child

raise child_exception_type(errno_num, err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe'

如果python没有从PATH文件读取,我如何指定在哪里ffprobe?

编辑:似乎python路径与我的shell路径不对齐。os.environ["PATH"]+=":/the_path/of/ffprobe/dir"在每个程序的开头使用允许我使用ffprobe,但是为什么我的python路径与shell路径可能不同?

解决方案

您可以使用

importosprintos.environ['PATH']

验证/验证ffprobe在您的python环境中。根据您的错误,可能没有。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值