Cannot run ffmpeg as a subprocess in Ruby

I am trying to execute the code to determine the resolution of the video by running the ffmpeg utility as a subprocess and getting its output and analyzing it:

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

... but the ffmpeg output is still connected to stdout and ffmepgIO.readlines is empty. Is there any special treatment needed for the ffmpeg utility? Or is there another way to get ffmpeg output? I tested this code under WinXP and Fedora Linux - the results are the same.

+5
source share
3 answers

To follow the mouviciel comments, you need to use something like popen3 :

require 'open3'

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

(btw, , popen , , )

+7

FFmpeg stdout . (, ) ffmpeg stderr.

+3

Depending on what you are trying to do, it may be easier to use rvideo gem .

For example:

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

All Articles