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
I would use bash
for
loop for this purpose - let's assume you are in the parent directory, that contains the directoriesvideos/
andcompressed/
:Or if you want to convert any type of video file to mkv, you can use:
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.References: