Find files and HandBrakeCLI convert in a single line

439 views Asked by At

Not sure if this is possible...

I'm trying to write a terminal command (linux) that would find all video files with a specific extension and then convert them using HandBrakeCLI

I have the first half of that down:

find . -type f -name "*.avi*" -exec

And I have a working HandBrakeCLI command:

HandBrakeCLI -i file.mkv -o file2.mkv -e x265 --vfr -q 20 --all-audio --all-subtitles

What I have been unable to figure out is how to insert the file name/path for the files found in the find into the file.mkv and then output the converted file with the same file name but in an mkv format.

Is it possible to do this in one line or do I need to break this out in a bash script?

1

There are 1 answers

0
tshiono On BEST ANSWER

As a one-liner, try something like:

find . -type f -name "*.avi" -print0 | perl -pe 's/\.avi\0/\0/g' | xargs -0 -I% HandBrakeCLI -i %.avi -o %.mkv -e x265 --vfr -q 20 --all-audio --all-subtitles

-print0 option in find prints the filename on the standard output, followed by a null character.
The following perl snippet removes the .avi extention to supply the basename to xargs.
-I% option in xargs replaces "%" with names read from standard input.