Get video duration by URL in Ruby on Rails
First install ffmpeg on your system http://ffmpeg.org/download.html
OR
your_video_path = https://s3-us-west-2.amazonaws.com/its-get-brighter-staging/uploads/video/video/2/Planking.mp4
OR
sudo add-apt-repository ppa:mc3man/trusty-media
And confirm the following message by pressing <enter>:
Also note that with apt-get a sudo apt-get dist-upgrade is needed for initial setup & with some package upgrades More info: https://launchpad.net/~mc3man/+archive/ubuntu/trusty-media Press [ENTER] to continue or ctrl-c to cancel adding it
Update the package list.
sudo apt-get update sudo apt-get dist-upgrade
Now FFmpeg is available to be installed with apt:
sudo apt-get install ffmpegIn Controller:
your_video_path = https://s3-us-west-2.amazonaws.com/its-get-brighter-staging/uploads/video/video/2/Planking.mp4
result = `ffmpeg -i #{your_video_path} 2>&1`
videotime = result.match("Duration: ([0-9]+):([0-9]+):([0-9]+).([0-9]+)")[0].split("Duration: ").last.split(".").first
Comments
Post a Comment