WIP GStreamer Wrapper

This commit is contained in:
AlexPresso
2022-05-16 15:33:52 +02:00
parent 21927bb5f1
commit d2c3bdfed3
2 changed files with 57 additions and 17 deletions

View File

@@ -5,53 +5,49 @@
#########################
pid=$$
childpid=""
defaultargs=(${@:3})
defaultargs=($@)
hlsslice=${@: -1}
hlsroot=${hlsslice::-14}
stderrfile="/tmp/ffmpeg-$pid.stderr"
logfile="/tmp/ffmpeg.log"
#########################
# UTILS
#########################
function log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2" >> /tmp/ffmpeg.log
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2" >> $logfile
}
function newline() {
echo "" >> $logfile
}
function info() {
log "INFO" "$1"
}
function killchild() {
function endprocess() {
info "========================================[end ffmpeg $pid]"
newline
rm $stderrfile
if [[ "$childpid" -ne "" ]]; then
info "Killed child ($childpid)"
kill -TERM "$childpid" 2>/dev/null
fi
}
#########################
# ENTRYPOINT
#########################
trap killchild SIGTERM
trap endprocess SIGTERM
movie=$(cat "$hlsroot/video_metadata" | jq -r ".path")
info "========================================[$pid]"
newline
info "========================================[start ffmpeg $pid]"
info "MOVIE: $movie"
info "HLS_ROOT: $hlsroot"
info "DEFAULT_ARGS: ${defaultargs[*]}"
declare -a args=(
"-i" "$movie"
"${defaultargs[@]}"
)
info "ARGS: ${args[*]}"
/var/packages/ffmpeg/target/bin/ffmpeg "${args[@]}" 2> $stderrfile &
childpid=$!
wait $childpid
/var/packages/ffmpeg/target/bin/ffmpeg "${args[@]}" 2> $stderrfile

44
gst-wrapper.sh Normal file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
#########################
# VARS
#########################
pid=$$
defaultargs=($@)
hlsslice=${@: -1}
hlsroot=${hlsslice::-14}
stderrfile="/tmp/gstlaunch-$pid.stderr"
logfile="/tmp/ffmpeg.log"
#########################
# UTILS
#########################
function log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2" >> $logfile
}
function newline() {
echo "" >> $logfile
}
function info() {
log "INFO" "$1"
}
function endprocess() {
info "========================================[end gst $pid]"
newline
rm $stderrfile
}
#########################
# ENTRYPOINT
#########################
trap endprocess SIGTERM
newline
info "========================================[start gst $pid]"
info "GST_ARGS: ${defaultargs[*]}"
/var/packages/CodecPack/target/pack/bin/gst-launch-1.0.orig "${defaultargs[@]}" 2> $stderrfile