Created
September 8, 2011 14:25
-
-
Save gfontenot/1203520 to your computer and use it in GitHub Desktop.
Get duration of a video file with Ruby 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 get_movie_duration video_file | |
# Run ffmpeg on the video, and do it silently | |
ffmpeg_output = `/usr/local/bin/ffmpeg -i "#{video_file}" 2>&1` | |
# Find the duration in the output, and force a return if it's found | |
/duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})/i.match(ffmpeg_output) { |m| return m[1] } | |
# If it didn't get a match, something is wrong. Log the error | |
return "FFMPEG ERROR" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment