Body: <p>I received a script that cuts video into sub-clips with a specific durationand  then <code>concat</code>s them again but for some reason the script <code>concat</code>s the files in reverse order:</p>
  
  <pre><code>#!/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")
  </code></pre>
  
  <p><em>How do I implement the above without reversal?</em> </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-06-02T12:57:25.020Z
Comments.Text: 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
Comments.UserDisplayName: Fabby
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-06-03T16:31:53.870Z
Comments.Text: I took it from here and modified for my needs.
  https://superuser.com/questions/1298270/ffmpeg-mp4-to-webm-make-a-10-second-compilation-based-on-length
Comments.UserDisplayName: Jakub Dobrzeniecki
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-06-03T17:16:12.157Z
Comments.Text: Use https://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.
Comments.UserDisplayName: Fabby
Tags: <ffmpeg>
Title: FFMPEG cut video and concat put it in reverse
UserDisplayName: Jakub Dobrzeniecki
ThreadText: # FFMPEG cut video and concat put it in reverse
  
  (Asked by: username_0 on 2019-06-02)
  
  I received a script that cuts video into sub-clips with a specific durationand then `concat`s them again but for some reason the script `concat`s 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?*
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: 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  
  > **username_0**: I took it from here and modified for my needs. https://superuser.com/questions/1298270/ffmpeg-mp4-to-webm-make-a-10-second-compilation-based-on-length  
  > **username_1**: Use https://shellcheck.net when adapting scripts to check for syntax errors.  Do that first and then copy-paste what you currently have, then ping me @username_1 again.  
  
  ---
  
  ## 0 answers
  
  