Skip to content

Instantly share code, notes, and snippets.

@jarun
Last active February 15, 2020 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarun/e822b13774cd64e177dc333a74be6765 to your computer and use it in GitHub Desktop.
Save jarun/e822b13774cd64e177dc333a74be6765 to your computer and use it in GitHub Desktop.
Get the size to duration ratio of a media
#!/usr/bin/env sh
# Description: POSIZ compliant script to get the size to duration of a media file
# Requires: mediainfo, bc, ls
#
# For sorted output: ratio.sh | sort -rg
for file in *; do
# get duration in milliseconds->mins
ms=$(mediainfo --Inform="Video;%Duration%" "$file")
min=$(echo "scale=2;${ms}/60000" | bc)
# get the file size
size=$(ls -l "$file" | cut -d" " -f5)
mb=$(echo "scale=2;${size}/1048576" | bc)
# get mb/min ration
ratio=$(echo "scale=2;${mb}/${min}" | bc)
# echo $ratio "$file"
echo $ratio $(ls -sh "$file")
done
@jarun
Copy link
Author

jarun commented Feb 15, 2020

ratio | sort -nr > ratio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment