1

For the script below:

Is it possible to make out of these six lines one single line that is looking for mp4, webm etc. files in one step? (perhaps with something like: ".*\.mp4|.*\.webm..."?

for i in *.mp4 ; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3 ; done;
for i in *.webm ; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3 ; done;
for i in *.m4a ; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3 ; done;
for i in *.3gp ; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3 ; done;
for i in *.mpeg ; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3 ; done;
for i in *.aac ; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3 ; done;
  • 4
    Possible duplicate of [Matching files with various extensions using for loop](https://stackoverflow.com/q/6223817/608639), [for loop for multiple extension and do something with each file](https://stackoverflow.com/q/12259331/608639), [Loop over multiple file extensions from bash script](https://stackoverflow.com/q/49103942/608639), [for loop in bash go though files with two specific extensions](https://stackoverflow.com/q/34382072/608639), etc. – jww Aug 19 '18 at 06:41
  • Do you want the output files to have a ".mp3" *added*, or to replace the old extension? For example, should file.webm be converted to file.webm.mp3 or file.mp3? If the latter, use `"${i%.*}.mp3"` as the output file. – Gordon Davisson Aug 19 '18 at 19:31

1 Answers1

1
for i in *.mp4 *.webm *.m4a *.3gp *.mpeg *.aac; do avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$i".mp3; done
Cyrus
  • 84,225
  • 14
  • 89
  • 153