Skip to content

Instantly share code, notes, and snippets.

@kencoba
Created June 1, 2017 09:59
Show Gist options
  • Save kencoba/9324010cff7dc62e930678420c0265da to your computer and use it in GitHub Desktop.
Save kencoba/9324010cff7dc62e930678420c0265da to your computer and use it in GitHub Desktop.
Listing duration of mp4s.
#! /bin/sh
exec ruby -S -x "$0" "$@"
#! ruby
def h_mm_ss(sec)
min, ss = sec.to_i.divmod(60)
hh , mm = min.divmod(60)
"%dh%02dm%02ds" % [hh, mm, ss]
end
while $file = gets
$file.chomp!
$result = `ffprobe #{$file} -hide_banner -show_entries format=duration`
$duration = $result.gsub(/(\s)/,"").match(%r{\[FORMAT\]duration=(.+?)\[/FORMAT\]})[1].to_i
print $duration, "\t" , h_mm_ss($duration), "\t", $file, "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment