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: Critique my ffmpeg pipe for opus encode (Read 3933 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Critique my ffmpeg pipe for opus encode

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" - |

Re: Critique my ffmpeg pipe for opus encode

Reply #1
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.

Re: Critique my ffmpeg pipe for opus encode

Reply #2
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

Re: Critique my ffmpeg pipe for opus encode

Reply #3
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.

Re: Critique my ffmpeg pipe for opus encode

Reply #4
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.

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.

Re: Critique my ffmpeg pipe for opus encode

Reply #5
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.


Re: Critique my ffmpeg pipe for opus encode

Reply #7
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.


 

Re: Critique my ffmpeg pipe for opus encode

Reply #9
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.