Script to recode mp4 files to avi Divx

Using avidemux to recode mp4 files to Divx .avi. Script converts all files in current dir. Uses avidemux.

#!/bin/bash
VAR="files.txt"
ls *.mp4 | sort > $VAR # Collect the files in the current directory
cat $VAR | while read line; do  # Loop read the filenames from the file
  INPUT=$(echo ${line}) # Grab the nxt new filename
  OUTPUT=${INPUT%.*4} # Remove shortest match of characters between the '. ' and the '4' at end of string
  OUTPUT+=".avi" # Append new extension
  avidemux --force-alt-h264 --output-format AVI --video-codec Xvid --audio-codec mp3 --load "$INPUT" --save "$OUTPUT" --quit 
done
rm $VAR # Remove the text file with the file names