From 890cf28a0915f3caa8d767c5ee31d2d738b244ae Mon Sep 17 00:00:00 2001 From: pepa65 Date: Sun, 16 Apr 2023 11:22:39 +0700 Subject: [PATCH] Add new files and change fps to 30 --- .gitignore | 1 + convert | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ encode | 4 ++-- getcron | 20 ++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 convert create mode 100755 getcron diff --git a/.gitignore b/.gitignore index 03af4a4..81fa91b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ vars mailer.log process.log upload.log +library.log web/streams/* diff --git a/convert b/convert new file mode 100755 index 0000000..d603106 --- /dev/null +++ b/convert @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set +vx +# convert - Encode for Library display +# Usage: convert +# Called by cron every minute; process oldest .library file in ./web/streams +# and upload it to the Library display server +# Required: file coreutils(readlink ls head mv tail rm) ffmpeg + +# Check for oldest uploaded file +_=$(readlink -f -- "${BASH_SOURCE:-$0}") path=${_%/*} +log=$path/library.log dir=$path/web/streams +upload=$(ls -Atr "$dir"/*.library 2>/dev/null |head -1) + +# Finished if no videos/*.library videos found +[[ $upload ]] || exit 0 + +Log(){ # 1:message 2:returncode(empty: no exit) I:log + echo -e "$(date +'%Y-%m-%d at %H:%M:%S') $1">>"$log" + [[ $2 ]] && exit $2 || return 0 +} + +# Rename upload and check type +file=${upload%.library} video=$file.mp4 name=${file##*/} +mv "$upload" "$file" + +type=$(file -bL --mime-type "$file") +[[ ! ${type:0:5} = video ]] && Log "File $name is of type $type" 1 + +# Encode video +b= F= s= d= f= t= +[[ $bitrate ]] && bi="-b:v $bitrate -maxrate $bitrate -bufsize $((bitrate*2))" +[[ $format ]] && fo="format=$format," +[[ $scale ]] && sc="scale=${scale//:/x}," +[[ $dar ]] && da="setdar=${dar//://}," +[[ $fps ]] && fp="fps=$fps," +[[ $fo || $sc || $da || $fp ]] && vf="-vf '$fo$sc$da$fp" vf="${vf%,}'" +[[ $tbn ]] && tb="-video_track_timescale $tbn" +cmd="ffmpeg -y -i $file -c:v libx264 -x264opts no-scenecut $bi $vf $tb -c:a copy $video" +set -o pipefail # to get ffmpeg's returncode +ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -vf "scale=1920x980,fps=15" "$video" 2>&1 |tail -n 20 >"$log" || + Log "Error encoding $name" 2 + +Log "Encoding $video done" + +curl -v -F video=@$dir/$name.mp4 -F type=play http://192.168.7.21:8888/process.php && + Log "Dispatching video done" 0 || + Log "Error dispatching video" 3 + diff --git a/encode b/encode index c4ef0b3..d9e13f9 100755 --- a/encode +++ b/encode @@ -74,8 +74,8 @@ error=0 #ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -force_key_frames 'expr:gte(t,n_forced*2)' -c:a copy -tune zerolatency -f mp4 "$video" |tail -n 20 >"$file.0log" || error=1 # Double pass set -o pipefail # to get ffmpeg's returncode -ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=25" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 1 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.1log" && - ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=25" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 2 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.2log" || +ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=30" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 1 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.1log" && + ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=30" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 2 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.2log" || error=1 # Remove logfiles diff --git a/getcron b/getcron new file mode 100755 index 0000000..1471414 --- /dev/null +++ b/getcron @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set +vx +# getcron - Process crontab stream entries +# Usage: getcron [] +# If is given, only show entries of that user + +# Get uncommented crontab stream entries +mapfile -t lines < <(crontab -l |grep -v '^#' |grep ' *\s/var/www/stream ') + +#echo "User: $1" +#now=$(date '+%Y-%m-%d %H:%M') +for line in "${lines[@]}" +do + #tag=${line##* } _=${tag#*.} dt="${_:0:10} ${_:11:2}:${_:13:2}" _=${_:16} user=${_%%[@:]*} + #[[ $dt > $now && $user = $1 ]] && echo "$dt $tag" + read m h d M _ _ tag <<<"$line" + _=${tag#*.} _=${_:16} user=${_%%[@:]*} + dt=$(printf "%02d:%02d %s %d" $h $m $(date -d 2022-$M-01 +%B) $d) + [[ -z $1 || $user = $1 ]] && printf "%-20s %s\n" "$dt" $tag +done |sort