-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbucket_video_by_resolution
30 lines (24 loc) · 1.02 KB
/
bucket_video_by_resolution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
die() { printf %s "${@+$@$'\n'}" 1>&2 ; exit 1 ; }
see() ( { set -x; } 2>/dev/null ; "$@" )
mvtovidres() {
[[ -f "$1" ]] || return
local res ; res="$(2>/dev/null ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$1")" # https://stackoverflow.com/a/27831698
[[ "$res" ]] || return
# echo "$res"
case "$res" in # give standard names to "TV resolutions"
1920x1080 ) res="@1080p" ;;
1280x720 ) res="@720p" ;;
esac
# echo "$res"
local dn="./$res/"
# echo "$dn"
# echo "${1}"
# echo "${1#"${dn@E}"}"
[[ "${1#"${dn@E}"}" != "${1}" ]] && return # if file already located in target dir $dn
[[ -d "$res" ]] || mkdir -- "$dn"
[[ -d "$res" ]] && see mv -- "$1" "$dn"
}
# https://stackoverflow.com/a/26349346 variant of https://stackoverflow.com/a/8489394
find . -maxdepth 1 -type f \( -iname '*.mp4' -o -iname '*.webm' -o -iname '*.flv' \) -print0 | while IFS= read -r -d '' file; do mvtovidres "$file" ; done
# NONRECURSIVE!!!