#!/bin/bash # blurp scene detected frames # not using anything from singularity, needs: # ffmpeg and catimg (or jp2a, enable the needed line down there) (and maybe imagemagick) # usage: # sceneFrame *.mp4 # sceneFrame --wait movie.mov # < wait for user keypress before scrolling on # test: # watch -n 1 tree $HOME/tmp/test/ # tmp dir tmp="$HOME/tmp/test/$RANDOM" trap '[ -n "$tmp" ] && kill %% && rm -fr "$tmp"' EXIT mkdir -p "$tmp" "$tmp/make" "$tmp/show" || { echo '!! unable to create a tmpdir' >&2; tmp=; exit 1; } # --wait or -w # must be 1st parameter if [[ "$1" == "-w" ]] || [[ "$1" == "--wait" ]]; then # wait for anykey before scrolling on userwait="1" shift fi # main while [ $# -gt 0 ]; do # for each file loop #set -x # first frame, I want as well, -vf 'scale=trunc(ih*dar):ih',setsar=1/1 < no idea how to implement ffmpeg -hide_banner -loglevel panic -i "$1" -vframes 1 -pix_fmt rgb24 "$tmp/make/000.png" #set +x # scene detect ffmpeg -hide_banner -loglevel info -nostats -i "$1" -threads 0 -vf 'select=gt(scene\,0.2)',showinfo -pix_fmt rgb24 -vsync vfr "$tmp/make/%03d.png" 2> "$tmp/detect.log" >/dev/null & pid="$!" # title echo; echo # toilet -t -f smmono12 "$1" echo "$1"; echo #set -x sleep 2 # checking if the pid is still active OR some files left to process OR show # ps -p $pid &>/dev/null && echo "true" # ls "$tmp/make"* && echo "true" # ls "$tmp/show"* && echo "true" #while ps -p $pid &>/dev/null || ls "$tmp/make"* >/dev/null 2>&1 || ls "$tmp/show" >/dev/null 2>&1; do while ps -p $pid &>/dev/null || [ "$(ls -A "$tmp/make/")" ] || [ "$(ls -A "$tmp/show/")" ] ; do if [ "$(ls -A "$tmp/make/")" ]; then mv "$tmp/make/"* "$tmp/show" >/dev/null 2>&1 fi if [ "$(ls -A "$tmp/show/")" ]; then pushd "$tmp/show" >/dev/null || exit # lets just hardcode 16:9 mogrify -resize 1920x1080! * for file in *; do name="${file%.*}" # name without extension # frame number must be the same as in detection log frame="$(echo "$name" | sed -r 's/^0+//g')" frame="$(( frame - 1))" termheight="$(tput lines)" && height="$(( termheight * 1 / 2 ))" # give me frame and time position #var="$(cat "$tmp/detect.log" | grep "n: \+$frame ")" var="$(grep "n: \+$frame " "$tmp/detect.log")" tmptime="${var#*pts_time:}" tmptime="${tmptime%pos:*}" time="$(date -u -d @"${tmptime}" +"%H:%M:%S,%3N" 2>/dev/null)" echo "$name $time" # catimg dualheight="$(( height * 4 / 3 ))" # 2 is 2 big for my taste catimg -H ${dualheight} "$file" if (( userwait )); then read -n 1 -s -r -p "" # wait for any key from user else sleep 0.1 fi rm "$file" >/dev/null 2>&1 done popd >/dev/null || exit fi sleep 1 done wait #cat "$tmp/detect.log" | grep "pts_time:" shift done