3

I have a folder mostly containing mp4 videos. I want to extract the audio of those videos.

for i in $(ls); do echo ffmpeg -i $i $i_mp3; done

This command doesn't take any concern for the none mp4 files, and it seems to be adding line breaks in the ls command.

Adam
  • 515

1 Answers1

8

The ls command is superfluous: filename expansion should be just enough. I did not understand the adding line breaks part of your question though... I suppose you had problems with blank spaces in filenames.

I would personally use a variant of the following command:

for f in *.mp4; do ffmpeg -i "$f" -vn "$(basename "$f" .mp4).mp3"; done

The basename part is just to remove the .mp4 suffix from $f. You can use some bash trickery instead, but I never remember the syntax.

terdon
  • 104,119
ntd
  • 198