Skip to content

Instantly share code, notes, and snippets.

@gfontenot
Created September 8, 2011 14:25
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfontenot/1203520 to your computer and use it in GitHub Desktop.
Save gfontenot/1203520 to your computer and use it in GitHub Desktop.
Get duration of a video file with Ruby and FFMpeg
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