]>
Raphaƫl G. Git Repositories - tools/blob - vidpack
3 #Set temporary directory
6 #Without temporary directory
7 if [ ! -d "$tmpdir" ]; then
8 #Create temporary directory or die
9 mkdir -p "$tmpdir" || exit 1;
15 #Iterate on each video in cur dir older than 1h
16 #for i in `find $docdir -maxdepth 1 -type f,l -name '*.mov' -o -name '*.mp4' -mmin +60`; do
17 #for i in `find . -maxdepth 1 -type f \( -name '*.mp4' -o -name '*.avi' -o -name '*.mpg' -o -name '*.mkv' \)`; do
18 find .
-maxdepth 1 -type f \
( -iname '*.mov' -o -iname '*.mp4' -o -iname '*.avi' -o -iname '*.mpg' -o -iname '*.mkv' \
) -print0 | while read -d $
'\0' i
; do
20 fdate
=$(date -u --rfc-3339=ns -r "$i" | perl -pne 's/\..*$/.000000Z/; s/ /T/');
24 #File must not be empty
29 if [ -z "$fdate" ]; then
30 #File date must exists
35 #XXX: may miss if filename don't match /^(.*[^0-9])?YYYYMMDD[^0-9]?HHMMSS([^0-9].*)?$/
36 ndate
=$(echo "$i" | perl -ne 'print if s/^(?:.*[^0-9])?
([0-9]{4})([0-9]{2})([0-9]{2})(?
:[^
0-9])?
([0-9]{2})([0-9]{2})([0-9]{2})(?
:[^
0-9].
*)?$
/\
1-\
2-\
3T\
4:\
5:\
6.000000Z
/');
39 if [ -z "$ndate" ]; then
41 #XXX: catch when filename match only /^(.*[^0-9])?20YYMMDD([^0-9].*)?$/
42 ndate=$(echo "$i" | perl -ne 'print if s/^(?:.*[^0-9])?(20[0-9]{2})([0-9]{2})([0-9]{2})(?:[^0-9].*)?$/\1-\2-\3T00:00:00.000000Z/');
46 cdate
=$(ffprobe -hide_banner -v error -show_entries format_tags=date,creation_time,com.apple.quicktime.creationdate -of default=nokey=1:noprint_wrappers=1 -i "$i" 2> /dev/null | perl -ne '$l = $_ unless /^$/; END { chomp $l; print $l }');
49 date=$(echo -e "$fdate\n$ndate\n$cdate" | perl -ne '$l = $_ unless /^(0000:00:00 00:00:00|)$
/; END
{ chomp
$l; print
$l }');
52 dest="$(echo "$i" | perl -pne 's/\.(?:mp4|avi|mpg|mkv)$//').webm
";
55 passlog="$tmpdir/$(echo "$i" | perl -pne 's%(?:.*/)([^
/]+)\.
(?
:mp4
|avi
|mpg
|mkv
)$
%\
1%;s
% %_
%g
')";
58 #if [ -f "$passlog-0.log" ]; then
60 # echo "Operation in progress: $passlog-0.log exists"
67 sourcerate=$(ffprobe -hide_banner -v quiet -select_streams v:0 -show_entries stream=bit_rate -of default=nokey=1:noprint_wrappers=1 "$i" | perl -ne 'chomp; print');
72 #With sourcerate >= 5120k (1080p)
73 if [ $sourcerate -ge 5120000 ]; then
76 #With sourcerate >= 2560k (720p)
77 elif [ $sourcerate -ge 2560000 ]; then
80 #With sourcerate >= 1024k
81 elif [ $sourcerate -ge 1024000 ]; then
84 #With sourcerate >= 512k
85 elif [ $sourcerate -ge 512000 ]; then
91 if [ ! -f "$dest" ]; then
93 if [ ! -f "$passlog-0.log" ]; then
95 #ffmpeg -i "$i" -v error -passlogfile "$passlog" -c:v libaom-av1 -b:v "$bitrate" -pass 1 -an -f null /dev/null < /dev/null;
96 ffmpeg -i "$i" -v error -passlogfile "$passlog" -c:v libvpx-vp9 -b:v "$bitrate" -pass 1 -an -f null /dev/null < /dev/null;
106 if [ -f "$passlog-0.log" ]; then
108 #XXX: see http://wiki.webmproject.org/webm-metadata/global-metadata#TOC-Official-Tags
109 #ffmpeg -y -i "$i" -v error -passlogfile "$passlog" -c:v libaom-av1 -b:v "$bitrate" -pass 2 -pix_fmt yuv420p -c:a libopus -movflags +faststart -metadata creation_time="$date" -fflags +bitexact "$dest" < /dev/null;
110 ffmpeg -y -i "$i" -v error -passlogfile "$passlog" -c:v libvpx-vp9 -b:v "$bitrate" -pass 2 -pix_fmt yuv420p -c:a libopus -movflags +faststart -metadata creation_time="$date" -fflags +bitexact "$dest" < /dev/null;
112 #With second pass pass
114 #With non empty dest file
115 #if [ -s "$dest" ]; then
116 # #Remove source file
121 if [ -f "$passlog-0.log" ]; then
123 unlink "$passlog-0.log";
130 #Remove temporary directory
131 rmdir "$tmpdir" || true;