I gotreceived a script that cutcuts video into subclibssub-clips with specified full duration of preview then concat it. Fora specific durationand then concat
s them again but for some reason it put it together reversed. What's wrong withthe script or how to implementconcat
s the files in reverse that put it correctly.order:
#! /bin/bash
SUBCLIPS=4
OUTPUTLENGTH=10
cliplength=$(echo "$OUTPUTLENGTH/$SUBCLIPS"| bc -l)
if [ -e "$1" ]; then
videofile="$1"
else
echo "file not found: $1"
exit 1
fi
if [ "$2" ]; then
OUTPUTFILE="$2"
else
echo "No name given"
exit 1
fi
ffmpeg_preamble="ffmpeg -hide_banner -i '$videofile' -s 320x240 - filter_complex \""
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$videofile")
cutfilters=""
concatfilter=""
for cutno in $( seq 1 $SUBCLIPS ); do
cut=$(echo "(1 / ($SUBCLIPS+1)) * $cutno" | bc -l)
cutchar= $cutno+96
reverse= $(printf "%sreverse")
cutletter=$(printf "\x$(printf %x $cutchar)")
cutpos=$(echo "$duration * $cut" |bc)
cutfilters=$(printf "%s[0:v]trim=start=%f:duration=%f,setpts=PTS-STARTPTS[%sv];" "$cutfilters" "$cutpos" "$cliplength" "$cutletter")
cutfilters=$(printf "%s[0:a]atrim=start=%f:duration=%f,asetpts=PTS-STARTPTS[%sa];" "$cutfilters" "$cutpos" "$cliplength" "$cutletter")
concatfilter=$(printf "%s[%sv][%sa]" "$concatfilter" "$cutletter" "$cutletter")
done
# concat the cuts together
concatfilter=$(printf "%sconcat=n=%s:v=1:a=1[outv][outa]" "$concatfilter" "$SUBCLIPS")
ffmpeg_webmopts=" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis "
ffmpeg_postscript="\" -map [outv] -map [outa] $ffmpeg_webmopts '$OUTPUTFILE'"
# Chance to cancel before we start
printf "***(hit ctrl+c to cancel)***\n\nExecuting: %s%s%s%s\n" "$ffmpeg_preamble" "$cutfilters" "$concatfilter" "$ffmpeg_postscript"
sleep 3
eval $(echo "$ffmpeg_preamble $cutfilters $concatfilter $ffmpeg_postscript")
How do I implement the above without reversal?