HydrogenAudio

Lossy Audio Compression => Opus => Topic started by: channel on 2021-04-30 04:05:30

Title: Critique my ffmpeg pipe for opus encode
Post by: channel on 2021-04-30 04:05:30
I am trying to convert my music library to opus for portable listening. I want to use ffmpeg to create WAVs that are piped to an opus encoder. input files are flac.

files are mostly 44KHz with some at 48, 96, 192. I don't care about high sample rates that's just the format they're in. should i resample in ffmpeg or pass them directly to opus encoder? I know internally they're all 48khz in opus. my thought is that since higher sample rates can make things sound worse, downsample to 48 or 44. but does this matter since opus isn't "really" above 48khz?

same thing with bit depth, downsample to 16 or pass 24 to opus? I don't care about keeping high bit depth.

is there a benefit to tailoring the command to the content? (ex. downsample 96 to 48, 92 to 41). if I resample everything to 48 in ffmpeg before sending it to opus, does that change anything?

Is precision 28 fine or is there any benefit to 31/max?

output is stereo.

Code: [Select]
ffmpeg -i "$source" -ac 2 -acodec pcm_s16le -rf64 auto -af "aresample=44100:resampler=soxr:precision=28:osf=s16:dither_method=shibata" - |
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: kode54 on 2021-04-30 08:03:54
Why are you converting to 16 bit, or resampling to 44100? Opus will convert it to float anyway, and will resample it to 48000. Opus tools will accept float 32.
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: channel on 2021-04-30 15:41:38
I didn't want to pointlessly upsample my music. So since most is 16/44, I set that as the output. Would upsampling make the quality worse?

Ideally, I'll have one command for all my FLACs, but if I have to make one for CD-quality and one for above-CD, I can probably make that work. I'm using beets (music library manager) and its convert plugin, which generally takes one command.

I saw some arguments about dithering but I couldn't get my head around it. "FFmpeg doesn't dither by default". Is that a problem? Does opus dither? Looks like it's opinion:

https://wiki.hydrogenaud.io/index.php?title=Dither
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: Makaki on 2021-04-30 15:50:21
Why use ffmpeg at all? opus tools has everything you need.

And if you are going to use ffmpeg, why pipe to an opus encoder? I believe ffmpeg can be compiled with libopus support.
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: channel on 2021-04-30 16:00:29
Why use ffmpeg at all? opus tools has everything you need.

And if you are going to use ffmpeg, why pipe to an opus encoder? I believe ffmpeg can be compiled with libopus support.

Good question. I want to pipe to this opus encoder for gapless support:
I didn't see anyone else using libopusenc for gapless encoding, so I did it myself.

Source code and usage instructions here. (https://github.com/Octocontrabass/opusgap)

I like keeping things simple and the Unix philosophy. Many small tools that do one thing well. I know ffmpeg can handle any audio format I throw at it. And I know most Opus encoders can handle raw wave.
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: Rollin on 2021-04-30 16:12:17
Code: [Select]
ffmpeg -i "$source" -ac 2 -c:a pcm_f32le -rf64 auto -af "aresample=48000:resampler=soxr:precision=28" -f wav -|
Resample to 48000. Opus will resample everything to 48000 anyway.
Use 32 bit floating point to avoid unnecessary clipping.
No dither.

I want to pipe to this opus encoder for gapless support:
The tool, you are referring to ( https://github.com/Octocontrabass/opusgap ) can't take pipe input. It is designed to convert group of wav files to opus at once. And this is needed to get perfect gaplessness. So it seems that what you are trying to do is pointless.
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: zezao on 2021-04-30 23:55:19
Why not use Foobar2000 converter + SoX DSP Resampler? http://www.saunalahti.fi/~cse/Opus/
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: Octocontrabass on 2021-05-01 02:07:07
I want to pipe to this opus encoder for gapless support:
There are three problems.

The first problem, already mentioned, is that my encoder frontend does not support pipe input. It's meant to encode entire albums at once, and it does that by taking a list of WAV files to encode.

The second problem is that, if you resample each file separately, you may introduce gaps at the file boundaries. You don't need to resample at all, since libopusenc includes a resampler.

The third problem is that my encoder frontend doesn't support very many different WAV formats. I've only tried it with CD audio, so it might not work for all of your files. I can add support for different WAV formats if you provide sample files, but it might take me a while!

Why not use Foobar2000 converter + SoX DSP Resampler?
That way isn't guaranteed to be gapless.
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: channel on 2021-05-01 18:39:57
There are three problems.
Appreciated. I should be able to put something together in Python that provides files in the way your tool is expecting.
Title: Re: Critique my ffmpeg pipe for opus encode
Post by: lozenge on 2021-05-05 00:54:17
You might consider using CAF as the intermediate format instead of WAV for better support for metadata (tags etc) which ffmpeg will copy over, but will break when using WAV.
SimplePortal 1.0.0 RC1 © 2008-2021