我已经在PC上使用pip ffprobe命令安装了ffprobe,并从here安装了ffmpeg。使用ffmpeg获取python中的视频持续时间
但是,我仍然无法运行列出的代码here。
我尝试使用下面的代码失败。
SyntaxError: Non-ASCII character '\xe2' in file GetVideoDurations.py on line 12, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
有没有人知道什么是错的?我没有正确引用目录吗?我需要确保.py和视频文件位于特定位置吗?
import subprocess
def getLength(filename):
result = subprocess.Popen(["ffprobe", "filename"],
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
return [x for x in result.stdout.readlines() if "Duration" in x]
fileToWorkWith = 'C:\Users\PC\Desktop\Video.mkv'
getLength(fileToWorkWith)
道歉,如果问题是有点基本。我所需要的就是能够遍历一组视频文件并获得它们的开始时间和结束时间。
谢谢!
谢谢Chamath。我会在哪里使用第一个命令?另外,当我运行你的方法时,我仍然遇到同样的错误。 – OSK
第一条命令是我们在python中用'Popen'执行的命令行FFprobe命令。你的错误令人困惑。你的命令中的“第12行”在哪里?您需要包含完整的python脚本。还要记住反斜杠是一个转义字符,您可能需要使用\\而不是\\ – Chamath
第二行应该是'result = subprocess.Popen(['ffprobe -i%s -show_entries format = duration -v quiet -of csv =“p = 0”'%input_video],stdout = subprocess.PIPE,stderr = subprocess.STDOUT)',它会给出一个没有方括号的错误。 –