Opened 20 months ago

Closed 5 months ago

Last modified 5 months ago

#9297 closed defect (fixed)

Decoded flac file ends up sounding distorted

Reported by: Mattias Wadman Owned by:
Priority: important Component: avcodec
Version: git-master Keywords: flac regression
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug:

flac_decode_bug.flac is a flac file with the first flac frame extracted from a longer file that I unfortunately can't share. Metadata suggest it was encoded using "reference libFLAC 1.2.1 20070917".

Some debugging findings:
Most diffing samples are reference decoded 0xffff vs ffmpeg 0x7fff

Some residual samples are quite large 65535 and -65535.

If I change "int need32 = s->flac_stream_info.bps > 16" to "int need32 = s->flac_stream_info.bps >= 16" in flac_set_bps it seems to decode fine.

How to reproduce:

$ ls -l flac_decode_bug.flac
-rw-r--r-- 1 root root 12329 Jun 21 10:19 flac_decode_bug.flac
$ flac -t flac_decode_bug.flac

flac 1.3.3
Copyright (C) 2000-2009  Josh Coalson, 2011-2016  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

flac_decode_bug.flac: ok
$ flac -d -o flac_decode_bug.flac.ref.wav flac_decode_bug.flac

flac 1.3.3
Copyright (C) 2000-2009  Josh Coalson, 2011-2016  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

flac_decode_bug.flac: done

$ ./ffmpeg_g -i flac_decode_bug.flac flac_decode_bug.flac.ffmpeg.wav
ffmpeg version N-102781-g05f9b3a0a5 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.1 (Alpine 10.2.1_pre1) 20201203
  configuration: --enable-debug --disable-optimizations
  libavutil      57.  0.100 / 57.  0.100
  libavcodec     59.  1.102 / 59.  1.102
  libavformat    59.  3.101 / 59.  3.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  0.102 /  8.  0.102
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
Input #0, flac, from 'flac_decode_bug.flac':
  Duration: 00:00:00.09, bitrate: 1061 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to 'flac_decode_bug.flac.ffmpeg.wav':
  Metadata:
    ISFT            : Lavf59.3.101
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.1.102 pcm_s16le
size=      16kB time=00:00:00.09 bitrate=1417.9kbits/s speed=11.8x
video:0kB audio:16kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.476074%

$ ./ffmpeg_with_fix_g -i flac_decode_bug.flac flac_decode_bug.flac.ffmpeg_with_fix.wav
ffmpeg version N-102781-g05f9b3a0a5 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.1 (Alpine 10.2.1_pre1) 20201203
  configuration: --enable-debug --disable-optimizations
  libavutil      57.  0.100 / 57.  0.100
  libavcodec     59.  1.102 / 59.  1.102
  libavformat    59.  3.101 / 59.  3.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  0.102 /  8.  0.102
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
Input #0, flac, from 'flac_decode_bug.flac':
  Duration: 00:00:00.09, bitrate: 1061 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s32 (16 bit)
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to 'flac_decode_bug.flac.ffmpeg_with_fix.wav':
  Metadata:
    ISFT            : Lavf59.3.101
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.1.102 pcm_s16le
size=      16kB time=00:00:00.09 bitrate=1417.9kbits/s speed=18.3x
video:0kB audio:16kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.476074%

$ ./ffmpeg_g -i flac_decode_bug.flac.ref.wav -f s16le flac_decode_bug.flac.ref.wav.pcm
$ ./ffmpeg_g -i flac_decode_bug.flac.ffmpeg.wav -f s16le flac_decode_bug.flac.ffmpeg.wav.pcm
$ ./ffmpeg_g -i flac_decode_bug.flac.ffmpeg_with_fix.wav -f s16le flac_decode_bug.flac.ffmpeg_with_fix.wav.pcm

$ md5sum *.pcm
d1076c476bcd12c1d6944d0e19c60000  flac_decode_bug.flac.ffmpeg.wav.pcm
e5ca6f718f932e3a95461bd7dc690829  flac_decode_bug.flac.ffmpeg_with_fix.wav.pcm
e5ca6f718f932e3a95461bd7dc690829  flac_decode_bug.flac.ref.wav.pcm

Attachments (1)

flac_decode_bug.flac (12.0 KB ) - added by Mattias Wadman 20 months ago.

Download all attachments as: .zip

Change History (6)

by Mattias Wadman, 20 months ago

Attachment: flac_decode_bug.flac added

comment:1 by Carl Eugen Hoyos, 20 months ago

Component: undeterminedavcodec
Keywords: regression added
Priority: normalimportant
Reproduced by developer: set
Status: newopen

Regression since 3cec54b7d72bc594b28faa7b8fb6683ef397fe66 (on SSE2 systems)

comment:2 by Mattias Wadman, 20 months ago

Thanks, the longer file decodes to correct md5 sum using ffmpeg master with SSE2 disabled.

comment:3 by Balling, 5 months ago

Will be fixed by https://patchwork.ffmpeg.org/project/ffmpeg/patch/CAPYw7P4HsGHG_ys1gmJiXUzqWjkKHM8k4nYdnX5k50NuU86QnA@mail.gmail.com/

What is up with Carl and Paul using a new way of sending email that is not accepted by patchwork?

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

comment:4 by Elon Musk, 5 months ago

Resolution: fixed
Status: openclosed

comment:5 by Mattias Wadman, 5 months ago

Thanks!

Note: See TracTickets for help on using tickets.