使用ffmpeg,ffprobe或rvideo在ruby脚本中获取video元数据
我想使用Ruby获取URL引用的video元数据。 此时,我发现了许多相关post,但无法找到如何解决我的问题。
我尝试使用RVideo,但是当我这样做时:
file = RVideo :: Inspector.new(:file =>’http://www.agreatsite.com/avideo.mp4’)
它抛出
‘ArgumentError:找不到文件(http://www.agreatsite.com/avideo.mp4)…
所以我无法使用RVideo获取信息(但是当我在本地计算机上托管文件时,它运行良好)。
然后我尝试使用ffprobe,但我不知道如何读取输出。 到目前为止,我有以下方法,当我在控制台中运行它时“显示”我想要的信息,但它实际上返回“true”,我无法找到如何捕获我需要的输出…
def media_info source = self command = <<-end_command ffprobe -v quiet -print_format json -show_format -show_streams #{source} end_command command.gsub!(/\s+/, " ") system(command) end
希望得到一些帮助,使用ffprobe或RVideo来完成这项工作!
更新:我找到了一种方法来获得我需要的东西。 不确定这是最好的方法:
def get_media_duration
source = self.media[0][:url] command = < 1 end } duration
结束
我想我可以让它以这种方式工作,但对我来说似乎并不优雅。 更好的建议将不胜感激!
检查streamio-ffmpeg,如果您仍在寻找解决方案。 ffprobe现在也支持json格式: ffprobe -print_format json -show_streams #{input_file}