Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run ffmpeg as subprocess in Ruby

Tags:

ruby

ffmpeg

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.

like image 340
Eskat0n Avatar asked Apr 16 '09 08:04

Eskat0n


1 Answers

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)

like image 109
Sebastien Tanguy Avatar answered Sep 29 '22 18:09

Sebastien Tanguy