How To Resample Audio Files With GStreamer

April 9, 2011 by
Filed under: command line, HowTo, lame, linux, mp3, Ubuntu 

One of the older posts on this site shows how to resample MP3 files on Linux with LAME. One of the problems with that process is that the MP3 tags are not maintained when resampling, so I had to work around the issue by copying certain tags from the original files to the new files. As it turns out, there's a way to use the GStreamer framework to resample audio files and maintain the tags. In this post I'll show the commands you can use to resample audio files to both constant bitrate and variable bitrate MP3's.

The following examples show how to resample MP3 files, but the decodebin2 plugin automatically figures how to decode any type of stream that GStreamer can handle, so these examples will also work to convert audio files from other formats to MP3.

Resample MP3: CBR

This first example shows how to read an MP3 encoded at 320 kbps and resample it to a constant bitrate of 128 kbps.

gst-launch filesrc location=05-Fly_By_Night-320kbps.mp3 ! decodebin2 ! audioconvert ! lamemp3enc target=bitrate bitrate=128 ! id3v2mux ! filesink location=05-Fly_By_Night-128kbps.mp3

Resample MP3: VBR

The second example shows how to read an MP3 encoded at 320 kbps and resample it to a variable bitrate with a quality setting of 9. Valid values for quality are 0-9.999 with 0 being the best.

Affiliate Link
gst-launch filesrc location=05-Fly_By_Night-320kbps.mp3 ! decodebin2 ! audioconvert ! lamemp3enc target=quality quality=9 ! id3v2mux ! filesink location=05-Fly_By_Night-quality_9.mp3

Comments

3 Responses to “How To Resample Audio Files With GStreamer”

  1. [...] few searches on the Internet led me to this page, where I learned the command line to convert a single file: gst-launch filesrc location=input.mp3 [...]

  2. Schnoggo says:

    Which packages do you need to install? I installed basic gstreamer, but didn't get decodebin2

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>