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
  • basic audio extraction with ffmep is ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3 where vn is no video and acodec copy says use the same audio stream that's already in there; from Github – damadam Dec 20 '19 at 08:59
  • I suggest you also to add a sed command, in order to remove the .mp4 extension on the filename, or your music filename would be for example music.mp4.mp3 – damadam Dec 20 '19 at 09:01

1 Answers1

7

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
  • 100,812
ntd
  • 168