]>
Raphaƫl G. Git Repositories - binary/blob - vidpack
3 #XXX: TODO: remove file ffmpeg2pass-1.log
5 # bitrate=2560k; for i in `find images/side_quests -type f -name "*.webm"`; do tmpdir=/tmp/vidpack; passlog="$tmpdir/$(echo $i | perl -pne 's%(?:.*/)([^/]+)\.(?:mov|mp4|webm)$%\1%')"; date=$(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 }'); ffmpeg -i $i -v error -passlogfile $passlog.1080p -vf 'fps=30' -c:v libvpx-vp9 -b:v $bitrate -pass 1 -an -f null /dev/null < /dev/null; ffmpeg -y -i $i -v error -passlogfile $passlog.1080p -vf 'fps=30' -c:v libvpx-vp9 -b:v $bitrate -pass 2 -pix_fmt yuv420p -c:a libopus -movflags +faststart -metadata creation_time="$date" -fflags +bitexact $(echo $i | perl -pne 's/.[a-z]+$/.1080p.webm/') < /dev/null; done
8 #XXX: ffplay -vf "curves=all='0/0 0.25/0.375 0.5/0.75 0.75/0.875 1/1'"
11 #XXX: ffplay -vf scale=-1:720
13 #Set temporary directory
14 tmpdir
='/tmp/vidpack';
16 #Without temporary directory
17 if [ ! -d "$tmpdir" ]; then
18 #Create temporary directory or die
19 mkdir -p "$tmpdir" || exit 1;
25 #Iterate on each mov or mp4 in doc dir older than 1h
26 #for i in `find $docdir -maxdepth 1 -type f,l -name '*.mov' -o -name '*.mp4' -o -name '*.webm' -mmin +60`; do
27 #find . -type f \( -name 'p*.webm' -o -name 'n*.webm' \) -print0 | while read -d $'\0' i; do
28 find .
-type f
-size +0 \
( -name '*.mp4' -o -name '*.avi' -o -name '*.mpg' -o -name '*.mkv' -o -name '*.webm' -o -name '*.mov' -o -name '*.ogv' \
) -print0 | while read -d $
'\0' i
; do
29 #find . -type f -size +2G \( -name '*.mp4' -o -name '*.avi' -o -name '*.mpg' -o -name '*.mkv' -o -name '*.mov' -o -name '*.ogv' \) -print0 | while read -d $'\0' i; do
31 fdate
=$(date -u --rfc-3339=ns -r "$i" | perl -pne 's/\..*$/.000000Z/; s/ /T/');
34 if [ -z "$fdate" ]; then
35 #File date must exists
40 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 }');
43 date=$(echo -e "$fdate\n$cdate" | perl -ne '$l = $_ unless /^(0000:00:00 00:00:00|)$
/; END
{ chomp
$l; print
$l }');
46 passlog="$tmpdir/$(dirname "$i" | md5sum - | perl -pne 's/\s+-$//')_$(basename "$i")";
48 #With passlog lock file
49 if [ -f "$passlog.lock" ]; then
51 echo "Operation in progress: $passlog-0.log exists" 1>&2
60 #XXX: see https://stackoverflow.com/questions/65231616/what-is-the-difference-between-location-and-location-eng-metadata-of-a-mp4-f
61 #XXX: drop location name after /
62 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 }')
65 if [ ! -z "$location" ]; then
66 #Replace with location arguments
67 location="-metadata location=\"$location\"";
70 #Prevent empty location
75 sourcerate=$(ffprobe -hide_banner -v quiet -select_streams v:0 -show_entries format=bit_rate -of default=nokey=1:noprint_wrappers=1 "$i" | perl -ne 'chomp; print');
80 ##With sourcerate >= 5120k (1080p)
81 #if [ $sourcerate -ge 5120000 ]; then
84 ##With sourcerate >= 2560k (720p)
85 #elif [ $sourcerate -ge 2560000 ]; then
86 if [ $sourcerate -ge 2560000 ]; then
89 #With sourcerate >= 1024k
90 elif [ $sourcerate -ge 1024000 ]; then
93 #With sourcerate >= 512k
94 elif [ $sourcerate -ge 512000 ]; then
100 sourcefps=$(ffprobe -hide_banner -v quiet -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 -i "$i" | perl -pne 'use POSIX qw(ceil); if (/^([0-9]+)\/([0-9]+)$/) { print ceil($1/$2); } elsif (/^([0-9]+)$/) { print ceil($1); }; undef $_;');
109 if [ $sourcefps -gt 59 ]; then
113 elif [ $sourcefps -gt 49 ]; then
117 elif [ $sourcefps -gt 47 ]; then
121 elif [ $sourcefps -gt 29 ]; then
125 elif [ $sourcefps -gt 24 ]; then
131 filters
+=("fps='$fps'")
134 sourceheight
=$(ffprobe -hide_banner -v quiet -select_streams v:0 -show_entries stream=height -of default=nokey=1:noprint_wrappers=1 -i "$i" | perl -ne 'chomp; print')
136 #With sourceheight > 1080
137 if [ $sourceheight -gt 1080 ]; then
139 filters
+=("scale='-1:1080'")
146 if [ ${#filters[@]} -gt 0 ]; then
148 filter
=$(IFS=,; echo "-vf ${filters[*]}");
151 #With existing dest file
152 if [ ! -f "$i.vp" ]; then
153 #Create passlog lock file
154 touch "$passlog.lock"
157 ffmpeg
-i "$i" -v error
-passlogfile "$passlog" $filter -c:v libvpx
-vp9 -b:v
$bitrate -pass 1 -an -f null
/dev
/null
< /dev
/null
;
162 ffmpeg
-y -i "$i" -v error
-passlogfile "$passlog" $filter -c:v libvpx
-vp9 -b:v
$bitrate -pass 2 -pix_fmt yuv420p
-c:a libopus
-movflags +faststart
-metadata creation_time
="$date" $location -fflags +bitexact
-f webm
"$i.vp" < /dev
/null
;
166 if [ -f "$passlog-0.log" ]; then
168 unlink
"$passlog-0.log";
171 #With passlog lock file
172 if [ -f "$passlog.lock" ]; then
173 #Remove passlog lock file
174 unlink
"$passlog.lock";
179 #Remove temporary directory
180 rmdir "$tmpdir" || true
;