I have many videos in a folder, and I want to compress them all with one command.

To compress one video I use:

sudo apt-get install ffmpeg
ffmpeg -i input.mp4 output.mp4

But what if I have many videos I want to compress? I've tried the following:

ffmpeg -i ./videos ./compressed-videos

But then I get this error:

./videos: Is a directory

1 Answer 1


I would use bash for loop for this purpose - let's assume you are in the parent directory, that contains the directories videos/ and compressed/:

for f in videos/*mp4; do ffmpeg -i "$f" "compressed/${f##*/}"; done

Or if you want to convert any type of video file to mkv, you can use:

for f in videos/*; do ffmpeg -i "$f" "compressed/$(basename "${f%.*}").mkv"; done

In the above examples:

  • ${var##*/} will outputs all characters after the last slash /, so only the filename without the path will remains;
  • ${f%.*} will outputs all characters before the last dot, so the path and the filename will be kept but the file extension will be removed. Then the command substitution $(basename "/path/name") will outputs only the name without the path.


  • Anyway to do this at the same time? We want to split up and use all the cores. Dec 10, 2022 at 14:42
  • Hello, @OliverDixon. You can use something like nohup ffmpeg ... >/tmp/${var##*/}.log 2>&1 & to run each ffmpeg command in a detached shell, then you can monitor the progress of each by the created log. Here is an references: askubuntu.com/a/1192383/566421
    – pa4080
    Dec 10, 2022 at 18:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .