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:

  1. Create a silent WAV file (44.1khz, 32-bit floating point) using iZotope RX.
  2. Convert that file to 16-bit with triangular dither, using iZotope RX
  3. 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)

silence 44-32.png​ (324.8 KB ) - added by mstgrv 2 years ago.
ffmpeg.png​ (325.1 KB ) - added by mstgrv 2 years ago.
rx.png​ (325.4 KB ) - added by mstgrv 2 years ago.
audio files.zip​ (445.3 KB ) - added by mstgrv 2 years ago.
wavestat.webp​ (109.1 KB ) - added by MasterQuestionable 2 years ago.
[[Image(...)]]
wav.7z​ (266.6 KB ) - added by MasterQuestionable 2 years ago.
͏    Your files can be deleted.
outputnodcoffset.zip​ (260.4 KB ) - added by Balling 4 months ago.
output.wav.zip​ (235.8 KB ) - added by mstgrv 3 months ago.

Change History (18)

by mstgrv, 2 years ago

Attachment: silence 44-32.png​ added

by mstgrv, 2 years ago

Attachment: ffmpeg.png​ added

by mstgrv, 2 years ago

Attachment: rx.png​ added

by mstgrv, 2 years ago

Attachment: audio files.zip​ added

comment:1 by mstgrv, 2 years ago

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?

Last edited 2 years ago by mstgrv (previous) (diff)

comment:2 by Balling, 2 years ago

Paul that worked on this moved to his own fork of ffmpeg. Open the issue there.

​https://github.com/librempeg/librempeg

comment:3 by MasterQuestionable, 2 years ago

Cc: MasterQuestionable 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?

Last edited 2 years ago by MasterQuestionable (previous) (diff)

by MasterQuestionable, 2 years ago

Attachment: wavestat.webp​ added

https://trac.ffmpeg.org/raw-attachment/ticket/11138/wavestat.webp

by MasterQuestionable, 2 years ago

Attachment: wav.7z​ added

͏    Your files can be deleted.

comment:5 by Balling, 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.

Last edited 4 months ago by Balling (previous) (diff)

comment:6 by mstgrv, 4 months ago

Thank you - has the fix been released? Just trying this again with v8.1.2 and I still see DC offset

in reply to:  6 comment:7 by Balling, 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 Balling, 4 months ago

Attachment: outputnodcoffset.zip​ added

comment:8 by Balling, 4 months ago

Wait, I actually cannot see any DC offset on 8.1.2... Weird, maybe it is some CPU issue?

in reply to:  8 comment:9 by mstgrv, 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 mstgrv, 3 months ago

Attachment: output.wav.zip​ added

comment:10 by Balling, 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.

Note: See TracTickets for help on using tickets.