Trouble capturing output of spawned process

E

Eric Marthinsen

Hello-

I'm using the backtick notation to drive FFmpeg from Ruby. When FFmpeg
runs, it outputs a fair amount of informational text to the console. I'm
unable to read that data from my script. Here is my code:

result = `ffmpeg -i test.avi -f flv -acodec mp3 output.flv`
puts "HERE IS THE RESULT\n"
puts result
puts "\nRESULT COMPLETE"

Here is the result when I run it:

FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et
al.
configuration: --enable-gpl --enable-pp --enable-swscaler
--enable-pthreads --enable-libvorbis --enable-libtheora --enable-libogg
--enable-libgsm --enable-dc1394 --disable-debug --enable-shared
--prefix=/usr
libavutil version: 1d.49.3.0
libavcodec version: 1d.51.38.0
libavformat version: 1d.51.10.0
built on Jun 3 2007 20:59:25, gcc: 4.1.3 20070528 (prerelease)
(Ubuntu 4.1.2-9ubuntu2)
Input #0, avi, from 'test.avi':
Duration: 00:00:01.8, start: 0.000000, bitrate: 6571 kb/s
Stream #0.0: Video: cinepak, yuv420p, 640x480, 25.00 fps(r)
Output #0, flv, to 'output.flv':
Stream #0.0: Video: flv, yuv420p, 640x480, q=2-31, 200 kb/s, 25.00
fps(c)
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
frame= 45 q=31.0 Lsize= 436kB time=1.8 bitrate=1985.8kbits/s
video:435kB audio:0kB global headers:0kB muxing overhead 0.203409%
HERE IS THE RESULT


RESULT COMPLETE


I was expecting the output to be bracketed by the text "HERE IS THE
RESULT" and "RESULT COMPLETE", but it looks like the infomation isn't
being put into the variable.

I'm running this using Ruby 1.8.6 on Ubuntu 7.10. I'm connecting to the
machine using PuTTY from my Windows XP machine.

Does anyone know what might be going on?

Regards-
Eric
 
P

Paul Mckibbin

Eric said:
I was expecting the output to be bracketed by the text "HERE IS THE
RESULT" and "RESULT COMPLETE", but it looks like the infomation isn't
being put into the variable.

It may not be doing what you think it is. You may find that the output
from ffmpeg is going directly to stderr. Inspect result to see if it
contains anything, and if not then try

result=`ffmpeg -i test.avi -f flv -acodec mp3 output.flv 2>&1`

to see if that does the trick.
 
E

Eric Marthinsen

Hi Paul-

Thanks for your reply. I inspected the variable result and it is an
empty string. I tried the syntax that you recommended, but it caused
that commnd to hang. What is the "2>&1" supposed to do? Does that pipe
stderr into stdout?

Regards-
Eric
 
E

Eric Marthinsen

Actually, it looks like the 2>&1 syntax might be working. I think the
last time I ran the script, it paused to ask me if I wanted to overwrite
a file, since I didn't see the prompt, I wasn't able to repond. If the
file doesn't exist, it seems to complete just fine.

A second test I just did confirmed this.
 
P

Paul Mckibbin

Eric said:
last time I ran the script, it paused to ask me if I wanted to overwrite
a file, since I didn't see the prompt, I wasn't able to repond. If the

If that's going to be an issue you can use IO#popen to control it more
interactively.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top