-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathjietu
295 lines (239 loc) · 12.8 KB
/
jietu
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
#
# https://github.com/Aniverse/inexistence
# Author: Aniverse
#
Script_UpDate=2019.01.26
Script_Version=2.3.5
# --------------------------------------------------------------------------------
# If you would like to change the output path,
# sets CustomedOutput=1,then write your output path to OUTPUT
CustomedOutput=1
OUTPUT="$HOME/iSeed/01.Screenshots"
# --------------------------------------------------------------------------------
function Deprecated() {
DW=$VideoHeight
DARX=` echo $DAR | sed "s/[0-9]\{1,\}://" `
DARY=` echo $DAR | sed "s/:[0-9]\{1,\}//" `
# DH0=` expr $VideoHeight / $DARX `
# DH=` expr $DH0 \* $DARY `
DH=` echo "$VideoHeight/$DARX*$DARY" | bc -l | awk '{print int($0)}' `
echo -n "${yellow}${bold}The correct resolution should be ${underline}$fenbianlv${reset_underline},${normal} [${cyan}T${normal}]rue or [F]alse " ; read responce
case $responce in
[Tt] | [Tt][Ru][Uu][eE] ) echo -e "The script will take 10 screenshots in $fenbianlv" ;;
[Ff] | [Ff][Aa][Ll][Ss][Ee] ) resolution=input ;;
"" | * ) echo -e "The script will take 10 screenshots in $fenbianlv" ;;
esac
}
# Transform numbers
function even_number () { [ ! $(($2%2)) == 0 ] && eval $1=$( expr $2 + 1 ) ; }
# Cleanup when cancel
cancel() { echo -e "${normal}" ; rm -f ./bc "${outputpath}/${file_title_clean}*" ; exit ; }
trap cancel SIGINT
# Colors
black=$(tput setaf 0); red=$(tput setaf 1); green=$(tput setaf 2); yellow=$(tput setaf 3); blue=$(tput setaf 4); magenta=$(tput setaf 5); cyan=$(tput setaf 6); white=$(tput setaf 7)
bold=$(tput bold); normal=$(tput sgr0); underline=$(tput smul); reset_underline=$(tput rmul); jiacu=${normal}${bold}
mediapath="$1" ; fenbianlv="$2"
Source=undefined
#if [[ $EUID != 0 ]]; then
# yum install bc -y
# apt-get install bc -y
# [[ $(command -v bc) ]] && bc_cli="bc"
bc_cli="bc"
[[ ! $(command -v bc) ]] && { wget --no-check-certificate https://github.com/Aniverse/MissingCLI/raw/master/bc ; chmod +x bc ; bc_cli="./bc" ; }
[[ ! $(command -v ffmpeg) ]] && echo -e "\n${red}${bold}ERROR${jiacu} ffmpeg not found, please install it or set it to your \$PATH\n${normal}" && exit 1
[[ ! $(command -v mediainfo) ]] && echo -e "\n${red}${bold}ERROR${jiacu} mediainfo not found, please install it or set it to your \$PATH\n${normal}" && exit 1
[[ $EUID != 0 ]] && [[ $CustomedOutput == 0 ]] && echo -e "\n${red}${bold}ERROR${jiacu} Please edit this script to set output path first\n${normal}" && exit 1
[[ "$mediapath" == "" ]] && echo -e "\n${red}${bold}WARNING${jiacu} You must input the path to your file with double quotes\n${normal}" && exit 1
[[ ! $( ls "$mediapath" 2>/dev/null ) ]] && echo -e "\n${red}${bold}WARNING${jiacu} This file or dictionary doesn't exist, or it's empty\n${normal}" && exit 1
[[ -d "$mediapath" ]] && {
omediapath="$mediapath"
mediapath=$( find "$mediapath" -type f -print0 | xargs -0 ls -1S 2>&1 | head -1 )
# DVD Name/VIDEO_TS/VTS_01_1.VOB
dirname "$mediapath" | grep VIDEO_TS -q && Source=DVD &&
ifo=$( find "$omediapath" -type f -name "*.[Ii][Ff][Oo]" | xargs ls -S 2>&1 | head -1 ) &&
disk_path="$(dirname "$(dirname "$mediapath")")" && disk_title="$(basename "$disk_path")"
# Blu-ray Name/BDMV/STREAM/00002.m2ts
dirname "$mediapath" | grep STREAM -q && Source=Blu-ray &&
disk_path="$( dirname "$( dirname "$(dirname "$mediapath")")")" && disk_title="$(basename "$disk_path")"
[[ ! -z $disk_title ]] && {
disk_title_clean="$(echo "$disk_title" | tr '[:space:]' '.')"
disk_title_clean="$(echo "$disk_title_clean" | sed s'/[.]$//')"
disk_title_clean="$(echo "$disk_title_clean" | tr -d '(')"
disk_title_clean="$(echo "$disk_title_clean" | tr -d ')')" ; }
if [[ $Source == DVD ]]; then
# echo -e "\nThis is a DVD, ${underline}${mediapath}${reset_underline} would be used for taking screenshots and mediainfo,${normal}"
# echo -e "and the mediainfo of ${underline}${ifo}${reset_underline} would be added to the report too${normal}"
echo -e "\n${bold}This is a DVD, we will take screenshots for a main VOB file,\nand mediainfo reports of a main VOB file and the right IFO file${normal}"
else
# echo -e "\n${red}${bold}ATTENTION${normal} You have input a dictionary, so we find the biggest file for taking screenshots,\nwhich is ${underline}${mediapath}${reset_underline}${normal}"
echo -e "\n${bold}You have input a dictionary, we find the biggest file for taking screenshots,\nwhich is ${blue}${mediapath}${normal}"
fi ; }
# TEST MODE
[[ $fenbianlv == -t ]] && {
VideoResolution=$( ffmpeg -i "$mediapath" 2>&1 | grep -E "Stream.*Video" | grep -Eo "[0-9]{2,5}x[0-9]{2,5}" )
VideoWidth=$( echo $VideoResolution | sed "s/x[0-9]\{2,\}//" )
VideoHeight=$( echo $VideoResolution | sed "s/[0-9]\{2,\}x//" )
DAR=$( ffmpeg -i "$mediapath" 2>&1 | grep -Eo "DAR [0-9]+:[0-9]+" | sed "s/DAR //" )
DARX=$( echo $DAR | sed "s/:[0-9]\{1,\}//" )
DARY=$( echo $DAR | sed "s/[0-9]\{1,\}://" )
SAR=$( ffmpeg -i "$mediapath" 2>&1 | grep -Eo "SAR [0-9]+:[0-9]+" | sed "s/SAR //" )
SARX=$( echo $SAR | sed "s/:[0-9]\{1,\}//" )
SARY=$( echo $SAR | sed "s/[0-9]\{1,\}://" )
PAR=$( mediainfo -f "$mediapath" 2>&1 | grep -i "Pixel aspect ratio" | grep -oE "[0-9.]+" )
# 第一种,720×480 16:9,算出来 720×405,也就是重新计算 Y
# $VideoWidth/$DARY*$DARX=720÷16×9=405
DAR1_W=$VideoWidth
DAR1_H_BC=$( echo "$VideoWidth/$DARX*$DARY" | bc -l | awk '{print int($0)}' )
even_number DAR1_H_BC $DAR1_H_BC
DAR1_H=$( expr $(expr $VideoWidth / $DARX) \* $DARY )
DAR1_R_BC="${DAR1_W}x${DAR1_H_BC}"
DAR1_R="${DAR1_W}x${DAR1_H}"
# 第二种,720×480 16:9,算出来 853×480,也就是重新计算 X
# $VideoHeight/$DARX*$DARY=480÷9×16=853
#
DAR2_H=$VideoHeight
DAR2_W_BC=$( echo "$VideoHeight/$DARY*$DARX" | bc -l | awk '{print int($0)}' )
even_number DAR2_W_BC $DAR2_W_BC
DAR2_W=$( expr $(expr $VideoHeight / $DARY) \* $DARX )
DAR2_R_BC="${DAR2_W_BC}x${DAR2_H}"
DAR2_R="${DAR2_W}x${DAR2_H}"
# 第三种,看 SAR,720×480 32:27,算出来 853×480
# $VideoWidth/$SARX*$SARY=720÷27×32=853
# 这个其实也只变 Width,但其实我们可以考虑当 SAR 小于 1 的时候改成用 Height 算
# 蛋疼的是这个需要 bc,我怕某些共享盒子没有 bc(seedboxes.cc 和 dediseedbox 就没有)
# bc 不确定是不是直接复制过来就行
SAR1_H=$VideoHeight
SAR1_W_BC=$( echo "$VideoWidth/$SARY*$SARX" | bc -l | awk '{print int($0)}' )
even_number SAR1_W_BC $SAR1_W_BC
SAR1_W=$( expr $(expr $VideoWidth / $SARY) \* $SARX )
SAR1_R_BC="${SAR1_W_BC}x${SAR1_H}"
SAR1_R="${SAR1_W}x${SAR1_H}"
# https://github.com/TnS-hun/PtpUploader/blob/master/src/PtpUploader/Tool/Ffmpeg.py#L42
# 有一种算法,是用 DAR 比视频分辨率的 AR 大时,重新算 X,反之 算 Y
# 蛋疼的是 shell 自带的那些不支持浮点数比较,不过 expr 似乎是取整算法,比如
# expr 8 / 9 = 0
# expr 17 / 9 = 1
# 这样子的话可以根据 expr SAR 的数值来选择怎么操作
if [[ $( expr $SARX / $SARY ) == 0 ]] ; then
resize=Y
TrueRes="${DAR1_W}x${DAR1_H_BC}"
else
resize=X
TrueRes="${DAR2_W_BC}x${DAR2_H}"
fi
# ${cyan}${bold}FileName ${yellow}$mediapath
echo -e "
${cyan}${bold}bc Command ${yellow}$bc_cli
${cyan}${bold}Source Type ${yellow}$Source"
[[ $Source == DVD ]] && echo -e \
"${cyan}${bold}DVD IFO File ${yellow}$ifo
${cyan}${bold}DVD Title ${yellow}$disk_title_clean"
[[ $Source == Blu-ray ]] && echo -e \
"${cyan}${bold}Blu-ray Title ${yellow}$disk_title_clean"
echo -e "
${cyan}${bold}Display Aspect Ratio ${yellow}$DAR
${cyan}${bold}Sample Aspect Ratio ${yellow}$SAR
${cyan}${bold}Pixel Aspect Ratio ${yellow}$PAR
${cyan}${bold}Video Resolution ${yellow}$VideoResolution
${cyan}${bold}Right Resolution ${yellow}$TrueRes
${cyan}${bold}DAR-1 Resolution (bc) ${yellow}$DAR1_R_BC
${cyan}${bold}DAR-1 Resolution ${yellow}$DAR1_R
${cyan}${bold}DAR-2 Resolution (bc) ${yellow}$DAR2_R_BC
${cyan}${bold}DAR-2 Resolution ${yellow}$DAR2_R
${cyan}${bold}SAR Resolution (bc) ${yellow}$SAR1_R_BC
${cyan}${bold}SAR Resolution ${yellow}$SAR1_R
${green}
mediapath=\"$mediapath\"
ffmpeg -i \"\$mediapath\"
mediainfo -f \"\$mediapath\"
${normal}"
[[ ! $Source == undefined ]] && ls -hAlvZ --color "$(dirname "$mediapath")"
echo
exit 0 ; }
# Calculating resolution
if [[ "$fenbianlv" == "" ]]; then
########################################################################################################################
echo -e "\n${bold}Calculating resolution ...${normal} "
VideoResolution=$( ffmpeg -i "$mediapath" 2>&1 | grep -E "Stream.*Video" | grep -Eo "[0-9]{2,5}x[0-9]{2,5}" )
VideoWidth=$( echo $VideoResolution | sed "s/x[0-9]\{2,\}//" )
VideoHeight=$( echo $VideoResolution | sed "s/[0-9]\{2,\}x//" )
DAR=$( ffmpeg -i "$mediapath" 2>&1 | grep -Eo "DAR [0-9]+:[0-9]+" | sed "s/DAR //" )
DARX=$( echo $DAR | sed "s/:[0-9]\{1,\}//" )
DARY=$( echo $DAR | sed "s/[0-9]\{1,\}://" )
SAR=$( ffmpeg -i "$mediapath" 2>&1 | grep -Eo "SAR [0-9]+:[0-9]+" | sed "s/SAR //" )
SARX=$( echo $SAR | sed "s/:[0-9]\{1,\}//" )
SARY=$( echo $SAR | sed "s/[0-9]\{1,\}://" )
if [[ $( expr $SARX / $SARY ) == 0 ]] ; then # Re-calculate Y (Height)
resize=Y
SSR_W=$VideoWidth
SSR_H=$( echo "$VideoWidth/$DARX*$DARY" | $bc_cli -l | awk '{print int($0)}' )
even_number SSR_H $SSR_H
fenbianlv="${SSR_W}x${SSR_H}"
else # Re-calculate X (Width)
resize=X
SSR_H=$VideoHeight
SSR_W=$( echo "$VideoHeight/$DARY*$DARX" | $bc_cli -l | awk '{print int($0)}' )
even_number SSR_W $SSR_W
fenbianlv="${SSR_W}x${SSR_H}"
fi
echo -e "${bold}
${cyan}Aspect Ratio ${yellow}$DAR
${cyan}Resolution ${yellow}$VideoResolution ---> $fenbianlv${normal}"
########################################################################################################################
fi
[[ $Source == DVD ]] && {
echo -e "${bold}${cyan}DVD IFO File ${yellow}$ifo
${cyan}DVD VOB File ${yellow}$mediapath${normal}" ; }
file_title=$(basename "$mediapath")
file_title_clean="$(echo "$file_title" | tr '[:space:]' '.')"
file_title_clean="$(echo "$file_title_clean" | sed s'/[.]$//')"
file_title_clean="$(echo "$file_title_clean" | tr -d '(')"
file_title_clean="$(echo "$file_title_clean" | tr -d ')')"
[[ ! -z $disk_title_clean ]] &&
file_title_clean="$(echo "${disk_title_clean}.${file_title_clean}")"
# Calculating timestampsetting
duration1=$(ffmpeg -i "$mediapath" 2>&1 | egrep '(Duration:)' | cut -d ' ' -f4 | cut -c1-8)
duration2=`date -u -d "1970-01-01 $duration1" +%s`
if [[ "${duration2}" -ge 3600 ]]; then
timestampsetting=331
elif [[ "${duration2}" -ge 1500 && "${duration2}" -lt 3600 ]]; then
timestampsetting=121
elif [[ "${duration2}" -ge 600 && "${duration2}" -lt 1500 ]]; then
timestampsetting=71
elif [[ "${duration2}" -lt 600 ]]; then
timestampsetting=21
fi
[[ $CustomedOutput == 0 ]] && mkdir -p "/etc/inexistence/07.Screenshots" && outputpath="/etc/inexistence/07.Screenshots"
[[ ! $CustomedOutput == 0 ]] && mkdir -p "$OUTPUT" && outputpath="$OUTPUT"
echo
# Screenshots
for c in {01..10} ; do
i=`expr $i + $timestampsetting` ; timestamp=`date -u -d @$i +%H:%M:%S`
echo -n "Writing ${blue}${file_title_clean}.scr${c}.png${normal} from timestamp ${blue}${timestamp}${normal} ... "
# ffmpeg -y -ss $timestamp -i "$mediapath" -vframes 1 -s $fenbianlv "${outputpath}/${file_title_clean}.scr${c}.png" > /dev/null 2>&1
ffmpeg -y -ss $timestamp -i "$mediapath" -ss 00:00:01 -frames:v 1 -s $fenbianlv "${outputpath}/${file_title_clean}.scr${c}.png" > /dev/null 2>&1
echo -e "${green}DONE${normal}"
[[ $(command -v nconvert) ]] && {
echo -n "Compressing ${blue}${file_title_clean}.scr${c}.png${normal} ${normal} ... "
nconvert -out png -clevel 6 -o "${outputpath}/${file_title_clean}.scr${c}_1.png" "${outputpath}/${file_title_clean}.scr${c}.png" > /dev/null 2>&1
mv -f "${outputpath}/${file_title_clean}.scr${c}_1.png" "${outputpath}/${file_title_clean}.scr${c}.png" > /dev/null 2>&1
echo -e "${green}DONE${normal}" ; }
done
# mediainfo
echo -ne "\nWriting ${blue}${file_title_clean}.mediainfo.txt${normal} ... "
mediainfo "$mediapath" > "${outputpath}/${file_title_clean}.mediainfo.txt"
sed -i '/${outputpath}\//'d "${outputpath}/${file_title_clean}.mediainfo.txt"
echo -e "${green}DONE${normal}"
[[ ! -z "$ifo" ]] && {
echo -ne "Adding IFO mediainfo to ${blue}${file_title_clean}.mediainfo.txt${normal} ... "
echo -e "\n\n" >> "${outputpath}/${file_title_clean}.mediainfo.txt"
mediainfo "$ifo" >> "${outputpath}/${file_title_clean}.mediainfo.txt"
echo -e "${green}DONE${normal}" ; }
# finished
echo -e "\n${bold}Done. Outputs are stored in ${yellow}\"${outputpath}\"${normal}\n"
rm -f ./bc
usage() {
rm -f /usr/local/bin/jietu && nano /usr/local/bin/jietu && chmod +x /usr/local/bin/jietu
wget -q https://github.com/Aniverse/inexistence/raw/master/00.Installation/script/jietu -O /usr/local/bin/jietu && chmod +x /usr/local/bin/jietu
}