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

MrD*_*Coy 49 audio vlc-media-player encoding ffmpeg

Opus 音频编解码器看起来是迄今为止压缩音频的最佳编解码器。它最近在最新的 ffmpeg 和 VLC 播放器中得到支持。但是,我找不到有关如何使用它实际编码媒体的文档。有人可以将我引导到上述文档,最好详细说明 ffmpeg 标志和用法吗?我有很多有声读物占用了太多空间,Opus 看起来是保存它们的完美格式。

小智 54

ffmpeg -i <input> -c:a libopus -b:a bitrate <output>
Run Code Online (Sandbox Code Playgroud)

比特率可以-b:a 96K为 96 kBit/s。

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

确保你编译了 ffmpeg --enable-libopus

  • 这对我有帮助。注意,`vbr on` 和 `compression_level 10` 是默认值,可以省略。https://ffmpeg.org/ffmpeg-codecs.html#Option-Mapping (7认同)
  • 实际上,这些是默认值,在大多数情况下不必修改它们。另外,请注意比特率以比特/秒为单位,而不是通常的千比特/秒。默认比特率是 96000(96 kbits/s),这是(当然可以说)一个很好的值。总结的示例命令:`ffmpeg -i input.flac -acodec libopus -b:a 128000 output.opus` (2认同)
  • @MinhNghĩa https://en.wikipedia.org/wiki/Variable_bitrate 你用 `q` 描述的是 `fixed quality` 模式。我正在描述我认为 libopus 在这里使用的“平均比特率”。它们都是 `vbr` 的形式。显然在这个答案中我们没有定义 `q` 值,因此它不能使用 `fixed quality` 模式。我什至在 http://ffmpeg.org/ffmpeg-codecs.html#libopus-1 上根本看不到 libopus 可以在“固定质量”模式下运行。您一定在考虑使用不同的编解码器。 (2认同)

小智 15

  1. 下载Opus-tools

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

  3. 解码:(在任何媒体播放器中播放,如果您的媒体播放器不支持 opus 则很有用):
    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
Run Code Online (Sandbox Code Playgroud)

  • @nakedhitman `--vbr` 选项是默认的。请参阅 opusenc 的手册页。您也可以使用 ffmpeg 进行编码,但需要在安装 [libopus](http://www.opus-codec.org/downloads/) 后使用 `--enable-libopus` 进行编译。 (2认同)