我正在尝试获取视频剪辑的持续时间。但是无法获取文件。 这是我的代码:
import subprocess
import os
def getLength(input_video):
result = subprocess.Popen('ffprobe -i input_video -show_entries format=duration -v quiet -of csv="p=0"', stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
output = result.communicate()
return output[0]
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
x = (os.path.join(BASE_DIR,'uploads/video.mkv'))
getLength(x)
这是我遇到的错误信息:
Traceback (most recent call last):
File "/home/aman/Desktop/stream/src/stream/uploads/sadf.py", line 9, in <module>
getLength(x)
File "/home/aman/Desktop/stream/src/stream/uploads/sadf.py", line 4, in getLength
result = subprocess.Popen('ffprobe -i input_video -show_entries format=duration -v quiet -of csv="p=0"', stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
[Finished in 0.1s with exit code 1]
[shell_cmd: "python" -u "/home/aman/Desktop/stream/src/stream/uploads/sadf.py"]
[dir: /home/aman/Desktop/stream/src/stream/uploads]
[path: /home/aman/bin:/home/aman/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
Popen
是否允许命令作为字符串。 - FamousJameoussubprocess.Popen('ls -l')
,我会得到与您相同的错误。如果我改为运行subprocess.Popen('ls -l'.split())
,它将正确运行。 - FamousJameous