How to convert an MP3 file to an Ogg Opus file?
Asked Answered
D

2

8

Is there a converter that can convert MP3 files to Ogg Opus?

Can you recommend one that can do it?

So far I've tried Adobe Audition, Xilisoft Audio Converter Pro, WinAVI Video Converter, and Aimersoft Video Converter Pro. None of them was useful.

Duality answered 4/7, 2016 at 13:10 Comment(0)
G
30

The easiest option is a command like this

ffmpeg -i input.mp3 -c:a libopus output.opus

But there is a selection of parameters you can tweak, all documented here.

E.g. I use the following command to compress audiobooks/podcasts (the resulting ~32 kbps OPUS files sound indistinguishable from 192 kbps MP3):

ffmpeg -i input.mp3 -c:a libopus -b:a 32k -vbr on -compression_level 10 -frame_duration 60 -application voip output.opus
  • -b:a 32k sets bitrate to 32 kbps (or about 35 kbps in case of VBR), it can be reasonable to use 128k to compress music given a lossless (or a 320k MP3) original or 64k to compress music given a 192k MP3 original
  • -vbr on turns variable bitrate mode on (may increase quality at cost of a using some additional kbits for some seconds)
  • -compression_level 10 commands to favour quality over compression speed
  • -frame_duration 60 increases quality at cost of 40 additional milliseconds of latency
  • -application voip asks to do the best possible to save speech intelligibility, use -application audio for music

You can convert a set of many files this way in bash:

for f in *.mp3; do ffmpeg -i "$f" -c:a libopus "${f%.*}.opus"; done
Goode answered 7/3, 2018 at 0:7 Comment(1)
vbr is on by default, so you don't have to add it.Goodhumored
W
9

Convert MP3 files in all subfolders recursively and utilizing all CPU

NOTE: FFmpeg multithread -thread n argument is ignored when encoding OPUS files.

Preparing

Install GNU parallel, FFmpeg, and MP3 with Opus codecs

sudo apt install -y parallel ffmpeg libmp3lame libopus

Usage

Recursive and using all CPUs:

  • find -iname "*.mp3" -type f Find all MP3 files in whole directory
  • parallel -I% --max-args 1 Prepare parallel to use % char as argument for file path saving
  • -c:a opus Set OPUS as encoder
  • -strict -2 Enable FFmpeg to work with OPUS encoder
  • -b:a 128K -vbr on Set OPUS at 128 KB/s (VBR) that is enough to store stereo music
  • -map_metadata 0 Copy tags from MP3 to OPUS file
  • -compression_level 10 Favour quality over compression speed
  • -y Overwrite OPUS file if already exists
  • touch -r % %.opus Use MP3 file's times instead of newly created files
  • rm -vf % Remove MP3 file
find -iname "*.mp3" -type f | parallel -I% --max-args 1  \
  "ffmpeg -i % -strict -2 -c:a opus -b:a 128K -vbr on -map_metadata 0 -compression_level 10 -y %.opus;touch -r % %.opus;rm -vf %"

NOTE: Don't use -frame_duration argument for mixing audio purposes

Workingman answered 3/4, 2021 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.