Created
January 18, 2010 22:54
-
-
Save nukturnal/280455 to your computer and use it in GitHub Desktop.
Extracting audio length with Rails and ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.get_audio_length(filepath) | |
pipe = "ffmpeg -i "+ filepath.to_s+" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//" | |
command = `#{pipe}` | |
if command =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/ | |
#convert the result to only secs | |
duration = ($2.to_i * 60) + $3.to_i | |
end | |
#return and array containing the seconds and the human readable time length, ["6453","03:54"] | |
return "#{duration.to_s},#{$2}:#{$3}".split(",") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment