Search code examples
ruby-on-railsruby-on-rails-3youtuberubygemsmp4

Get mp3 & mp4 time length of file in rails


I'm using Rails 3.2+ and am wondering if there is an easy way to find out what the time length of a file is on my server. For example if I had a video file in mp4 format, how would I find out that the length of the video is say 4 minutes 2 seconds long? Same goes for mp3, or external sources like youtube/vimeo. If there is a gem that does this that is fine as well, thanks.


Solution

  • For youtube/vimeo - https://github.com/thibaudgg/video_info

    For video - https://github.com/streamio/streamio-ffmpeg

    For mp3s - https://robinst.github.io/taglib-ruby/