Add new files and change fps to 30

This commit is contained in:
pepa65 2023-04-16 11:22:39 +07:00
parent d4ab65bf19
commit 890cf28a09
4 changed files with 71 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,4 +4,5 @@ vars
mailer.log
process.log
upload.log
library.log
web/streams/*

48
convert Executable file
View File

@ -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

4
encode
View File

@ -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

20
getcron Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set +vx
# getcron - Process crontab stream entries
# Usage: getcron [<user>]
# If <user> 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