Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Best way to convert lossy codecs to opus (Read 1139 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Best way to convert lossy codecs to opus

I have over 30GB of music in mp3 V0, and while it's apparently not advisable to convert already compressed files to another encoding format.
My goal is to get all of this onto my phone, and to do that I'd like to get opus --bitare 80 audios to take up less storage.

Anyway, I got to the point of wanting to know the best way to convert an already compressed file to opus (and why). Indeed opusenc only takes in input non-compressed formats (like wav or flac).

I found for the moment 2 methods (tell me which one is better, and maybe there are others? ) :

  • Use ffmpeg to convert the mp3 to wav first, then convert the wav file to opus using opusenc
    The corresponding code would look like this (on Linux) :
    Code: [Select]
    ffmpeg -i input.mp3 -f wav - | opusenc --bitrate 80 - output.opus
    Personally, I think I prefer this one because it use opusenc, and as said here ffmpeg and opusenc for opus file have some differences.

  • Only use ffmpeg to convert directly mp3
    The corresponding code would look like this (on Linux) :
    Code: [Select]
    ffmpeg -i input.mp3 -b:a 80k output.opus

I know what I want (I already tested bitrate 80 etc), so please don't answer with : "Ergh, don't do that...".
Any help is welcome :))

Re: Best way to convert lossy codecs to opus

Reply #1
I am too lazy to check whether the former approach will preserve metadata, but if the former doesn't: maybe try flac in place of wav?

Also, if you know very well where you have your files from, this tip is maybe irrelevant for you, but I always tag transcodes and give them double file suffixes or something. So my output file would be filename.mp3.opus, and then I would select all the .mp3.opus files and populate a tag <SOURCE> with "mp3 transcode" or something. That makes it clear for later which files are disposable.
But if all your .opus are transcodes - and you intend to keep it that way - you already know from the suffix.
High Voltage socket-nose-avatar

Re: Best way to convert lossy codecs to opus

Reply #2
You could also consider running foobar2000 via WINE (assuming you're on Linux):  https://snapcraft.io/foobar2000

From there, fb2k could convert easily in a one-step process, handing everything cleanly and automatically behind the scenes.

Re: Best way to convert lossy codecs to opus

Reply #3
All the mp3 files I'm going to convert will be in a same folder, so there is no need to add more information in their file names.
Strangely, using the first approach I lost some tags when I converted via wav, but I have absolutely no loss of metadata with flac.

Just one thing I don't know if I have to worry about : while converting mp3 to opus via flac, ffmpeg prints me the warning "unable to rewrite FLAC header". And if I execute the following command (with same input file), I don't get anymore warning :
Code: [Select]
ffmpeg -i output.mp3 -c:v copy test.flac
What is your opinion on this ?

I can't quite figure out why, but thanks anyway because I think I'll stick with this method - via flac - (I like to use opusenc because it will not change the frequency of input file, unlike ffmpeg using libopus (who always give 48 kHz output file) - and perhaps fb2k, which I don't know much about).

Re: Best way to convert lossy codecs to opus

Reply #4
Semi-qualified hunches coming up:

Strangely, using the first approach I lost some tags when I converted via wav, but I have absolutely no loss of metadata with flac.
Vorbis comments support "pretty much everything" you could have in ID3 metadata, and once the metadata are there in the .flac, you use a xiph application taking a xiph codec with vorbis comments in, and encoding to a xiph codec with vorbis comments. I am not surprised that it works.
On the other hand, .wav tagging isn't that well uniformly standardized

I have not much of an idea about that "unable to rewrite FLAC header", but -c:v copy refers to video codec, so if pressed to guess: album art?
High Voltage socket-nose-avatar

Re: Best way to convert lossy codecs to opus

Reply #5
Yes, I use c:v copy to copy the album art (only) to the output audio file.
Interesting part about the headers (metadata) of flac and wav files. I had no idea that flac was better "defined".
Thank you for your great help, I now know where I need to go :))

Re: Best way to convert lossy codecs to opus

Reply #6
WAV has full tagging, if you abuse the fact that a number of apps support stuffing an entire ID3v2.3 frame into the file as a defined chunk name. Most software doesn't support this, though, so there's also the standard RIFF INFO chunks, which are ANSI encoded, and have limited specific fields.

Whereas FLAC has free form key=value tagging, with a standard describing basic field names that most software should expect standard values to be assigned to, but software should be able to support arbitrary fields as well.

 

Re: Best way to convert lossy codecs to opus

Reply #7
Good thing is your V0 (245kbps) is already more than good enough lossy bitrate. so considering your converting from MP3 @ V0 to Opus @ 80kbps your converted files will still be good enough I am sure.

I do all of my conversion using Foobar2000 with Encoders Pack installed. this will especially be easy to do if your music is not all that organized as the easiest thing to do would be to drag-and-drop all of your V0 MP3's into Foobar2000 then select all of them (so they are highlighted in blue color) and then 'right click > Convert' (tweak things to your liking), then select destination folder, and just sit back and wait and they will all be in the same folder as this process won't take all that long unless you got a boatload of music. but even then, it will still be quick enough especially if your CPU is a quad core (or at least a faster dual core CPU) or better.

but if you got music organized a bit into folders (like with artists and albums) and your MP3 tag data is setup well, you can do something like the following...

'Convert > ... > Destination' (and obviously, select Opus here on Converter Setup > Output Format (may need to select EDIT and adjust bit rate to 80kbps which is easy enough to do))). then on window that appears (Converter Setup) on the 'Output style and file name formatting' section, of which the 'Convert each track to an individual file' will already be selected, you simply select the small '...' on the right side of the white section with text in it below (you click the '...') which will bring up the 'File Name Pattern Selector' and from here it can make things easier to organize stuff properly as this is mainly helpful if you got a certain artist with full albums as then you might select "artist - album (year)" on the left side and I typically use "nn. title" on the right side. either way, I tend to have my presets setup so it at the least uses "nn. title" as then tracks will be listed a bit better in the sense instead of say "Track Title.mp3" it will be "01. Track Title.mp3" (assuming your tag data of the files your converting is setup decently with track numbering in tag data).

but that should get the gist of it across ;) (NOTE: I am assuming since your using MP3 it's probably standard 44.1/16. if not one can tweak that stuff with SoX Resampler etc (one has to install SoX but there might be other options already installed(?)). but the resampler stuff is done though 'Converter Setup > Processing' section. but if a person is using standard 44.1/16 lossless files when they made those MP3 files to begin with, things should be pretty standard and you likely won't have to mess with resampling)

p.s. while I imagine the OP probably already sorted things out, I figured I would make this post as it could be beneficial for others in a similar situation in the future to keep things simple enough.
For music I suggest (using Foobar2000)...
1)Opus @ 64kbps or 96kbps. NOTE: using 64kbps on Samsung J3 /w Foobar2k.
2)AAC (Apple or FhG(Winamp)) @ 96kbps.
3)MP3 (LAME) @ V5 (130kbps). NOTE: using on AGPTEK-U3 as of Mar 18th 2021. I use 'fatsort' (on Linux) so MP3's are listed in order on AGPTEK-U3.

 
SimplePortal 1.0.0 RC1 © 2008-2021