Opened 2 years ago
Last modified 3 months ago
#11138 reopened defect
FFmpeg audio dither creates unwanted DC offset on Mac
| Reported by: | mstgrv | Owned by: | |
|---|---|---|---|
| Priority: | normal | Component: | swresample |
| Version: | 7.0 | Keywords: | dither |
| Cc: | MasterQuestionable | Blocked By: | |
| Blocking: | Reproduced by developer: | no | |
| Analyzed by developer: | no |
Description
I ran a test of FFmpeg's audio dithering and I noticed that it creates a DC offset in the resulting audio file, which shouldn't be there. Doing the same dithering process with other tools produces no DC offset in the resulting audio.
Here's what I did:
- Create a silent WAV file (44.1khz, 32-bit floating point) using iZotope RX.
- Convert that file to 16-bit with triangular dither, using iZotope RX
- Convert the same file to 16-bit with triangular dither, using FFmpeg. The command I used was:
ffmpeg -i input.wav -c:a pcm_s16le -dither_method triangular output.wav
Because the file in step 1 is completely silent, the files created in steps 2 & 3 contain just the dither by itself.
FFmpeg's conversion results in a file with DC offset, but iZotope RX's conversion has none. The expected result is no DC offset.
I have attached all the WAV files, plus screenshots of the analysis of each file (using iZotope RX) which shows the DC offset result.
Attachments (8)
Change History (18)
by , 2 years ago
| Attachment: | silence 44-32.png added |
|---|
by , 2 years ago
| Attachment: | ffmpeg.png added |
|---|
by , 2 years ago
by , 2 years ago
| Attachment: | audio files.zip added |
|---|
comment:2 by , 2 years ago
Paul that worked on this moved to his own fork of ffmpeg. Open the issue there.
comment:3 by , 2 years ago
| Cc: | added |
|---|---|
| Component: | undetermined → swresample |
| Keywords: | dither added; audio dithering removed |
͏ Did.
͏ Potential rounding error of "swresample"
͏ https://github.com/librempeg/librempeg/issues/11
͏ ----
͏ "-dither_method triangular"
͏ Does it happen with other methods?
͏ Or the default..?? 0?
comment:4 by , 19 months ago
Found it, and looks related to our code. https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/2040
And this literally about dither
https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4057
comment:5 by , 4 months ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Well, this is fixed now. There is no DC offset anymore with iZotope RX Alt+D menu. Even on triangular_hp dither.
follow-up: 7 comment:6 by , 4 months ago
Thank you - has the fix been released? Just trying this again with v8.1.2 and I still see DC offset
comment:7 by , 4 months ago
Replying to mstgrv:
Thank you - has the fix been released? Just trying this again with v8.1.2 and I still see DC offset
ffmpeg -i "silence 44-32.wav" -c:a pcm_s16le -dither_method triangular output.wav
produces this file that has no DC offset in iZotope RX 12.
But you can test latest master branch Windows build here: https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip
by , 4 months ago
| Attachment: | outputnodcoffset.zip added |
|---|
follow-up: 9 comment:8 by , 4 months ago
Wait, I actually cannot see any DC offset on 8.1.2... Weird, maybe it is some CPU issue?
comment:9 by , 3 months ago
Replying to Balling:
Wait, I actually cannot see any DC offset on 8.1.2... Weird, maybe it is some CPU issue?
I'm on a Mac, if that helps track it down?
Mac M4 Pro
macOS Tahoe 26.5.2
FFmpeg 8.1.2 installed via homebrew
Just retried it again and confirming I still get the DC offset when I check in RX
by , 3 months ago
| Attachment: | output.wav.zip added |
|---|
comment:10 by , 3 months ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
| Summary: | FFmpeg audio dither creates unwanted DC offset → FFmpeg audio dither creates unwanted DC offset on Mac |
Yes, I never checked this originally, as I thought Paul reproduced it. But it is only in ARM. Linux x86 not affected either.




A similar bug existed in Reaper, which was fixed in 2021 https://forum.cockos.com/showpost.php?p=2425940&postcount=25
The developer clarified what the issue was and how it was fixed https://forum.cockos.com/showpost.php?p=2801990&postcount=33
The bug (fixed in v6.27) was using floor() instead of rounding when reducing floating point samples to the desired bit depth. For example if you have a variable in [-1,1] with mean=0, floor(x) will have a mean of -0.5, but floor(x+0.5) will have a mean of 0.
Perhaps this could be the fix for the issue in FFmpeg?