5

我正在尝试以下代码,通过将 ffmpeg 实用程序作为子进程运行并获取其输出并解析它来确定视频分辨率:

IO.popen 'ffmpeg -i ' + path_to_file do |ffmpegIO|
    # my parse goes here
end

...但是 ffmpeg 输出仍然连接到 stdout 并且 ffmepgIO.readlines 是空的。ffmpeg 实用程序是否需要一些特殊处理?还是有其他方法可以获得 ffmpeg 输出?我在 WinXP 和 Fedora Linux 下测试了这段代码——结果是一样的。

4

3 回答 3

7

To follow-up on mouviciel's comment, you would need to use something like popen3:

require 'open3'

Open3.popen3("ffmpeg", "-i", path_to_file) { |stdin, stdout, stderr|
  # do stuff
}

(btw, note that using an array as parameter to popen would be a bit safer, especially if the filename may include spaces or any kind of character that would need to be quoted otherwise)

于 2009-04-16T21:25:54.217 回答
3

FFmpeg 标准输出用于媒体输出。对于日志信息(例如分辨率),您必须解析 ffmpeg 标准错误。

于 2009-04-16T08:41:42.230 回答
0

Depending on what you are trying to do it might be easier to use the rvideo gem.

For example:

video = RVideo::Inspector.new(:file => path_to_file)
video.resolution # => "480x272"
video.width # => 480
video.height # => 272
于 2009-04-16T10:16:25.273 回答