]> git.plutz.net Git - rawnet/blobdiff - page_video.sh
more reliable video meta data check (duration)
[rawnet] / page_video.sh
index 0a1f2752baf5181cf384e386a0655e32ccbb1f7a..9f214093b8f4dcabaad20657ec48c42f3558ecf4 100644 (file)
@@ -23,7 +23,7 @@ update_video(){
         hits descr_cache futureuse
   local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \
         DESCR_CACHE FUTUREUSE
-  local arg video thumb
+  local arg video thumb cnt
   video="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.mp4"
   thumb="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg"
 
@@ -37,16 +37,22 @@ update_video(){
   esac; done
 
   if [ -f "$video" -a -r "$video" ]; then
-    arg="$(echo; ffprobe -show_entries stream=width,height,duration "$video" 2>&-)"
+    arg="$(echo; ffprobe -show_entries format=duration:stream=width,height "$video" 2>&-)"
     resx="${arg#*width=}"; resx="${resx%%${BR}*}"
     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 [ "${length%.*}" -a ! "${thumb}" -nt "${video}" ]; then
+    for cnt in 1 2 3 4 5 6 7 8 9 10; do
+      ffmpeg -nostdin -y -ss "$((cnt * ${length%.*} / 11))" -i "$video" \
+             -frames 1 "${thumb%.jpg}_$((cnt - 1)).jpg"
+    done 2>&-
+    montage "${thumb%.jpg}"_[0-9].jpg \
+            -background "#000000" \
+            -tile 10x1 -geometry 320x180+0+0 \
+            -interlace line -quality 85 "${thumb}"
+    rm -- "${thumb%.jpg}"_[0-9].jpg
+  fi
 
   if LOCK "$vid_db"; then
     while read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \