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
2009-12-08 04:23:43
works great, thx Ben.
giovanni
2009-12-08 05:21:34