improve encoder_example_ffmpeg
Current encoder_example_ffmpeg script is not working:
- the script calls theora_encoder_example which is a Debian rename, but the executable is encoder_example
- if the input file has audio, mplayer uses a compressed format not compatible with encoder_example and errors with:
The WAV file /tmp/tmp.2ZSNbj17Lj is in a compressed format; can't read it.
- if the input file has no audio, it play the video in real time but doesn't write anything
- if only 1 parameter is specified it tries to use an empty name for the output
- syntax used is
encoder_example $video $audio
, but the proper one isencoder_example $audio $video
Here is a working version:
- really use ffmpeg as the script name suggests and not mplayer
- fix: try to use encoder_example as well as Debian renamed theora_encoder_example executable
- fix: ffmpeg is called with proper audio output, compatible with encoder_example
- fix: calling with video only (and no audio) files now properly work
- check proper script parameters before executing
- FIFOs: no need to create a file and then delete it to just get a random namefile
- pass additional options to encoder_example
- check availability of ffmpeg and ffprobe binaries before executing
ffmpeg=ffmpeg
if ! command -v $ffmpeg 2>&1 >/dev/null ; then
echo error: $ffmpeg executable not found!
exit
fi
ffprobe=ffprobe
if ! command -v $ffprobe 2>&1 >/dev/null ; then
echo error: $ffprobe executable not found!
exit
fi
# TODO: get script dir, and call encoder_example from the same dir, to
# support both system installed as well as local dir version
# check encoder_example as well as Debian named theora_encoder_example
if command -v encoder_example 2>&1 >/dev/null ; then
encoder_example=encoder_example
elif command -v theora_encoder_example 2>&1 >/dev/null ; then
encoder_example=theora_encoder_example
else
echo error: encoder_example or theora_encoder_example executable not found!
exit
fi
if [ -z "$2" ] ; then
echo usage:
echo $0 inputfile outputfile [$encoder_example encoder options]
echo
echo for $encoder_example encoder options run:
echo $encoder_example -h
exit
fi
inputfile=$1
outputfile=$2
shift 2
INPUT_AUDIO=0
# check if there is audio in the input file, then encoder_example needs a different syntax
$ffprobe -i $inputfile -show_streams -select_streams a -loglevel error | grep -q audio && INPUT_AUDIO=1
video=$(mktemp -u)
mkfifo -m 600 $video
# TODO: merge the two separate ffmpeg commands to a single process
$ffmpeg -i $inputfile -y -hide_banner -loglevel error -an -f yuv4mpegpipe $video &
if [ "$INPUT_AUDIO" = 1 ] ; then
audio=$(mktemp -u)
mkfifo -m 600 $audio
$ffmpeg -i $inputfile -y -hide_banner -loglevel error -vn -f wav -bitexact $audio &
$encoder_example $@ $audio $video -o $outputfile
rm -f $audio
else
$encoder_example $@ $video -o $outputfile
fi
rm -f $video