#!/bin/sh #=============================================================================== # relay a stream to a named pipe with mpv #=============================================================================== #=============================================================================== # script usage #=============================================================================== usage () { # if argument passed to function echo it [ -z "${1}" ] || echo "! ${1}" # display help echo "\ $(basename "$0") -i input -s 00:00:00 -e 00:00:00" exit 2 } #=============================================================================== # error messages #=============================================================================== INVALID_OPT_ERR='Invalid option:' REQ_ARG_ERR='requires an argument' WRONG_ARGS_ERR='wrong number of arguments passed to script' #=============================================================================== # check number of aruments passed to script #=============================================================================== [ $# -gt 0 ] || usage "${WRONG_ARGS_ERR}" #=============================================================================== # getopts check options passed to script #=============================================================================== while getopts ':s:i:e:h' opt do case ${opt} in s) start="${OPTARG}";; i) input="${OPTARG}";; e) end="${OPTARG}";; h) usage;; \?) usage "${INVALID_OPT_ERR} ${OPTARG}" 1>&2;; :) usage "${INVALID_OPT_ERR} ${OPTARG} ${REQ_ARG_ERR}" 1>&2;; esac done shift $((OPTIND-1)) #=============================================================================== # named pipe #=============================================================================== # check if the /tmp/relay named pipe exist otherwise create it [ -p /tmp/relay ] || mkfifo /tmp/relay #=============================================================================== # mpv pipe function #=============================================================================== # mpv pipe mpv_pipe () { mpv \ --config-dir=/dev/null \ --o=/tmp/relay \ --of=nut \ --ovc=rawvideo \ --oac=pcm_s16le \ --start="${start}" \ --end="${end}" \ "${input}" } #=============================================================================== # run the mpv pipe function #=============================================================================== mpv_pipe