]>
Raphaƫl G. Git Repositories - binary/blob - vidpack
4 #XXX: ffplay -vf "curves=all='0/0 0.25/0.375 0.5/0.75 0.75/0.875 1/1'"
6 #Set document directory
12 #Set temporary directory
15 #Without temporary directory
16 if [ ! -d "$tmpdir" ]; then
17 #Create temporary directory or die
18 mkdir -p "$tmpdir" || exit 1;
24 #Change to document directory
25 pushd "$docdir" > /dev
/null
|| exit 1
27 #Iterate on each mov or mp4 in doc dir older than 1h
28 for i
in `find $docdir -maxdepth 1 -type f,l -name '*.mov' -o -name '*.mp4' -mmin +60`; do
30 fdate
=$(date -u --rfc-3339=ns -r $i | perl -pne 's/\..*$/.000000Z/; s/ /T/');
33 if [ -z "$fdate" ]; then
34 #File date must exists
39 #XXX: may miss if filename don't match /^(.*[^0-9])?YYYYMMDD[^0-9]?HHMMSS([^0-9].*)?$/
40 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
/');
43 if [ -z "$ndate" ]; then
45 #XXX: catch when filename match only /^(.*[^0-9])?20YYMMDD([^0-9].*)?$/
46 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/');
50 cdate
=$(ffprobe -hide_banner -v quiet -show_entries format_tags=date,creation_time,com.apple.quicktime.creationdate -of default=nokey=1:noprint_wrappers=1 -i $i | perl -ne '$l = $_ unless /^$/; END { chomp $l; print $l }');
53 date=$(echo -e "$fdate\n$ndate\n$cdate" | perl -ne '$l = $_ unless /^(0000:00:00 00:00:00|)$
/; END
{ chomp
$l; print
$l }');
56 dest="$viddir/$(echo $date | perl -pne 's%^([0-9]{4})-([0-9]{2})-([0-9]{2}).*$%\1/\2/\3%')/$(echo ${i#$docdir/} | perl -pne 's/\.(?:mov|mp4)$
//')";
58 #Without dest directory
59 if [ ! -d "$(dirname $dest)" ]; then
60 #Create dest directory or die
61 mkdir -p "$(dirname $dest)" || exit 1;
65 passlog="$tmpdir/$(echo $i | perl -pne 's%(?:.*/)([^/]+)\.(?:mov|mp4)$%\1%')";
67 #With passlog lock file
68 if [ -f "$passlog.lock
" ]; then
70 echo "Operation
in progress
: $passlog-0.log exists
" 1>&2
77 #XXX: see https://stackoverflow.com/questions/65231616/what-is-the-difference-between-location-and-location-eng-metadata-of-a-mp4-f
78 #XXX: drop location name after /
79 location=$(ffprobe -hide_banner -v quiet -show_entries format_tags=location,location-eng,com.apple.quicktime.location.ISO6709 -of default=nokey=1:noprint_wrappers=1 -i $i 2> /dev/null | perl -ne 's/\/.*$/\//g; $l = $_ unless /^$/; END { chomp $l; print $l }')
82 if [ ! -z "$location" ]; then
83 #Replace with location arguments
84 location=" -metadata location
=\"$location\"";
87 #Prevent empty location
92 #TODO: use instead which works on webm: ffprobe -hide_banner -v quiet -select_streams v:0 -show_entries format=bit_rate -of default=nokey=1:noprint_wrappers=1 -i "$i" | perl -ne 'chomp; print'
93 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');
98 #With sourcerate >= 5120k (1080p)
99 if [ $sourcerate -ge 5120000 ]; then
102 #With sourcerate >= 2560k (720p)
103 elif [ $sourcerate -ge 2560000 ]; then
106 #With sourcerate >= 1024k
107 elif [ $sourcerate -ge 1024000 ]; then
110 #With sourcerate >= 512k
111 elif [ $sourcerate -ge 512000 ]; then
116 #With dest.webm existing
117 if [ ! -f "$dest.webm
" ]; then
118 #Create passlog lock file
119 touch "$passlog.lock
"
121 #With 1080p sourcerate
122 if [ $sourcerate -ge 5120000 ]; then
127 ffmpeg -i $i -v error -passlogfile $passlog.1080p -c:v libvpx-vp9 -b:v $bitrate -pass 1 -an -f null /dev/null < /dev/null;
132 ffmpeg -y -i $i -v error -passlogfile $passlog.1080p -c:v libvpx-vp9 -b:v $bitrate -pass 2 -pix_fmt yuv420p -c:a libopus -movflags +faststart -metadata creation_time="$date"$location -fflags +bitexact $dest.1080p.webm < /dev/null;
136 if [ -f "$passlog.1080p
-0.log
" ]; then
138 unlink "$passlog.1080p
-0.log
";
145 #With sourcerate >= 2560k (720p)
146 if [ $sourcerate -ge 2560000 ]; then
151 ffmpeg -i $i -v error -passlogfile $passlog.720p -c:v libvpx-vp9 -b:v $bitrate -pass 1 -an -f null /dev/null < /dev/null;
156 ffmpeg -y -i $i -v error -passlogfile $passlog.720p -c:v libvpx-vp9 -b:v $bitrate -pass 2 -pix_fmt yuv420p -c:a libopus -movflags +faststart -metadata creation_time="$date"$location -fflags +bitexact $dest.720p.webm < /dev/null;
160 if [ -f "$passlog.720p
-0.log
" ]; then
162 unlink "$passlog.720p
-0.log
";
170 ffmpeg -i $i -v error -passlogfile $passlog -c:v libvpx-vp9 -b:v $bitrate -pass 1 -an -f null /dev/null < /dev/null;
175 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"$location -fflags +bitexact $dest.webm < /dev/null;
179 if [ -f "$passlog-0.log
" ]; then
181 unlink "$passlog-0.log
";
184 #With passlog lock file
185 if [ -f "$passlog.lock
" ]; then
186 #Remove passlog lock file
187 unlink "$passlog.lock
";
194 popd > /dev/null || exit 1;
196 #Remove temporary directory
197 rmdir "$tmpdir" || true;