FfmpegandAudio

From XPUB & Lens-Based wiki

Audio transcoding with ffmpeg

transcode to mp3

ffmpeg -i in_file.aiff -acodec libmp3lame -ab 128k out_file.mp3


transcode to ogg

ogg/Vorbis audio files (Vorbis codec; ogg file-format) are quite important, not only it is an open-source format, but also firefox requires ogg format in its <audio> Quality seems quite good (better than mp3 when compressed from a uncompressed audio format: flac, wav or aiff, so it says)

ffmpeg -i input.mp3 -acodec libvorbis -ab 128k output.ogg
  • explained:
    • -acodec libvorbis use vorbis codec
    • -ab 128k convert output to 128kbits/sec bit-rate alternatively can use -aq 60 which means audio quality is 60 (~160 kbits/sec)

good information on ffmpeg transcoding: http://howto-pages.org/ffmpeg/#basicaudio


Here is a small script to turn all the .mp3 on the directory to .ogg

#! /bin/sh

ext=".mp3"
target="ogg"
 
for n in *.mp3
do
base=$(basename $n $ext) #to extract only the filename and NOT the extension
ffmpeg -i $n -acodec libvorbis -ab 128k $base.$target 

done
#Script ends here



Adding metadata to mp3 files

unfortunately metadata doesn seem possible to be added to ogg files with ffmpeg

ffmpeg -i infile.mp3 -metadata author="the author name" -metadata title="the title" -acodec copy outputfile.mp3
#! /bin/sh

# adds metadata to all .mp3 files of the directory the script is located
# it employs the file name as the song's title 

ext=".mp3"
 
for n in *.mp3
do
base=$(basename $n $ext) #to extract only the filename and NOT the extension
ffmpeg -i $n -metadata author="YOUR NAME" -metadata title=$base -acodec copy $base$ext

done


Source: http://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata ffmpeg and metadata