Opened 11 years ago

Closed 11 years ago

#2497 closed defect (fixed)

ALAC encoder produces invalid output / is not lossless

Reported by: Leigh Dyer Owned by:
Priority: important Component: avcodec
Version: git-master Keywords: alac
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Hi,

I have a particular WAV file that, when converted to ALAC, contains a short burst of noise not present in the original WAV. This is clearly audible, and also clearly visible when comparing the original WAV to the ALAC in a tool like Audacity. The burst of noise is between the 1:14 and 1:15 mark.

I've reproduced this using ffmpeg from git compiled earlier today. The command line was as follows:

ffmpeg -y -i alac_encoding_error_white_noise_burst.wav -acodec alac -f ipod out.m4a

Output was as follows:

ffmpeg version N-52419-gdfdee6c Copyright (c) 2000-2013 the FFmpeg developers
  built on Apr 24 2013 09:52:56 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
  configuration: 
  libavutil      52. 27.100 / 52. 27.100
  libavcodec     55.  6.100 / 55.  6.100
  libavformat    55.  3.100 / 55.  3.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 60.101 /  3. 60.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
[wav @ 0x27b07c0] max_analyze_duration 5000000 reached at 5015510 microseconds
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, wav, from 'alac_encoding_error_white_noise_burst.wav':
  Duration: 00:05:46.91, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Output #0, ipod, to 'out.m4a':
  Metadata:
    encoder         : Lavf55.3.100
    Stream #0:0: Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s16p, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le -> alac)
Press [q] to stop, [?] for help
size=   51784kB time=00:05:46.99 bitrate=1222.5kbits/s    
video:0kB audio:51768kB subtitle:0 global headers:0kB muxing overhead 0.030579%

I can supply the WAV file, but it's copyright belongs to the user that uploaded it to our service, so I wouldn't feel comfortable uploading it to datafilehost.com unless I can supply the link to the relevant developer privately.

I did try to upload it to the FTP server, but had no luck there (there was no "incoming" directory, and I got a permission denied error trying to upload to the root directory).

Attachments (1)

alac_encoding_error_white_noise_burst.raw (52.0 KB ) - added by Carl Eugen Hoyos 11 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Carl Eugen Hoyos, 11 years ago

You can use http://streams.videolan.org/upload/
Please add a txt file that the sample is private.

comment:2 by Leigh Dyer, 11 years ago

Thanks, I've just uploaded the WAV file and a matching text file to that site.

by Carl Eugen Hoyos, 11 years ago

comment:3 by Carl Eugen Hoyos, 11 years ago

Reproduced by developer: set
Status: newopen
$ ffmpeg -f s16le -ac 2 -i alac_encoding_error_white_noise_burst.raw -acodec alac out.mov -f crc -
ffmpeg version N-52413-gad56535 Copyright (c) 2000-2013 the FFmpeg developers
  built on Apr 23 2013 16:00:56 with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl --disable-indev=jack
  libavutil      52. 27.100 / 52. 27.100
  libavcodec     55.  6.100 / 55.  6.100
  libavformat    55.  3.100 / 55.  3.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 60.101 /  3. 60.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
[s16le @ 0x1957fe0] Estimating duration from bitrate, this may be inaccurate
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, s16le, from 'alac_encoding_error_white_noise_burst.raw':
  Duration: 00:00:00.30, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Output #0, mov, to 'out.mov':
  Metadata:
    encoder         : Lavf55.3.100
    Stream #0:0: Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s16p, 128 kb/s
Output #1, crc, to 'pipe:':
  Metadata:
    encoder         : Lavf55.3.100
    Stream #1:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le -> alac)
  Stream #0:0 -> #1:0 (pcm_s16le -> pcm_s16le)
Press [q] to stop, [?] for help
CRC=0xb3c2238d
size=      48kB time=00:00:00.37 bitrate=1067.4kbits/s
video:0kB audio:100kB subtitle:0 global headers:0kB muxing overhead -51.431903%
$ ffmpeg -i out.mov -f crc -
ffmpeg version N-52413-gad56535 Copyright (c) 2000-2013 the FFmpeg developers
  built on Apr 23 2013 16:00:56 with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl --disable-indev=jack
  libavutil      52. 27.100 / 52. 27.100
  libavcodec     55.  6.100 / 55.  6.100
  libavformat    55.  3.100 / 55.  3.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 60.101 /  3. 60.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf55.3.100
  Duration: 00:00:00.30, start: 0.000000, bitrate: 1313 kb/s
    Stream #0:0(eng): Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s16p, 1292 kb/s
    Metadata:
      handler_name    : DataHandler
Output #0, crc, to 'pipe:':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf55.3.100
    Stream #0:0(eng): Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      handler_name    : DataHandler
Stream mapping:
  Stream #0:0 -> #0:0 (alac -> pcm_s16le)
Press [q] to stop, [?] for help
[alac @ 0x2b76520] invalid element channel count
Error while decoding stream #0:0: Invalid data found when processing input
CRC=0x19605977
size=       0kB time=00:00:00.30 bitrate=   0.4kbits/s
video:0kB audio:36kB subtitle:0 global headers:0kB muxing overhead -99.959310%

comment:4 by Cigaes, 11 years ago

You should run with asserts enabled:

Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le -> alac)
Press [q] to stop, [?] for help
Assertion n <= 31 && value < (1U << n) failed at libavcodec/put_bits.h:137
#2  0x00002aaaab5f2219 in put_bits (value=<optimized out>, n=<optimized out>, s=<optimized out>) at libavcodec/put_bits.h:137
#3  encode_scalar (s=s@entry=0x662e20, x=<optimized out>, k=<optimized out>, k@entry=7, write_sample_size=<optimized out>)
    at libavcodec/alacenc.c:115
#4  0x00002aaaab5f2aec in alac_entropy_coder (s=0x662e20) at libavcodec/alacenc.c:333
#5  write_element (s=0x662ea4, s@entry=0x662e20, element=element@entry=TYPE_CPE, instance=instance@entry=0, 
    samples0=<optimized out>, samples1=<optimized out>) at libavcodec/alacenc.c:438
#6  0x00002aaaab5f33ad in write_frame (s=s@entry=0x662e20, samples=0x634ce0, 
    avpkt=<error reading variable: Unhandled dwarf expression opcode 0xfa>, 
    avpkt=<error reading variable: Unhandled dwarf expression opcode 0xfa>) at libavcodec/alacenc.c:456
#7  0x00002aaaab5f3559 in alac_encode_frame (avctx=0x6624a0, avpkt=0x7fffffffe180, frame=0x634ce0, 
    got_packet_ptr=0x7fffffffe03c) at libavcodec/alacenc.c:628
#8  0x00002aaaaba456db in avcodec_encode_audio2 (avctx=0x6624a0, avpkt=0x7fffffffe180, frame=0x634ce0, 
    got_packet_ptr=0x7fffffffe03c) at libavcodec/utils.c:1532

comment:5 by Carl Eugen Hoyos, 11 years ago

encode_scalar() calls put_bits with parameters 17 (for n) and 164356 (for value) which is larger than 217 (131072).

comment:6 by Carl Eugen Hoyos, 11 years ago

Priority: normalimportant
Summary: ALAC encoder adds a burst of white noiseALAC encoder produces invalid output / is not lossless

comment:7 by Carl Eugen Hoyos, 11 years ago

Resolution: fixed
Status: openclosed

Fixed by Michael, thank you for the sample!

Note: See TracTickets for help on using tickets.