# IO.popen question

**URL:** <https://www.ruby-forum.com/t/io-popen-question/98903>\
**Category:** Ruby\
**Created:** [July 18, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/io-popen-question/98903 "2006-07-18T22:03:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [July 18, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/io-popen-question/98903/1 "2006-07-18T22:03:42Z")

</div>

I posted this on the Rails forum but is really just a ruby question…

////

iâ??m fairly new to ruby…

any suggestions getting the below to work…

iâ??d like to use myfile\_field.read within encodeVideo

and then self.data = Student\_Interviews.flv

class Myfile \< ActiveRecord::Base  
.  
.  
.  
def encodeVideo opts #, stream  
IO.popen(â?ffmpeg #{opts}â?, â??wâ??)#{ |io| io.puts stream}  
end

def myfile=(myfile\_field)  
if myfile\_field and myfile\_field.length \> 0

encodeVideo â??-i /tmp/Student\_Interviews.mov -ar 22050 -ab 64 -f flv -s  
320Ã?240 /tmp/Student\_Interviews.flvâ?#, myfile\_field.read

#self.data = myfile\_field.read  
self.filename = Myfile.base\_part\_of(myfile\_field.original\_filename) +  
Date.to\_s  
filesize = (myfile\_field.length / 1000).to\_i  
if filesize == 0  
self.filesize = 1 # a file of 0 KB doesnâ??t make sense  
else  
self.filesize = filesize  
end

end  
end

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [July 19, 2006, 12:40am UTC](https://www.ruby-forum.com/t/io-popen-question/98903/2 "2006-07-19T00:40:08Z")

</div>

Michael B. wrote:

> I posted this on the Rails forum but is really just a ruby question…
> 
> ////
> 
> iâ??m fairly new to ruby…
> 
> any suggestions getting the below to work…

Hi,  
It would help if you mentioned what isn’t working for you. Are you  
getting errors? What are they? Where? Or do you just need help with the  
logic?

> def encodeVideo opts #, stream  
> IO.popen(â?ffmpeg #{opts}â?, â??wâ??)#{ |io| io.puts stream}  
> end

I think you want to use io.print, because puts will append a newline.

> if filesize == 0  
> self.filesize = 1 # a file of 0 KB doesnâ??t make sense  
> else  
> self.filesize = filesize  
> end
> 
> end  
> en

Help us help you, as they say.

-Justin

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [July 19, 2006, 5:31am UTC](https://www.ruby-forum.com/t/io-popen-question/98903/3 "2006-07-19T05:31:40Z")

</div>

i need help with the logic and block…

i’ve commented out the areas i like to get working…

#{ |io| io.puts stream}

#, myfile\_field.read
