#!/bin/sh # mpv wrapper for video surveillance integration # $Id: mpp,v 1.39 2024/01/13 20:41:41 pdc Exp $ resample1="--video-sync=display-resample" resample0="--video-sync=display-resample-desync" desync="--video-sync=desync" cam_arg="--framedrop=decoder+vo --vd-lavc-skiploopfilter=nonkey --stop-screensaver=no --cache-pause=no --sid=no --osd-bar=no --osd-level=3 --force-window --input-ar-delay=250 --input-ar-rate=" # Property list # --title='${path} - ${media-title} - mpv' arg2='--title=\${path} - \${media-title} - mpv' #arg3='--script-opts=osc-title=${path} / ${media-title}' arg3='--script-opts=osc-title=\${path} : \${media-title}' cam_view= zm= case "$1" in DEL|DELS|ADD|ADDS|SEEN|SEENS) mpp-input "$@"; exit $? ;; esac playlist=`mktemp -t mpp.playlist` echo '#EXTM3U' > "$playlist" case "$1" in zm|zm2) zm=1 arg="$resample0" #arg="$desync" arg="$arg --screenshot-template=%f.%p.%n" #arg="$arg --demuxer=lavf --demuxer-lavf-probe-info=yes --demuxer-lavf-analyzeduration=2" arg="$arg --demuxer=lavf --demuxer-lavf-probe-info=no --demuxer-lavf-buffersize=10485760 --demuxer-lavf-analyzeduration=12" #arg="$arg --vo=gpu --hwdec=h264-vdpau" #arg="$arg --vo=gpu --hwdec=auto --hwdec-codecs=all" arg3="${arg3},osc-visibility=always" rate= speed= case `pwd` in */xm2/*) rate=15; speed=6 ;; */boa?/*) rate=5 ;; esac case "$1" in zm2) [ -z "$rate" ] && rate=30 [ -z "$speed" ] && speed=12 arg="$arg --window-scale=1 ${cam_arg}$rate --speed=$speed" arg="$arg --demuxer-max-back-bytes=40971520 --demuxer-max-bytes=50971520 --demuxer-readahead-secs=8" #arg="$arg --demuxer-max-back-bytes=409715200 --demuxer-max-bytes=509715200 --demuxer-readahead-secs=8" ;; *) [ -z "$rate" ] && rate=15 [ -z "$speed" ] && speed=6 arg="$arg --window-scale=1 ${cam_arg}$rate --speed=$speed" esac cam_view=1 shift ;; #;& cam|cam1) arg="$resample0" arg="$arg --window-scale=1 ${cam_arg}15 --speed=4" cam_view=1 shift ;; cam4) arg="$resample0" arg="$arg --window-scale=1 ${cam_arg}7 --speed=4 --volume=60" cam_view=1 shift ;; cam2) arg="$resample0" arg="$arg --window-scale=2 ${cam_arg}15 --speed=5" cam_view=1 shift ;; cam5) arg="$desync" arg="$arg --window-scale=2 ${cam_arg}10 --speed=4" cam_view=1 shift ;; input) arg="--input-test --force-window " fn="--idle" shift ;; test) arg="--force-window " fn="--idle" shift ;; jpg|mf:*) case "$1" in jpg) fn="mf://*.jp*g" ;; *) fn="$1" ;; esac arg3="${arg3},osc-visibility=always" arg="$arg --mf-fps=20" #arg="$arg --mf-fps=20 mf://*.jp*g" arg="$arg --screenshot-template=jpg.%p.%n" nowait=1 shift ;; rm) rm `cat /tmp/far2l.list ` exit $! ;; esac add1() { local a="$1" echo "a: $a" if [ -d "$a" ]; then #echo " " find "$a" -depth 1 -name '*.[mM][pP]4' for l in `find "$a" -depth 1 -name '*.[mM][pP]4'`; do echo " $l" if [ -z "$fn" ]; then fn="$l" else list="$list \"$l\"" echo "#EXTALB:$a/$l" >> "$playlist" echo "#EXTINF:9,$l" >> "$playlist" echo "$PWD/$l" >> "$playlist" fi done else if [ -z "$fn" -a -r "$a" ]; then fn="$a" else case "$a" in -proc*) do_processing=1 ;; -nowait) nowait=1 ;; -delseen) delseen="-delseen" ;; -*) tail="$tail \"$a\"" ;; # args actually *) list="$list \"$a\"" echo "$PWD/$a" >> "$playlist" esac fi fi } if : || [ -n "$zm" ]; then # process event dirs #local a e list= echo "event dirs: $@" for a in "$@"; do case "$a" in */far2l*.tmp|*/far2l.list|*/*.list) echo far2l file list cp -f "$a" /tmp/far2l.list while read e; do add1 "$e" done < "$a" ;; *) add1 "$a" esac done ##echo "list: $list" #set -- $list set -- #set -- "295615/295615-video.mp4" ##echo -- list: "$@" #exit if [ -n "$list" ]; then #echo "--idle" >> "$playlist" #echo "pause" >> "$playlist" #list="--playlist=$playlist" list="--prefetch-playlist=yes --playlist=$playlist" fi fi fn=${fn:-"$1"} shift echo "fn=$fn" case "$fn" in *.[Aa][Vv][Ii]|*.[Mm][Pp]4|*.[Mm][Oo][Vv]|*.[Ww][Ee][Bb][Mm]|*.[Mm][Kk][Vv]) arg="$arg --screenshot-template=%f.%p.%n" ;; esac if [ -z "$fn" ]; then echo "Usage: $0 [cam|cam1|cam2|cam4|cam5|jpg|zm] far2l examples: (xterm -e mpp cam4 \"!@!\"& sleep 1) (xterm -e 'mpp zm \"!@!\" --no-cache -geometry=0x0+2700+0 --rebase-start-time=no|mpp-input' & sleep 2) (xterm -geom 120x30+1920+0 -e 'mpp zm \"!@!\" --no-cache -geometry=0x0+2700-1055 --volume=80 -proc' & sleep 2) (xterm -geom 120x30+1920+0 -e 'mpp zm2 \"!@!\" -geometry=0x0+2700-1055 --volume=80 -proc -delseen' & sleep 2) (xterm -geom 120x30+1920+0 -e 'mpp zm2 "!@!" -geometry=0x0+2700-1065 --volume=80 -proc -delseen' & sleep 2) "; exit 64 fi #exit if [ -n "$do_processing" ]; then processing="2>&1 | mpp-input $delseen" fi ao= echo "arg: $arg" echo mpv "$fn" -volume-max 400 --keep-open=yes --idle=yes $arg "$arg2" "$arg3" "$@" "$list" "$tail" "$processing" eval mpv \""$fn"\" -volume-max 400 --keep-open=yes --idle=yes "$arg" \""$arg2"\" \""$arg3"\" "$@" "$list" "$tail" "$processing" [ -z "$nowait" ] && sleep 5 rm "$playlist" # https://en.wikipedia.org/wiki/M3U