]>
Git — Sourcephile - julm/camera.git/blob - index.sh
2 # Copyright: Julien Moutinho <julm+camera@sourcephile.fr>
3 # License: AGPL-3.0-or-later
5 # $ mv 2023/src/02/IMG_20230228_111645{,.fav}.jpg
6 # $ echo >2023/src/02/IMG_20230228_111645.fav.txt "Some HTML <b>comment</b> about the picture"
7 # $ years=2023 months=02 ./index.sh
8 # $ sensible-browser 2023/fav/02/index.html
10 # shellcheck disable=SC2086
16 ffmpeg_
() { local -; set -x; nice
-19 ffmpeg
</dev
/null
-loglevel warning
-stats -report -y "$@"; }
17 magick_
() { local -; set -x; nice
-19 magick
"$@"; }
18 mv_
() { local -; set -x; mv -iv >&2 "$@"; }
20 user
=$(realpath --relative-to .. .)
21 declare -a years
=${years:-$(find * -maxdepth 0 -type d -not -name ".*")}
22 for year
in ${years[@]}; do
23 pushd "$year" >/dev
/null
24 test -d src
|| { popd; continue; }
26 ln -sf -t fav ..
/..
/index.css
27 declare -a months
=${months:-(01 02 03 04 05 06 07 08 09 10 11 12)}
28 for month
in ${months[@]}; do
29 test -d src
/"$month" || { popd; continue; }
31 mkdir -p {tmp
,wip
}/fav
/"$month"
36 <!-- Generator: https://git.sourcephile.fr/julm/camera -->
37 <!-- GenerationDate: $(date -R -d@"$genDate") -->
41 <meta charset="utf-8">
42 <title>camera/$user/$year/$month</title>
43 <link rel="stylesheet" href="../index.css?$genDate">
50 <li><a href='../../..'>camera</a>/ <a href='../..'>$user</a>/ <a href='..'>$year</a>/ $month</li>
56 echo >&2 "$year/$month: processing favorites in chronological order"
57 # Time is encoded in filenames like so: MM/{IMG,VID}_YYYYMMDD_hhmmss.*
58 # hence sorting after the underscore (2nd field, 5th char).
59 (cd src
; find "$month" -name '*.fav.*' -not -name "*.txt") | sort -n -t/ -k2.5
|
61 echo >&2 "$year/$month: processing $year/src/$src"
65 creationDate
=$(printf %s "${src##*/???_}" | sed -e 's/\(....\)\
(..\
)\
(..\
)_\
(..\
)\
(..\
)\
(..\
).
*/\
1-\
2-\
3 \
4:\
5:\
6/')
66 echo "<li id='$id'><div class='item
'>"
67 test -e fav/"$base".uuid ||
68 uuidgen --random >fav/"$base".uuid
69 uuid=$(cat fav/"$base".uuid)
70 mkdir -p fav/"$month"/by-uuid/"$uuid"
74 printf "<source type='image
/avif
' srcset='"
75 for w in {1200,600,300}; do
76 test fav/"$base"."$w"x.avif -nt src/"$src" || {
78 -sampling-factor 4:2:0 -colorspace sRGB \
79 -auto-orient -thumbnail "$w"x -unsharp 0x.5 \
80 fav/"$base"."$w"x.avif
82 printf %s "$name.
${w}x.avif
${w}w
, "
86 test fav/"$base"."$w"x.avif -nt src/"$src" || {
87 magick_ -define jpeg:size=$((w * 2))x src/"$src" \
88 -sampling-factor 4:2:0 -interlace JPEG -colorspace sRGB \
89 -auto-orient -thumbnail "$w"x -unsharp 0x.5 \
92 echo "<source type='image
/jpeg
' srcset='$name.
${w}x.jpg
${w}w
' />"
93 echo "<img src='$name.
${w}x.jpg
' alt='$creationDate' />"
95 dst="$name".1200x.avif
96 ln -fs -t fav/"$month"/by-uuid/"$uuid" ../../"$dst"
99 test fav/"$base".avif -nt src/"$src" || {
100 ffmpeg_ -i src/"$src" \
102 -filter:v format=yuv420p,scale='trunc
(oh
*a
/2)*2:360' \
103 -frames:v 1 -crf 40 \
105 mv_ {wip/,}fav/"$base".avif
108 test tmp/fav/"$base".opus -nt src/"$src" || {
109 ffmpeg_ -i src/"$src" \
110 -map 0:a -c:a libopus -b:a 64k -application voip \
112 mv_ {wip,tmp}/fav/"$base".opus
115 test fav/"$base".360p.av1.webm -nt src/"$src" || {
117 ffmpeg_ -i src/"$src" -i tmp/fav/"$base".opus \
119 -filter:v format=yuv420p,scale='trunc
(oh
*a
/2)*2:360' \
120 -c:v libsvtav1 -crf 40 -g 120 \
122 wip/fav/"$base".360p.av1.webm
123 mv_ {wip/,}fav/"$base".360p.av1.webm
125 dst="$name".360p.av1.webm
126 ln -fs -t fav/"$month"/by-uuid/"$uuid" ../../"$dst"
127 #test fav/"$base".360p.vp9.webm -nt src/"$src" || {
129 # # See https://developers.google.com/media/vp9/settings/vod#recommended_settings
130 # # See https://gist.github.com/mrintrepide/3033c35ee9557e66cff7806f48dbd339
132 # -filter:v format=yuv420p,scale='trunc
(oh
*a
/2)*2:360' \
133 # -c:v libvpx-vp9 -quality good -crf 20 \
134 # -minrate 138k -b:v 276k -maxrate 400k \
135 # -cpu-used 4 -static-thresh 0 -tile-columns 0 -tile-rows 0 -frame-parallel 0 \
136 # -row-mt 1 -aq-mode 0 -auto-alt-ref 6 -lag-in-frames 25 -enable-tpl 1
137 # test -e tmp/fav/"$base".360p.vp9.webm-0.log || {
138 # # FIXME: how to disable h264 debug log?
139 # ffmpeg 2>/dev/null -i src/"$src" \
140 # -map 0:v "$@" -pass 1 -passlogfile wip/fav/"$base".360p.vp9.webm \
143 # mv_ -t tmp/fav/"${base%/*}" wip/fav/"$base".360p.vp9.webm-*.log
145 # ffmpeg -i src/"$src" -i tmp/fav/"$base".opus \
146 # -map 0:v "$@" -pass 2 -passlogfile tmp/fav/"$base".360p.vp9.webm \
147 # -map 1:a -c:a copy \
148 # wip/fav/"$base".360p.vp9.webm
149 # mkdir -p fav/"$month"/by-uuid/"$uuid"
150 # mv_ wip/fav/"$base".360p.vp9.webm fav/"$base".360p.vp9.webm
151 # rm -fv tmp/fav/"$base".360p.vp9.webm-*.log
153 #test fav/"$base".mp4 -nt src/"$src" || {
154 # ffmpeg -i src/"$src" \
155 # -filter:v format=yuv420p \
156 # -c:v libx264 -preset medium -crf 22 \
157 # -tune zerolatency \
158 # -maxrate 1M -bufsize 2M \
159 # -movflags use_metadata_tags +faststart \
160 # -c:a libopus -base:a 64k -application voip \
161 # -filter:v "scale=iw/2:ih/2" \
162 # wip/fav/"$base".mp4
163 # mv_ wip/fav/"$base".mp4 fav/"$base".mp4
165 #orient=$(ffprobe -v 0 -select_streams v:0 -show_entries stream_side_data=rotation -of default=nw=1:nk=1 src/"$src")
166 # class='orient
$orient'
167 echo "<video controls preload=none poster='$name.avif
'>"
168 # See https://jakearchibald.com/2022/html-codecs-parameter-for-av1/
169 # and ffmpeg -i fav/$month/foo.av1.webm -c:v copy -bsf:v trace_headers -f null /dev/null |&
170 # grep -e seq_profile -e seq_level_idx -e seq_tier -e high_bitdepth -e twelve_bit
171 P=0; LL=01; T=M; DD=08
172 echo "<source type='video
/webm
; codecs
=av01.
$P.
$LL$T.
$DD' src='$name.360p.av1.webm
' />"
173 echo "<p><a href='$name.360p.av1.webm
'>$name.360p.av1.webm</a></p>"
176 touch -a src/"$base".txt
177 printf %s "<span class='comment
'>"
178 sed -e '$q;s
/$
/<br \
/>\n/' src/"$base".txt
181 echo "<span class='infos
'>"
182 echo " <span class='creationDate
'>$creationDate</span>"
184 echo "<span class='links
'>"
185 echo " <a class='anchor
' href='#$id' title='Ancre vers cette capture'>#</a>"
186 echo " <a class='by-uuid' href='by-uuid/$uuid/$dst' title='Lien public vers cette capture' target='_blank'>@</a>"
198 } >tmp
/fav
/"$month"/index.html
199 mv_
-f {tmp
/,}fav
/"$month"/index.html
201 echo >&2 "$year/$month: remove any deleted favorites"
202 (cd fav
; find "$month" -mindepth 1 -type f
-not -name index.html
) |
203 while read -r fav
; do
207 for src
in src
/"$base".fav.
*; do test "${src%.txt}" != "$src" || hasSrc
=set; done
208 test "${hasSrc:+set}" || {
209 echo >&2 "$year/$month: removing $year/fav/$fav"
211 rm -f fav
/"$month"/by
-uuid/*/"${name%.*}".
*
214 rmdir -p 2>/dev
/null fav
/"$month"/by
-uuid/*/ || true
218 rmdir 2>/dev
/null
-p wip
/fav
/* || true