Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

For testing, I want to convert an MP3 and WAV file I have to Opus, what are the steps to doing this?

share|improve this question
    
Converting an mp3 to an opus is a horrible idea. –  Evan Carroll Jan 11 '13 at 16:44
    
@EvanCarroll Hence the part that says "For testing" ;) –  Luis Alvarado Jan 11 '13 at 18:18
1  
@EvanCarroll That depends on what you want to achieve and the quality of the input material. If you're looking for an absolute audiophile solution, you probably never want to consider Opus in the first place. Saying it is a horrible idea is just a horrible statement, when there is no explanation. –  LiveWireBT Mar 4 '13 at 22:05
    
@LiveWireBT Says that encoding an mp3 in opus is not a horrible idea unless you're looking for an absolute audiophile solution is just a horrible statement, when there is no explanation. –  Evan Carroll Mar 4 '13 at 22:34
    
re: the top. Encoding an mp3 in Opus is a bad idea because you compound the failures of both formats. If you assume MP3 is ABX %5 at 128 kbps, then the Opus is 2% ABX at 128 kbps, the final stream is significantly higher than the 2% rate by Opus, or the 5% rate by MP3. Moreover, it's likely that file has no size advantages whatsoever, and the encoding time is compounded by the second encoding. You get no benefits whatsoever if you have the mp3 input. And, with the original, you get no benefits by using MP3 as an intermediary format. –  Evan Carroll Mar 4 '13 at 22:40
show 3 more comments

4 Answers

up vote 9 down vote accepted

Per default the audio converter shipped with the opus-tools Install opus-tools can convert audio in raw, wave or AIFF format. The minimal syntax uses default settings:

opusenc input.wav output.opus

We may want to add a better bitrate as the default 96 kbps with the option --bitrate N.nnn (for all options consult the manpage for opusenc).

To convert mp3 "on the fly". i.e. without creating a temporary file we can pipe the output from avconv to opusenc like this:

avconv -i input.mp3 -f wav - | opusenc --bitrate 256 - output.opus
share|improve this answer
add comment

Opus on 12.04

On 12.04 (Precise), however, there are dependency problems with installing the opus codecs and tools, so I have found by far the best solution is the one that has become available very recently: compile the opus audio encoder and decoder as noted here, and build ffmpeg with opus support by adding --enable-opus to the configure options of ffmpeg (as listed on the compilation guide).

I know that ffmpeg is deprecated in Ubuntu in favour of Libav, but compiling is a good way to get a fully functioning opus encoder/decoder integrated into ffmpeg itself. You can then use it to convert files (first to wav) and then to .opus. The documentation installed with libopus and ffmpeg will reveal all the options that can be used to convert files.

When converting files with ffmpeg after compilation, you must specify -acodec libopus or ffmpeg will not use the opus codec:

ffmpeg -i pc.wav -ar 48000 -ac 2 -acodec libopus -ab 256k man.opus

You can then test the file created with

ffplay man.opus

Compilation Tips

There's no need to reproduce the guide here in its entirety, but it's worth noting one or two things:

  • You should first install the dependencies as listed (I omit yasm from the list: see my second point):

     sudo apt-get -y install autoconf build-essential checkinstall git libass-dev libfaac-dev libgpac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev librtmp-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
    
  • There is one issue that should be pointed out: the git build seems to want yasm-1.2, and that is not available, so you have to compile the source from the official site, but it is simple. Just remove any installed versions of yasm, then unpack the downloaded archive, cd to the folder, run ./configure && make and then sudo checkinstall. If any other builds require the earlier version, you can just remove this version and install the repository version.

  • It is necessary to remove any existing libav, ffmpeg, x264, libvpx, or fdk-aac packages before you start compiling.

  • It is critical that you compile and install x264, fdk-aac, libvpx and opus before you build ffmpeg, as those libraries will be used in the build.

  • Do not forget to add --enable-opus to the configure options when you run the ffmpeg compilation.

  • The version of opus compiled was 1.1alpha, so you may need to re-compile the opus library and ffmpeg in the future again when a new version is released.

  • You can use ffplay to play any opus files you create.

share|improve this answer
    
ffmpeg is a bad solution for anything there is a replacement for. –  Evan Carroll Jan 11 '13 at 16:43
2  
@EvanCarroll What do you mean by this? It's only someone's decision to deprecate it: ffmpeg is still as good as libav, which is just a fork of it. –  user76204 Jan 11 '13 at 16:44
1  
A great answer, and thanks for the reminder on the Yasm requirement. x264 increased the minimum version to 1.2.0 on their last push. Guide updated with Yasm instructions. –  LordNeckbeard Jan 11 '13 at 19:38
    
@Mik I think he wanted to say that the stand alone encoder will give better results. –  LiveWireBT Mar 4 '13 at 21:57
    
I saw some people mentioned having "opus not found" error when following the instructions to compile ffmpeg. I had the same issue in Ubuntu 12.04, and later found out the PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" needs a slash at the end. –  user175483 Jul 15 '13 at 21:54
add comment

Another option, if you are using 12.04 you can use the KXStudio PPA's to get the best selection of audio-related everything, and they now include backported opus-tools!

See http://kxstudio.sourceforge.net/

share|improve this answer
    
This sounds like an advert... –  papukaija Jul 15 '13 at 23:21
    
The one whose description says "DO NOT USE THIS PPA!"? launchpad.net/~kxstudio-team/+archive/ppa –  Christian Mar 22 at 5:06
add comment

Ubuntu 14.04 and Debian 8 ship with version 9 of libav-tools in their repositories, and it has built-in support for Opus through the package libopus0.

With version 9 of libav-tools and libopus0 installed you can simply, for example, do:

avconv -i file.mp3 -map 0:a -codec:a opus -b:a 100k -vbr on file.opus
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.