Replacing the Loop
Use
find -type f -name '*.mkv' -exec ffmpeg -n -i {} -c:v copy ~/Pobrane/{} \;
-exec
executes the following ffmpeg
command for each of the found paths, replacing {}
with the current path. The ;
informs find
that the ffmpeg
command ends there.
Quote '*.mkv'
in order to pass the literal string to find
, which then searches for files ending with *.mkv
. If you do not quote the string and have some mkv files laying around in your working directory, the shell will expand the unquoted *.mkv
resulting in find -type f -name firstFile.mkv secondFile.mkv ...
before starting find
.
Do not quote ~
. The unquoted ~
expands to your home directory (probably /home/yourname
) but the quoted '~'
is a directory/file with the literal name ~
.
Creating Parent Directories
How would I add mkdir -p
before the ffmpeg call?
You could wrap the mkdir
and ffmpeg
in one function and execute the function:
myFunction() {
mkdir -p "$(dirname "$1")"
ffmpeg -n -i "$1" -c:v copy ~/Pobrane/"$1"
}
export -f myFunction
find -type f -name '*.mkv' -exec bash -c 'myFunction "$0"' {} \;
or use a loop:
find . -type f -iname "*.txt" -print0 | while IFS= read -r -d $'\0' file; do
mkdir -p "$(dirname "$file")"
ffmpeg -n -i "$file" -c:v copy ~/Pobrane/"$file"
done