tags:

views:

555

answers:

3

I am trying following code to determine video resolution by running ffmpeg utility as subprocess and gain its output and parse it:

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

...but ffmpeg output is still connected to stdout and ffmepgIO.readlines is empty. Are there some special treatment needed for ffmpeg utility? Or are there other way to gain ffmpeg output? I tested this code under WinXP and Fedora Linux - results are same.

+3  A: 

FFmpeg stdout is for media output. For logging information (such as resolution) you have to parse ffmpeg stderr.

mouviciel
A: 

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
Olly
I am already disappointed in RVideo gem because it doesn't work with ffmpeg. I inspect source code of this gem and founded that it try tu run ffmpeg just as i described and therefore fails.
Eskat0n
+5  A: 

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)

Sebastien Tanguy