title: Run FFmpeg from Shell Script
body: <p>I have found a useful shell script that shows all files in a directory recursively.</p>
  
  <p>Where it prints the file name <code>echo "$i"; #Display File name</code>.</p>
  
  <p>I would instead like to run an ffmpeg command on non MP3 files, how can I do this? I have very limited knowledge of shell scripts so I appreciate if I was spoon fed! :)</p>
  
  <pre><code>//if file is NOT MP3
  
  ffmpeg -i [the_file] -sameq [same_file_name_with_mp3_extension]
  
  //delete old file
  </code></pre>
  
  <p>Here is the shell script for reference.</p>
  
  <pre><code>DIR="."
  
  function list_files()
  {
      if !(test -d "$1")  
      then echo $1; return;
      fi
  
      cd "$1"
      echo; echo `pwd`:; #Display Directory name
  
      for i in *
      do
                 if test -d "$i"  #if dictionary
                  then  
                            list_files "$i" #recursively list files
                    cd ..
                  else
              echo "$i"; #Display File name
                  fi
  
      done
  }
  
  if [ $# -eq 0 ]
  then list_files .
  exit 0
  fi
  
  for i in $*
  do
      DIR="$1"
      list_files "$DIR"
      shift 1 #To read next directory/file name
  done
  </code></pre>