Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ffmpeg、ffprobe或rvideo获取ruby脚本中的视频元数据_Ruby_Ruby On Rails 3_Ffmpeg - Fatal编程技术网

使用ffmpeg、ffprobe或rvideo获取ruby脚本中的视频元数据

使用ffmpeg、ffprobe或rvideo获取ruby脚本中的视频元数据,ruby,ruby-on-rails-3,ffmpeg,Ruby,Ruby On Rails 3,Ffmpeg,我想使用Ruby获取URL引用的视频元数据。在这一点上,我发现了许多相关的帖子,但无法找到如何解决我的问题 我尝试使用RVideo,但当我使用时: file=RVideo::Inspector.new(:file=>'http://www.agreatsite.com/avideo.mp4") 它抛出 'ArgumentError:找不到文件(http://www.agreatsite.com/avideo.mp4) 因此,我无法使用RVideo获取信息(但当我将文件托管在本地计算机上时,它工作

我想使用Ruby获取URL引用的视频元数据。在这一点上,我发现了许多相关的帖子,但无法找到如何解决我的问题

我尝试使用RVideo,但当我使用时:

file=RVideo::Inspector.new(:file=>'http://www.agreatsite.com/avideo.mp4")

它抛出

'ArgumentError:找不到文件(http://www.agreatsite.com/avideo.mp4)

因此,我无法使用RVideo获取信息(但当我将文件托管在本地计算机上时,它工作得很好)

然后我尝试使用ffprobe,但我不知道如何读取输出。 到目前为止,我有以下方法,当我在控制台中运行它时,它“显示”了我想要的信息,但它实际上返回“true”,我无法找到如何捕获我需要的输出

def媒体信息
来源=自我

command=如果您仍在寻找解决方案,请检查streamio ffmpeg。ffprobe现在也支持json格式:
ffprobe-print_format json-show_streams#{input_file}

我不确定我能帮上什么忙,但我在ffmpeg文档中找到了这一点:。当然,您使用的ruby库基本上运行的是不接受URL的
ffmpeg-i
。如果您试图从远程位置打开一个文件,我不确定
RVideo::Inspector
是否以您认为的方式处理该文件,那么您可能可以绕过它。
  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
source = self.media[0][:url]    

command = <<-end_command
  ffprobe -v quiet  -show_streams  #{source}
end_command
command.gsub!(/\s+/, " ")

duration = ""
IO.popen(command) { |io| while (line = io.gets) do
                        puts "++ "+line.inspect
                        duration = line.split("duration=")[1].gsub("\n", "") if line.split("duration=").length > 1
                      end
                  }
duration