如何使用Opus编解码器编码音频?


30

Opus音频编解码器看起来是有史以来压缩音频最好的东西。最近,最新的ffmpeg和VLC播放器已支持它。但是,没有关于如何使用它实际编码媒体的文档。有人可以将我定向到所说的文档,最好是带有ffmpeg标志和用法的细节吗?我有很多有声读物占用太多空间,而Opus看起来是保留它们的理想格式。


1
您没有提及您的操作系统。
llogan

Answers:


39
ffmpeg -i <input> -c:a libopus -b:a bitrate <output>

可以像-b:a 96K96 kBit / s 一样给出比特率。

ffmpeg的文件有选择和描述libopus列表。在这里您可以设置-vbr选项或其他-compression_level

确保使用ffmpeg编译--enable-libopus


这很棒!我已经弄清楚了如何使用ffmpeg进行编码,但是对-vbr和--compression_level标志一无所知。这正是我想要的!
MrDrMcCoy 2013年

6
这对我有帮助。注意,vbr on并且compression_level 10是默认值,可以省略。 ffmpeg.org/ffmpeg-codecs.html#Option-Mapping
Joshua Huber

1
实际上,这些是默认值,在大多数情况下,无需修改它们。另外,请注意,比特率以位/秒为单位,而不是通常的千位/秒。默认比特率是96000(96 kbits / s),(当然可以说)是一个很好的值。总结的示例命令:ffmpeg -i input.flac -acodec libopus -b:a 128000 output.opus
Gras Double

这是使用'application'参数的方法-application voip。作为ffmpeg的新用户,我努力寻找合适的语法。
tuxayo

15
  1. 下载Opus工具

  2. 编码:
    opusenc --bitrate 64 What_A_Feeling.wav What_A_Feeling_64.opus

  3. 解码:(可在任何媒体播放器中播放,如果您的媒体播放器尚不支持作品,则很有用):
    opusdec What_A_Feeling_64.opus What_A_Feeling_opus64.wav

(What_A_Feeling是一首歌的名字)

单独运行时显示的详细选项opusenc

Usage: opusenc [options] input_file output_file.opus

Encodes input_file using Opus.
It can read the WAV, AIFF, FLAC, Ogg/FLAC, or raw files.

General options:
 -h, --help         This help
 -V, --version      Version information
 --quiet            Quiet mode

input_file can be:
  filename.wav      file
  -                 stdin

output_file can be:
  filename.opus     compressed file
  -                 stdout

Encoding options:
 --bitrate n.nnn    Target bitrate in kbit/sec (6-256/channel)
 --vbr              Use variable bitrate encoding (default)
 --cvbr             Use constrained variable bitrate encoding
 --hard-cbr         Use hard constant bitrate encoding
 --comp n           Encoding complexity (0-10, default: 10 (slowest))
 --framesize n      Maximum frame size in milliseconds
                      (2.5, 5, 10, 20, 40, 60, default: 20)
 --expect-loss      Percentage packet loss to expect (default: 0)
 --downmix-mono     Downmix to mono
 --downmix-stereo   Downmix to stereo (if >2 channels)
 --max-delay n      Maximum container delay in milliseconds
                      (0-1000, default: 1000)

Diagnostic options:
 --serial n         Forces a specific stream serial number
 --save-range file  Saves check values for every frame to a file
 --set-ctl-int x=y  Pass the encoder control x with value y (advanced)
                      Preface with s: to direct the ctl to multistream s
                      This may be used multiple times

Metadata options:
 --comment          Add the given string as an extra comment
                      This may be used multiple times
 --artist           Author of this track
 --title            Title for this track
 --album            Album or collection this track belongs to
 --date             Date for this track
 --genre            Genre for this track
 --picture          Album art for this track
                      More than one --picture option can be specified.
                      Either a FILENAME for the picture file or a more
                      complete SPECIFICATION form can be used. The
                      SPECIFICATION is a string whose parts are
                      separated by | (pipe) characters. Some parts may
                      be left empty to invoke default values. A
                      FILENAME is just shorthand for "||||FILENAME".
                      The format of SPECIFICATION is

                      [TYPE]|[MIME-TYPE]|[DESCRIPTION]|[WIDTHxHEIGHT
                      xDEPTH[/COLORS]]|FILENAME

                      TYPE is an optional number from one of:
                      0: Other
                      1: 32x32 pixel 'file icon' (PNG only)
                      2: Other file icon
                      3: Cover (front)
                      4: Cover (back)
                      5: Leaflet page
                      6: Media (e.g., label side of a CD)
                      7: Lead artist/lead performer/soloist
                      8: Artist/performer
                      9: Conductor
                      10: Band/Orchestra
                      11: Composer
                      12: Lyricist/text writer
                      13: Recording location
                      14: During recording
                      15: During performance
                      16: Movie/video screen capture
                      17: A bright colored fish
                      18: Illustration
                      19: Band/artist logotype
                      20: Publisher/studio logotype

                      The default is 3 (front cover). There may only be
                      one picture each of type 1 and 2 in a file.

                      MIME-TYPE is optional. If left blank, it will be
                      detected from the file. For best compatibility
                      with players, use pictures with a MIME-TYPE of
                      image/jpeg or image/png. The MIME-TYPE can also
                      be --> to mean that FILENAME is actually a URL to
                      an image, though this use is discouraged. The
                      file at the URL will not be fetched. The URL
                      itself is stored in the metadata.

                      DESCRIPTION is optional. The default is an empty
                      string.

                      The next part specifies the resolution and color
                      information. If the MIME-TYPE is image/jpeg,
                      image/png, or image/gif, you can usually leave
                      this empty and they can be detected from the
                      file. Otherwise, you must specify the width in
                      pixels, height in pixels, and color depth in
                      bits-per-pixel. If the image has indexed colors
                      you should also specify the number of colors
                      used. If possible, these are checked against the
                      file for accuracy.

                      FILENAME is the path to the picture file to be
                      imported, or the URL if the MIME-TYPE is -->.
 --padding n        Extra bytes to reserve for metadata (default: 512)
 --discard-comments Don't keep metadata when transcoding
 --discard-pictures Don't keep pictures when transcoding

Input options:
 --raw              Raw input
 --raw-bits n       Set bits/sample for raw input (default: 16)
 --raw-rate n       Set sampling rate for raw input (default: 48000)
 --raw-chan n       Set number of channels for raw input (default: 2)
 --raw-endianness n 1 for bigendian, 0 for little (defaults to 0)
 --ignorelength     Always ignore the datalength in Wave headers

谢谢,但是我希望有一些更详细的信息。有可变比特率选项吗?我还可以传递其他哪些标志来优化音频流?
MrDrMcCoy 2012年

1
@nakedhitman该--vbr选项是默认选项。有关opusenc的信息,请参见手册页。您还可以使用ffmpeg进行编码,但是--enable-libopus在安装libopus之后需要使用ffmpeg对其进行编译。
llogan

为了获得一个想法(不用于批量转换),像这样的在线版本可能会有所帮助。如果计划转换整个集合,则opusinfo(也是的一部分opus-tools)可能会告诉您所选的编码工具是否运行良好。
Rainer Rillke

3

DOS / Windows命令中最好的Opus编解码器命令是:

对于lib 1.3,最小的文件大小(磁带质量):

Opusenc a.wav a.opus --bitrate 24 --framesize 40 --discard-comments --discard-pictures

你会:

a-在24kbit时仍具有16kHz(32kHz立体声)声音输出,尺寸非常小。较小的音速输出将降至11kHz

b-增加帧大小(节省几位数据(大约6%),而不会造成质量损失)

c-丢弃不必要的TAG信息,并覆盖只会扩大文件大小的图片。

对于lib 1.3,流式传输(接近CD质量)使用'--bitrate 52'而不是'24'。

1.2中的默认值是48kbit,但是1.3中使用52,并且“ framesize”设置为40,则文件大小是相等的,但是可听见的伪像少得多。

帧大小为40的52 kbit的质量可以说等于160kbit MP3,其大小不到其三分之一。而1.2的48kbit等于128kbit的MP3,或仅小2.5倍。

为了获得几乎相同的质量,您将需要80到96kbits。我几乎不使用它,因为我希望音频尽可能小。

超过96kbit的音频仅适用于编辑,并且听不见原始文件和Opus编码文件之间的区别。

话虽这么说,我还不知道它在Linux中如何工作。


在linux和Windows上尝试该操作时出现错误:Unrecognized option '-framesize'. Error splitting the argument list: Option not found。ffmpeg版本是4.0.2
sukhmel
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.