views:

336

answers:

2

I created a rails class with a video attachment, and i want to know how to get the length of a video that is uploaded to my application. How can I achieve that ?

+2  A: 

Use ffmpeg and the RVideo gem, which is a thin Ruby wrapper around it. There's a lot of forks of the RVideo project, personally I use http://github.com/greatseth/rvideo because it supports capturing frames from video and saving them as images. When it's all set up, you can do this:

video_attributes = RVideo::Inspector.new(:file => "/path/to/file", :ffmpeg_binary => "/usr/local/bin/ffmpeg" )
video_attributes.duration # duration in milliseconds
Ben
works great, thx Ben.
giovanni
A: 

Thanks, you saved my time.

satish