Question

I am trying to convert a directory full of mp3's (with spaces in file names) to m4a.

To convert a single file (this works):

ffmpeg  -i Traffic.mp3 -c:a libfaac -vn Traffic.m4a

The command that is failing (on OS X Mavericks):

find . -name \*.mp3 -print0 | xargs -0 ffmpeg -i {}  -c:a libfaac -vn {}.m4a
Was it helpful?

Solution

find . -name '*.mp3' -type f -exec bash -c 'ffmpeg -i "$0" -c:a libfaac -vn "${0%.mp3}.m4a"' {} \;

OTHER TIPS

Why do you use xargs? find -exec is enough:

find . -name \*.mp3 -exec ffmpeg -i {} -c:a libfaac -vn {}.m4a \;

The problem is that xargs is more similar to find -exec … + than find -exec … \;. It launches preferably just one instance of the command, replacing a single {} by sequence of space separated items read from input (more or less). If you want xargs to behave like find -exec … \;, you need to specify -I{} (xargs -0 -I{} ffmpeg …).

This converts Traffic.mp3 to Traffic.mp3.m4a. If you want to save the conversion result to Traffic.m4a, you can

  • rename the files after the conversion (not a very clean solution),
  • execute shell in the -exec action and remove the .mp3 before appending .m4a or
  • use xargs after sedding the .mp3 extension away from find result.

I vote for the last option as it executes less processes (and shell is quite a big one, though ffmpeg would be difinitely so large that the difference in performance is negligible).

find . -name \*.mp3 | sed 's/\.mp3$//' | xargs -I{} ffmpeg -i {}.mp3 -c:a libfaac -vn {}.m4a
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top