You can use ffprobe
that should come with ffmpeg
to get the duration.
dur=$(($(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 inputfilename | xargs printf %.0f)-4))ffmpeg -t ${dur} -i inputfilename -c copy outputfilename
The first line uses ffprobe
to get the duration minus 4 seconds then puts it in a var called dur
.
I have also used xargs
to round the number because bash
only accepts whole numbers when doing math operations.
You can use bc
if you need more accuracy.
dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 inputfilename)dur=$(bc <<< ${dur}-4)ffmpeg -t ${dur} -i inputfilename -c copy outputfilename