Help me debugs this script to create control ffmpeg from a bash script.

for f in $FILES
    INPUT_MOVIE=`basename "${f%.*}.mkv"`
    OUTPUT_MOVIE=${OUTPUT_MOVIE:0:2}") processed "${OUTPUT_MOVIE:2}
    /usr/bin/ffmpeg -i $INPUT_MOVIE -map 0:0 -vcodec copy -map 0:1 -acodec copy $OUTPUT_MOVIE
    /usr/bin/sleep 3

I've tried attaching the sleep but the processes seems to start to pile up. Is there a way to do them sequentially so that one video is processed after the other?

  • 1
    What you show should run one after the other. What makes you think the processes pile up? Could it just be that ffmpeg launches multiple instances of itself?
    – terdon
    Jun 1, 2016 at 17:44
  • what, exactly, is in $FILES? (and don't just say "filenames", that's obvious. Show some examples, add them to your question). Spaces, newlines, globbing characters? Use an array. Also, always double-quote ALL your variables. And why the weird usage of both basename AND ${f%.*}?
    – cas
    Jun 2, 2016 at 3:07
  • and where is $MOVIE defined? do you mean INPUT_MOVIE there? BTW, if you run something in the background and later want to wait until it's finished before doing something else, don't use sleep. use wait. that's what it's for. see help wait in bash for details.
    – cas
    Jun 2, 2016 at 3:12

1 Answer 1


Would this work for your purposes?

for i in *.mkv; do ffmpeg -i "$i" … ;done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.