Opened 3 months ago

Last modified 2 months ago

#11138 new defect

FFmpeg audio dither creates unwanted DC offset

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 (6)

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

Download all attachments as: .zip

Change History (9)

by mstgrv, 3 months ago

Attachment: silence 44-32.png added

by mstgrv, 3 months ago

Attachment: ffmpeg.png added

by mstgrv, 3 months ago

Attachment: rx.png added

by mstgrv, 3 months ago

Attachment: audio files.zip added

comment:1 by mstgrv, 3 months 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 3 months ago by mstgrv (previous) (diff)

comment:2 by Balling, 3 months 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 months ago

Cc: MasterQuestionable added
Component: undeterminedswresample
Keywords: dither added; audio dithering removed

͏    "-dither_method triangular"
͏    Does it happen with other methods?
͏    Or the default..?? 0?

Version 0, edited 2 months ago by MasterQuestionable (next)

by MasterQuestionable, 2 months ago

Attachment: wavestat.webp added

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

by MasterQuestionable, 2 months ago

Attachment: wav.7z added

͏    Your files can be deleted.

Note: See TracTickets for help on using tickets.