Harvey King
Harvey King

Reputation: 71

batch convert files using ffmpeg and find -exec and parallel

From another stack exchange post, I came to know that I can batch convert media file with original file name intacted and only change the file extension by using the following

find ./ -name '*.mp4' -exec bash -c 'ffmpeg -i $0 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 ${0/mp4/mp3}' {} \;

Since most computers nowadays have multiple cores, how do I modify the above command, so I can use all 4 cores in the -exec part of find thus I can convert 4 media files at the same time?

I know GNU parallel can do something similar, but I don't know how to combine them into one single command.

Thanks in advance

Harv

Upvotes: 1

Views: 1260

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207455

You can pass the filenames, null-terminated to parallel like this:

find . -name \*.mp4 -print0 | parallel -0 ...

You can access parameters in parallel via {} and you can get filenames without their extensions using {.}, so you want:

find . -name \*.mp4 -print0 | parallel -0 ffmpeg -i {} ... {.}.mp3

Try it with parallel --dry-run first to see if it looks right. It will use all cores by default anyway.

Upvotes: 1

Related Questions