Converting several ogg files to mp3

#!/bin/bash

root=.

for file in *.ogg

do
    basename="${file%.*}"
    opusdec ${file} ${basename}.wav
    lame ${basename}.wav ${basename}.mp3
done

Converting several ogg files to wav, concatenating them, then converting the concatenated file to an mp3

#!/bin/bash

prefix=whatever

for file in ${prefix}*.ogg

do
    basename="${file%.*}"
    opusdec ${file} ${basename}.wav
done

# https://superuser.com/a/587512
ffmpeg -f concat -safe 0 -i <( for f in ${prefix}*.wav; do echo "file '$(pwd)/$f'"; done ) combined.wav

lame combined.wav ${prefix}-complete.mp3

With ffmpeg

If lame is not installed on the machine, you can use ffmpeg.

#!/bin/bash

cd your/dir || exit 1

for file in *.mp3
do
  basename="${file%.*}"
  ffmpeg -i ${file} ${basename}.wav
done

Extracting audio from a video

Decoding aac

  • Install gstreamer: sudo apt-get install gstreamer1.0-libav
  • ffmpeg -i file.m4a file.wav

Converting mono to stereo

#!/bin/bash

dir=path/to/mono-files
outdir=path/to/new-stereo-files
for file in ${dir}/*.wav
do
  filename=${file##*/}
  outfile="${outdir}/${filename}"
  echo "Converting to ${outfile}."
  sox -M "${file}" "${file}" "${outfile}"
done

Converting sample rates and bitrates in mp3s

#!/bin/bash

for file in .mp3 do filename={file##/} wavfile="{filename}.wav" convfile="{filename}-converted.wav" outfile="{filename}-44k_16b.mp3" lame --decode "{filename}" "{wavfile}" echo "Converting to 44.1 kHz sample rate and 16-bit" sox "{wavfile}" -b 16 -r 44100 "{convfile}" lame "{convfile}" "{outfile}" done

#sox #lame #sample