Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# TEST VERSION FOR INTEL QUICK SYNC V2
_log(){
echo "$(date '+%Y-%m-%d %H:%M:%S') - ${streamid} - $1" >> /tmp/ffmpeg.log
}
_log_para(){
echo "$1" | fold -w 120 | sed "s/^.*$/$(date '+%Y-%m-%d %H:%M:%S') - ${streamid} - = &/" >> /tmp/ffmpeg.log
}
_term(){
rm /tmp/ffmpeg-${streamid}.stderr
_log "*** KILLCHILD ***"
kill -TERM "$childpid" 2>/dev/null
}
trap _term SIGTERM
pid=$$
paramvs=$@
stream="${@: -1}"
streamid="FFM$pid"
bin1=/var/packages/ffmpeg/target/bin/ffmpeg
bin2=/var/packages/VideoStation/target/bin/ffmpeg.orig
args=()
vcodec="KO"
while [[ $# -gt 0 ]]
do
case "$1" in
-i)
shift
movie="$1"
args+=("-i" "$1")
;;
-scodec)
shift
scodec="$1"
args+=("-scodec" "$1")
;;
-hwaccel)
shift
hwaccel="$1"
args+=("-hwaccel" "$1")
;;
-map)
shift
args+=("-map" "$1")
idmap=`echo $1 | cut -d : -f 2`
if [ "$vcodec" = "KO" ]; then
vcodec=`/var/packages/ffmpeg/target/bin/ffprobe -v error -select_streams $idmap -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$movie"`
else
acodec=`/var/packages/ffmpeg/target/bin/ffprobe -v error -select_streams $idmap -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$movie"`
fi
;;
*)
args+=("$1")
;;
esac
shift
done
if [ "$hwaccel" = "vaapi" ]; then
set -- "${args[@]}"
args=()
while [[ $# -gt 0 ]]
do
case "$1" in
-hwaccel)
shift
args+=("-hwaccel" "qsv")
;;
-hwaccel_output_format)
shift
if [ "$vcodec" = "mpeg4" ]; then
args+=("-c:v" "h264_qsv")
else
args+=("-c:v" "${vcodec}_qsv")
fi
;;
-vcodec)
shift
args+=("-c:v" "h264_qsv")
;;
-vf)
shift
scale_w=`echo "${1}" | sed -e 's/.*=w=//g' | sed -e 's/:h=.*//g'`
scale_h=`echo "${1}" | sed -e 's/.*:h=//g'`
if let ${scale_w} AND let ${scale_h}; then
args+=("-vf" "scale_qsv=w=${scale_w}:h=${scale_h}:format=nv12")
fi
;;
-vaapi_device)
shift
;;
-pix_fmt)
shift
;;
*)
args+=("$1")
stream="$1"
;;
esac
shift
done
fi
bin=$bin1
if [ "$scodec" = "subrip" ]; then
bin=$bin2
fi
_log "*** PROCESS START PID $pid ***"
_log "MOVIE = $movie"
_log "VCODEC = $vcodec"
_log "ACODEC = $acodec"
_log "FFMPEG = $bin"
_log "PARAMVS ="
_log_para "$paramvs"
set -- "${args[@]}"
paramqvs=$@
_log "PARAMQVS ="
_log_para "$paramqvs"
startexectime=`date +%s`
$bin "$@" 2> /tmp/ffmpeg-${streamhash}.stderr &
childpid=$!
_log "CHILDPID = $childpid"
wait $childpid
stopexectime=`date +%s`
if test $((stopexectime-startexectime)) -lt 10; then
_log "STDERR ="
_log_para "`tail -n 15 /tmp/ffmpeg-${streamhash}.stderr`"
fi
_log "*** CHILD END ***"
_log "*** PROCESS END ***"
rm /tmp/ffmpeg-${streamhash}.stderr
@namzu

This comment has been minimized.

Copy link

@namzu namzu commented May 11, 2021

It seems no working any more.
On DSM 6.2.4 and VideoStation 2.4.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment