Skip to content

Instantly share code, notes, and snippets.

@liamcurry
Created September 18, 2011 17:22
Show Gist options
  • Save liamcurry/1225299 to your computer and use it in GitHub Desktop.
Save liamcurry/1225299 to your computer and use it in GitHub Desktop.
Converting FLAC to various formats
ffmpeg -i name.flac -acodec alac name.m4a
ffmpeg -i name.flac -acodec libmp3lame -ab 320k -ac 2 -ar 48000 name.mp3
ffmpeg -i hlah_3.flac -strict experimental -acodec vorbis -aq 100 hlah.ogg
#!/usr/bin/python
import gobject
import gst
converter = gst.Pipeline('converter')
source = gst.element_factory_make('filesrc', 'file-source')
source.set_property('location', 'test.flac')
decoder = gst.element_factory_make('flacdec', 'decoder')
encoder = gst.element_factory_make('lame', 'encoder')
sink = gst.element_factory_make('filesink', 'sink')
sink.set_property('location', 'test.mp3')
converter.add(source, decoder, encoder, sink)
gst.element_link_many(source, decoder, encoder, sink)
converter.set_state(gst.STATE_PLAYING)
gobject.threads_init()
gobject.MainLoop().run()
#!/usr/bin/python
import gst
import gobject
import os
dirname = os.path.dirname(os.path.abspath(__file__))
source = os.path.join(dirname, 'test.flac')
dest = os.path.join(dirname, 'test.mp3')
pipeline = gst.parse_launch('filesrc location="%s" ! flacdec ! lame ! filesink location="%s"' % (source, dest))
pipeline.set_state(gst.STATE_PLAYING)
gobject.threads_init()
gobject.MainLoop().run()
# wav -> ogg
gst-launch filesrc location=music.wav ! wavparse ! audioconvert ! vorbisenc ! oggmux ! filesink location=music.ogg
# wav -> mp3
gst-launch filesrc location=music.wav ! wavparse ! audioconvert ! lame ! filesink location=music.mp3
@edouard-lopez
Copy link

From FLAC to MP3|OGG|OPUS, using avconv:

input="file.flac"
# → MP3
output="${input%flac}mp3" # remove 'flac', append 'mp3'
avconv -i "$input" -ab 256k "$output"
# → OGG
output="${input%flac}ogg"
avconv -i "$input" -acodec libvorbis -aq 100 "$output"
# → OPUS
output="${input%flac}opus"
avconv -i "$input" -f wav - | opusenc --bitrate 256 - "$output"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment