From 24e82b91931ffe75eaa3efd889a031076ff1f003 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Fri, 1 Oct 2021 00:35:12 +0200 Subject: [PATCH] automatic thumbnail generation and serving --- index.cgi | 2 +- page_channel.sh | 2 +- page_video.sh | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/index.cgi b/index.cgi index bd7e21b..02ab9dc 100755 --- a/index.cgi +++ b/index.cgi @@ -107,7 +107,7 @@ case ${PATH_INFO} in $(w_user_recover) EOF ;; - /video/*/*.mp4) + /video/*/*.mp4|/video/*/*_thumb.jpg) . "${_EXEC}/cgilite/file.sh" FILE "${_DATA}/${PATH_INFO#/video/}" ;; diff --git a/page_channel.sh b/page_channel.sh index 2e35590..72553ba 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -169,7 +169,7 @@ w_video(){ [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0 - thumb="${_BASE}/${CHANNEL_ID}/thumb_${VIDEO_ID}.jpg" + thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg" [ "$NAME" = \\ ] && NAME="(Unnamed Video)" printf '[div .video .thumb [h3 [a href="%s/channel/%s/%s/" . %s]] diff --git a/page_video.sh b/page_video.sh index e1a2ae3..0a1f275 100644 --- a/page_video.sh +++ b/page_video.sh @@ -23,8 +23,9 @@ update_video(){ hits descr_cache futureuse local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \ DESCR_CACHE FUTUREUSE - local arg video - video="$_DATA/$CHANNEL_ID/$VIDEO_ID.mp4" + local arg video thumb + video="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.mp4" + thumb="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg" for arg in "$@"; do case $arg in name=*) name="${arg#*=}";; @@ -41,6 +42,11 @@ update_video(){ resy="${arg#*height=}"; resy="${resy%%${BR}*}" length="${arg#*duration=}"; length="${length%%${BR}*}" fi + if [ "$length" -a ! "${thumb}" -nt "${video}" ]; then + ffmpeg -nostdin -y -i "$video" -vf scale=320:-2,fps=10/${length} "${thumb%.jpg}_%02d.jpg" + montage "${thumb%.jpg}_"[01][0-9].jpg -tile 10x1 -geometry 320x180+0+0 -quality 85 "${thumb}" + rm -- "${thumb%.jpg}_"[01][0-9].jpg + fi 2>&- if LOCK "$vid_db"; then while read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \ -- 2.39.2