代码之家  ›  专栏  ›  技术社区  ›  Eskat0n

无法在Ruby中将ffmpeg作为子进程运行

  •  5
  • Eskat0n  · 技术社区  · 17 年前

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

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

    3 回复  |  直到 17 年前
        1
  •  7
  •   Sebastien Tanguy    17 年前

    要跟进mouviciel的评论,你需要使用类似的东西 popen3 :

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

    (顺便说一句,请注意,使用数组作为popen的参数会更安全一些,特别是如果文件名可能包含空格或任何需要以其他方式引用的字符)

        2
  •  3
  •   mouviciel    17 年前

    FFmpeg stdout用于媒体输出。对于日志信息(如分辨率),您必须解析ffmpeg stderr。

        3
  •  0
  •   Olly    17 年前

    rvideo gem .

    video = RVideo::Inspector.new(:file => path_to_file)
    video.resolution # => "480x272"
    video.width # => 480
    video.height # => 272