]> git.rmz.io Git - dotfiles.git/blob - bin/rename-video.sh
017179db274a2fdebc4d3162a8aaf1a209f91615
[dotfiles.git] / bin / rename-video.sh
1 #!/bin/bash
2
3 get_videoinfo() {
4 local -a mediainfo
5 IFS=,
6 mediainfo=( $(mediainfo --Output='Video;%Width%,%Height%,%ScanType%,%Format%,%Codec%' "$1") )
7 mediainfo=( $(ffprobe -select_streams v -show_entries stream=codec_name,width,height -of compact "$1" 2> /dev/null) )
8 local width=${mediainfo[0]}
9 local height=${mediainfo[1]}
10 local scan=${mediainfo[2]}
11 local format=${mediainfo[3]}
12 local codecid=${mediainfo[4]}
13
14 echo ${mediainfo[@]}
15 return
16
17 # same tests xbmc does:
18 # https://github.com/xbmc/xbmc/blob/master/xbmc/utils/StreamDetails.cpp#L514
19 if (( $width <= 720 && $height <= 480 )); then
20 resolution=480
21 elif (( $width <= 768 && $height <= 576)); then
22 resolution=576
23 elif (( $width <= 960 && $height <= 544)); then
24 resolution=540
25 elif (( $width <= 1280 && $height <= 720)); then
26 resolution=720
27 else
28 resolution=1080
29 fi
30
31 if [[ "$scan" == "Progressive" ]]; then
32 resolution+="p"
33 elif [[ "$scan" == "Interlaced" ]]; then
34 resolution+="i"
35 fi
36
37 vcodec=
38 if [[ "$format" == "AVC" ]]; then
39 vcodec=h264
40 elif [[ "$format" == "VC-1" && "$codecid" == "WVC1" ]]; then
41 vcodec=wvc1
42 elif [[ "$codecid" == "XVID" ]]; then
43 vcodec=xvid
44 elif [[ "$codecid" == "DIV3" || "$codecid" == "DX50" || "$codecid" == "DIVX" ]]; then
45 vcodec=divx
46 elif [[ "$codecid" == "V_MPEG2" ]]; then
47 vcodec=mpeg2
48 elif [[ "$codecid" == "MP42" ]]; then
49 vcodec=mp42
50 else
51 echo $f
52 echo $format $codecid
53 fi
54 }
55
56 #TODO
57 get_audioinfo() {
58 local -a mediainfo
59 IFS=,
60 mediainfo=( $(mediainfo --Output='General;%Audio_Format_List%,%Audio_Language_List%,%AudioCount%' "$1") )
61 IFS=' / '
62 local format=( ${mediainfo[0]} )
63 local lang=( ${mediainfo[1]} )
64 local cnt=${mediainfo[2]}
65
66 audio=
67 local -i i=0
68 while (( $i < $cnt )) ; do
69 local iformat=${format[$i]}
70 local ilang=${lang[$i]}
71
72 acodec=
73 if [[ "$iformat" == "DTS" ]]; then
74 acodec=dts
75 elif [[ "$iformat" == "AC-3" ]]; then
76 acodec=ac3
77 elif [[ "$iformat" == "MPEG Audio" ]]; then
78 acodec=mp3
79 else
80 echo "$f"
81 echo "$iformat"
82 fi
83 alang=
84 if [[ "$ilang" == "English" ]]; then
85 alang=en
86 elif [[ "$ilang" == "German" ]]; then
87 alang=de
88 elif [[ "$ilang" == "French" ]]; then
89 alang=fr
90 else
91 echo "$f"
92 echo "$ilang"
93 fi
94 audio+="[${alang}]{${acodec}}"
95 i+=1
96 done
97 }
98
99 for f in "$@"; do
100 echo "$f"
101 get_videoinfo "$f"
102 #get_audioinfo "$f"
103 # echo "{$resolution}{$vcodec}$audio"
104 done