-vbr on turns on variable bitrate. This is an option specific for libopus. Here are all options for libopus:
$ avconv -h full | grep opus -A 11
avconv version 9.11-6:9.11-3+b2, Copyright (c) 2000-2013 the Libav developers
built on Apr 6 2014 17:45:45 with gcc 4.8 (Debian 4.8.2-16)
libopus AVOptions:
-application <int> E..A. Intended application type
voip E..A. Favor improved speech intelligibility
audio E..A. Favor faithfulness to the input
lowdelay E..A. Restrict to only the lowest delay modes
-frame_duration <float> E..A. Duration of a frame in milliseconds
-packet_loss <int> E..A. Expected packet loss percentage
-vbr <int> E..A. Variable bit rate mode
off E..A. Use constant bit rate
on E..A. Use variable bit rate
constrained E..A. Use constrained VBR
file.opus sets the output file.
Example 2: Grab the audio from a video file and encode it as opus
Take the second stream of the first input (-map 0:1), which is the audio stream. Encode it with libopus at 100 kbit/s with variable bitrate on:
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:
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.
It's super fast! Less than 8 seconds with a complexity of 10 (Encoding computational complexity (0-10, default: 10). Zero gives the fastest encodes but lower quality, while 10 gives the highest quality but slower encoding) and a maximum delay time of 10ms (Maximum container delay in milliseconds (0-1000, default: 1000)), so if you skip time in a song, the clipping effect will have a duration of 10ms so it is inperceptible (try with 1000 and hear the difference skipping time with your mouse). Bitrate is VBR by default. 320kbps worked for me so is optional, play with this number: --bitrate N.nnn => Target bitrate in kbit/sec (6-256 per channel)
By the way, encoding from MP3 to OPUS is not a good idea, it's not going to sound better, their compression algorithms are way too different. But from FLAC or WAV or any other Lossless Audio Format, that's another story.
Note: To encode another file, just press the Up Arrow in the same terminal to call the last command and change the name of the input and output files.
If you are looking for a ffmpeg/avconv GUI, maybe TraGtor is what you need.
You can also check the spectogram differences between Lossless and Lossy formats at high bitrates with Spek or Audacity.
If only the mp3 to opus route is needed, mpg123 can do the decoding to wav/pcm.
mpg123 -w - input.mp3 | opusenc - output.opus
For the unfamiliar the dash "-" functions as stdout on the left to be piped to opusencs stdin on the right.
Of course ffmpeg is excellent for general media conversion and editing, but its install size and usual distribution dependencies also have a bigger footprint.
In newer Ubuntu releases the Opus codec is included in the libavcodec libraries that will be installed with ffmpeg. Audio encoding is then done with
The audio converter shipped with the opus-tools can convert audio in raw, wave or AIFF format. The minimal syntax uses default settings:
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 ffmpeg to opusenc like this:
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 packagelibopus0
.Example 1: Reencode an audio file as opus
With version 9 of
libav-tools
andlibopus0
installed you can simply, for example, do:What the options do
-i file.mp3
sets the input file.-map 0:a
will select all audio streams (a
) from the input file0
. Read more about-map
on https://libav.org/avconv.html#Advanced-options-codec:a opus
selects the opus encoder for the audio streams (a
). Read more about-codec
on https://libav.org/avconv.html#Main-options.-b:a 100k
sets the audio's bitrate to 100 kilobit/s. Read more about-b
on https://libav.org/avconv.html#Codec-AVOptions-vbr on
turns on variable bitrate. This is an option specific for libopus. Here are all options for libopus:file.opus
sets the output file.Example 2: Grab the audio from a video file and encode it as opus
Take the second stream of the first input (
-map 0:1
), which is the audio stream. Encode it with libopus at 100 kbit/s with variable bitrate on:With the package
mediainfo
installed: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 offfmpeg
(as listed on the compilation guide).I know that
ffmpeg
is deprecated in Ubuntu in favour ofLibav
, but compiling is a good way to get a fully functioning opus encoder/decoder integrated intoffmpeg
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
orffmpeg
will not use the opus codec:You can then test the file created with
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):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 ofyasm
, then unpack the downloaded archive,cd
to the folder, run./configure && make
and thensudo 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
, orfdk-aac
packages before you start compiling.It is critical that you compile and install
x264
,fdk-aac
,libvpx
andopus
before you buildffmpeg
, as those libraries will be used in the build.Do not forget to add
--enable-opus
to the configure options when you run theffmpeg
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.That's how I do it:
EDIT:
For Audiophiles:
No need to specify
--maxdelay 10
option becauseopusenc
do this by default.Console Output for this file conversion (
--bitrate 320
):It's super fast! Less than 8 seconds with a complexity of 10 (Encoding computational complexity (0-10, default: 10). Zero gives the fastest encodes but lower quality, while 10 gives the highest quality but slower encoding) and a maximum delay time of 10ms (Maximum container delay in milliseconds (0-1000, default: 1000)), so if you skip time in a song, the clipping effect will have a duration of 10ms so it is inperceptible (try with 1000 and hear the difference skipping time with your mouse). Bitrate is VBR by default. 320kbps worked for me so is optional, play with this number:
--bitrate N.nnn
=> Target bitrate in kbit/sec (6-256 per channel)By the way, encoding from MP3 to OPUS is not a good idea, it's not going to sound better, their compression algorithms are way too different. But from FLAC or WAV or any other Lossless Audio Format, that's another story.
Note: To encode another file, just press the Up Arrow in the same terminal to call the last command and change the name of the input and output files.
If you are looking for a ffmpeg/avconv GUI, maybe TraGtor is what you need.
You can also check the spectogram differences between Lossless and Lossy formats at high bitrates with Spek or Audacity.
If only the mp3 to opus route is needed,
mpg123
can do the decoding to wav/pcm.For the unfamiliar the dash "-" functions as stdout on the left to be piped to opusencs stdin on the right.
Of course ffmpeg is excellent for general media conversion and editing, but its install size and usual distribution dependencies also have a bigger footprint.
opus-tools
andAudex
.Open Audex and add a new profile called Opus, add Command pattern;
opusenc $i --comment="TRACKNUMBER="$trackno"" --artist "$artist" --album "$title" --title "$ttitle" --date "$date" --picture "$cover" $o
and suffix
opus