0

I received a script that cuts video into sub-clips with a specific durationand then concats them again but for some reason the script concats the files in reverse 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?

3
  • There are multiple errors in the script that I can see that are unrecoverable. Can you copy-paste the script as is (don't try to make it pretty) and ping me afterwards
    – Fabby
    Commented Jun 2, 2019 at 12:57
  • I took it from here and modified for my needs. superuser.com/questions/1298270/… Commented Jun 3, 2019 at 16:31
  • 2
    Use shellcheck.net when adapting scripts to check for syntax errors. Do that first and then copy-paste what you currently have, then ping me @Fabby again.
    – Fabby
    Commented Jun 3, 2019 at 17:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.