2

I'm trying to remove the file that I was working on previously but it's not letting me, please help. Here is the command I run:

find . -type f -name '*.flac' -print0 |
  xargs -0i ffmpeg -i {} -acodec libmp3lame -ab 320k "{}.mp3" |
  rm -rf {}

4 Answers 4

3

If you have GNU Parallel installed you can do:

find . -type f -name '*.flac' | parallel ffmpeg -i {} -acodec libmp3lame -ab 320k {.}.mp3 '&&' rm {}

It will run one ffmpeg process per CPU core.

To learn more watch the intro videos: http://pi.dk/1

8
  • Hi, I think I might have to try this. I have a 3.2GHz Quad Core Xeon E3-1230 CPU, Passmark CPU mark Score of 8,200, 32GB ram - and I can't do more than 4 ffmpeg commands without being overloaded... not sure why... i might have to consider this if you're telling me that I can get each ffmpeg session to run on it's own cpu core.
    – thevoipman
    Jul 28, 2012 at 8:38
  • Not sure what you mean by 'overloaded'. GNU Parallel will most likely detect 8 cores (because of hyperthreading) and start 8 ffmpeg jobs in parallel. GNU Parallel does not guarantee a process will run on its own core. It simply start the number of jobs corresponding to the number of cores. Your O/S takes care of the rest.
    – Ole Tange
    Jul 30, 2012 at 18:47
  • I tweaked it up and ran it like this and it worked great!: find . -type f -name '*' | parallel ffmpeg -i {} -sameq {.}.mp4 '&&' rm {}
    – thevoipman
    Aug 1, 2012 at 3:16
  • So if I understood this coorectly. does this mean that I can do a | and run another command i want with parallel? For example, if I want to upload the recently encoded file to an ftp server, how would i do this with a single line?
    – thevoipman
    Aug 1, 2012 at 6:02
  • 1
    Something like (where upload is the program you use to upload with): find . -type f -name '*.flac' | parallel ffmpeg -i {} -sameq {.}.mp4 '&&' upload {.}.mp4 '&&' rm {}
    – Ole Tange
    Aug 2, 2012 at 7:01
2

You are piping the output of the ffmpeg call(s) into the rm command. Since ffmpeg produces no interesting output and rm does not read any input, this doesn't do anything.

I'm not sure what you're trying to do. I think you want to remove the flac file after processing. You have several choices: you can first convert all the ffmpeg files, then remove them all; or you can remove each file after it's been processed. I advise the latter, otherwise it will be difficult to only remove the flac file if the conversion succeeded.

Rather than use xargs, it's simpler to use find … -exec here. For each flac file, call ffmpeg, and then delete the file if ffmpeg succeeded. If your find doesn't have the -delete action, use -exec rm {} \; instead. Use an intermediate shell to construct the output file name.

find . -type f -name '*.flac' \
     -exec sh -c 'ffmpeg -i "$0" -acodec libmp3lame -ab 320k "${0%.*}.mp3"' {} \; \
     -delete

You can use the rm command inside the shell snippet instead.

find . -type f -name '*.flac' \
     -exec sh -c 'ffmpeg -i "$0" -acodec libmp3lame -ab 320k "${0%.*}.mp3" && rm "$0"' {} \;

With some versions of find, if you want the output file to be called foo.flac.mp3, you can skip the intermediate shell.

find . -type f -name '*.flac' \
     -exec ffmpeg -i {} -acodec libmp3lame -ab 320k {}.mp3 \; \
     -delete
1
  • The second option looks like the best AND the simplest option, doing exactly what the question requires, using no pipes. Very elegant solution.
    – Samveen
    Jul 20, 2012 at 10:05
0

The command rm doesn't take input from standard input, so you need to send it input using xargs just like you did for ffmpeg

try this:

find . -type f -name '*.flac' -print0 |
    xargs -0i bash -c 'ffmpeg -i {} -acodec libmp3lame -ab 320k \"{}.mp3" ; rm -rf {}'

This adds rm into the command xargs executes, essentially creating an inline shell script using bash -c.

0
0

First of all, "it's not letting me" is not the best way to describe the problem. You should post the error message or describe what happens.

Second, I don't quite get what you're trying to achieve, but you're not using rm with xargs, you just pipe something to rm. That's not how rm works.

find . -type f -name '*.flac' -print0 | xargs -0i rm "{}"

would probably work, for example. I'm not using rm -r here, because find only looks for files anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.