![]() For Windows you have to compile it yourself, or trust some websites that provide binaries. For Mac OS X, you can use the "lame" package of MacPorts or Fink. Installing on Linux should be easy: just look for the "lame" package. Lame is a well known open source MP3 encoder. # Note: you can also use '-ab 64k', but I'm not sure how well this # is supported in different version of FFmpeg # Picking the 30 seconds fragment at an offset of 1 minute: # In secondsįfmpeg -i input.mp3 -ss 60 -t 30 output.wavįfmpeg -i input.mp3 -ss 0:01:00 -t 0:00:30 output.wavĮncode as MP3 or re-encode an MP3 file to a different bit rate with Lame # Convert WAV to MP3, mix down to mono (use 1 audio channel), # set bit rate to 64 kbps and sample rate to 22050 Hzįfmpeg -i input.wav -ac 1 -ab 64000 -ar 22050 output.mp3 # You can get the list of supported formats with: # Minimal example: transcode from MP3 to WMA For Mac OS X, I installed the "ffmpeg" package through MacPorts, and there is also one for Fink.įFmpeg is typically used for video, but audio transcoding works too and is pretty simple: Getting it working on Windows apparently requires you to compile it yourself (or trusting a website that provides binaries). ![]() Installing is easy with a sufficient recent Linux distribution, install the "ffmpeg" package (note: on Ubuntu 9.10 aka Karmic Koala, I also had to install "libavcodec-unstripped-52", to make MP3 encoding possible, your mileage may vary). Transcode with FFmpeg (from and to a wide variety of formats)įFmpeg is another powerful open source tool for multimedia handling like conversion/transcoding. Note: on some platforms I had to add the option -format s16le to make sure MPlayer encoded 16 bit PCM samples instead of 24 bit or even 32 bit, which can cause problems with some audio players/tools. # To avoid this, set the format explicitly with: # -format s16le # Pick the 30 seconds fragment at an offset of 1 minute: On some setups however, # MPlayer uses 32 bits per sample by default. ![]() # By default, one expects 16 bits per sample. # Use additional audio filters (-af) to resample to 22050 Hz # and mix down to mono. ao pcm:fast:waveheader:file =output.wav \ # Decode the audio channel to PCM (WAV) and ignore the video channels For clarity, the command is spread out over several lines here (do not forget to remove the backslashes when you want it on one line): The invocation bit more complex than with the other decoders shown here. MPlayer is available for Linux (package "mplayer"), Windows and Mac OS X. It is typically used for playing video with a GUI, but can also be used (in batch mode without a GUI) to convert the audio to WAV format. MPlayer is a media player that supports a wide range of multimedia formats. Decode to WAV (from wide variety of formats) with MPlayer If you're up to it, you can recompile SoX with MP3 encoding support, but there are other options if you really want MP3 encoding (see below). Reading MP3 files worked for me (Ubuntu 8.04 and higher) after installing the "libsox-fmt-all" package. One issue with SoX is that default installs typically do not support writing MP3 files because of the patent and licensing issues with MP3. Sox input.mp3 output.wav trim 60 30 channels 1 rate 22050 Sox input.mp3 output.wav trim 60 30 # All together now (trimmed fragment in mono, 22.05 Hz sample rate) # Trim a fragment of 30 seconds at an offset of 60 seconds # with the 'trim' effect ![]() Sox input.mp3 output.wav rate 8000 # Newer versions of SoX also support Sox input.mp3 output.wav channels 1 # Change sample rate (again two possibilities) # Convert to mono (two possibilities: by specifying output format # or with the 'channels' effect. It's available for Linux (search for 'sox' in your package manager), Mac OS X and Windows. pitch shifting, reverb, low pass filtering, flanger, etc). SoX (Sound eXchange) calls itself "the Swiss Army knife of sound processing programs" and offers, apart from standard audio format and sample rate conversion, a basic set of effects (e.g. Update: also see a follow up blog post about an execution time comparison between SoX, FFmpeg and MPlayer. If you need more/other functionality, look in the man pages or ask your favorite search engine. Note that I only cover the operations I mostly need, like format conversion, sample rate conversion, conversion to mono and trimming/cropping. Having a cheat sheet of how to invoke them with the desired options has proven to be very useful, so here is mine. Because I typically have to do this in batch jobs, I'm mostly dealing with command line tools (on Linux) like Lame, SoX (Sound eXchange), MPlayer and FFmpeg. In my day job, I regularly have to convert/transcode/re-encode audio data from one format to another. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |