Skip to content

Instantly share code, notes, and snippets.

@mikklfr
Forked from BenjaminPoncet/ffmpeg-wrapper
Created October 31, 2021 11:32
Show Gist options
  • Select an option

  • Save mikklfr/ee0e4acf11eb25a10471f940c0ff72fa to your computer and use it in GitHub Desktop.

Select an option

Save mikklfr/ee0e4acf11eb25a10471f940c0ff72fa to your computer and use it in GitHub Desktop.
Synology VideoStation ffmpeg wrapper with DTS, EAC3 and TrueHD support (Installation instructions in 1st comment)
#!/bin/bash
paramvs=$@
args=()
while [[ $# -gt 0 ]]
do
case "$1" in
#-hls_seek_time)
#shift
#hls_seek_time="$1"
#;;
-i)
shift
movie="$1"
args+=("-i" "$1")
;;
-vaapi_device)
shift
args+=("-vaapi_device" "$1")
;;
-hwaccel)
shift
args+=("-hwaccel" "$1")
;;
-hwaccel_output_format)
shift
args+=("-hwaccel_output_format" "$1")
;;
-vcodec)
shift
args+=("-vcodec" "$1")
#args+=("-vcodec" "libx264")
;;
-vf)
shift
#args+=("-vf" "scale_vaapi=w=320:h=240:format=nv12")
args+=("-vf" "$1")
#args+=("-filter:v" "scale=720:-1")
;;
-vb)
shift
args+=("-vb" "$1")
#args+=("-preset" "ultrafast")
;;
*)
args+=("$1")
stream="$1"
;;
esac
shift
done
streamhash=`echo $stream | cut -d / -f 5`
echo "MOVIE = $movie" >> /tmp/ffmpeg.log
echo "STREAM = $streamhash" >> /tmp/ffmpeg.log
echo "PARAM_VS = $paramvs" >> /tmp/ffmpeg.log
#args+=("-hls_seek_time" "$hls_seek_time")
bin=/var/packages/ffmpeg/target/bin/ffmpeg
set -- "${args[@]}"
echo "PARAM_RW = $@" >> /tmp/ffmpeg.log
echo "FFMPEG = $bin" >> /tmp/ffmpeg.log
pkill -F /tmp/ffmpeg-${streamhash}.lastpid
$bin "$@" 2> /tmp/ffmpeg-${streamhash}.stdout &
childpid=$!
echo $childpid > /tmp/ffmpeg-${streamhash}.lastpid
echo "CHILDPID = $childpid" >> /tmp/ffmpeg.log
wait $childpid
if grep "Conversion failed!" /tmp/ffmpeg-${streamhash}.stdout; then
echo "ERROR = Conversion failed!" >> /tmp/ffmpeg.log
args=()
while [[ $# -gt 0 ]]
do
case "$1" in
-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'`
args+=("-vf" "scale_vaapi=w=${scale_w}:h=${scale_h}:format=nv12")
;;
*)
args+=("$1")
;;
esac
shift
done
set -- "${args[@]}"
echo "PARAM_RW = $@" >> /tmp/ffmpeg.log
echo "FFMPEG = $bin" >> /tmp/ffmpeg.log
$bin "$@" &
childpid=$!
echo $childpid > /tmp/ffmpeg-${streamhash}.lastpid
echo "CHILDPID = $childpid" >> /tmp/ffmpeg.log
wait $childpid
fi
echo >> /tmp/ffmpeg.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment