Opened 7 years ago

Last modified 3 years ago

#6601 new defect

MP2 files are decoded with errors

Reported by: koops Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: mp2
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

% ffmpeg -i Common_Room.mp2 Common_Room.wav
ffmpeg version N-86994-g92da230
built with gcc 7.1.0 (GCC)

...

[mp2 @ 0000000001295920] Header missing
Error while decoding stream #0:0: Invalid data found when processing input

...

1379 frames successfully decoded, 1 decoding errors

File is decoded successfully, but there are decoding errors.

Log:

ffmpeg started on 2017-08-20 at 13:02:39
Report written to "ffmpeg-20170820-130239.log"
Command line:
ffmpeg.exe -report -i Common_Room.mp2 Common_Room.wav
ffmpeg version N-86994-g92da230 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.1.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 74.100 / 55. 74.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 99.100 /  6. 99.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Splitting the commandline.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-i' ... matched as input url with argument 'Common_Room.mp2'.
Reading option 'Common_Room.wav' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url Common_Room.mp2.
Successfully parsed a group of options.
Opening an input file: Common_Room.mp2.
[NULL @ 00000000010564a0] Opening 'Common_Room.mp2' for reading
[file @ 0000000001283e60] Setting default whitelist 'file,crypto'
[mp3 @ 00000000010564a0] Format mp3 probed with size=4096 and score=51
[mp3 @ 00000000010564a0] Skipping 0 bytes of junk at 0.
[mp3 @ 00000000010564a0] Before avformat_find_stream_info() pos: 0 bytes read:65664 seeks:2 nb_streams:1
[mp3 @ 00000000010564a0] All info found
[mp3 @ 00000000010564a0] Estimating duration from bitrate, this may be inaccurate
[mp3 @ 00000000010564a0] After avformat_find_stream_info() pos: 31744 bytes read:65664 seeks:2 frames:50
Input #0, mp3, from 'Common_Room.mp2':
  Duration: 00:01:12.05, start: 0.000000, bitrate: 95 kb/s
    Stream #0:0, 50, 1/14112000: Audio: mp2, 22050 Hz, stereo, s16p, 96 kb/s
Successfully opened the file.
Parsing a group of options: output url Common_Room.wav.
Successfully parsed a group of options.
Opening an output file: Common_Room.wav.
[file @ 00000000012a05a0] Setting default whitelist 'file,crypto'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (mp2 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 12 logical cores
[graph_0_in_0_0 @ 00000000012e3b60] Setting 'time_base' to value '1/22050'
[graph_0_in_0_0 @ 00000000012e3b60] Setting 'sample_rate' to value '22050'
[graph_0_in_0_0 @ 00000000012e3b60] Setting 'sample_fmt' to value 's16p'
[graph_0_in_0_0 @ 00000000012e3b60] Setting 'channel_layout' to value '0x3'
[graph_0_in_0_0 @ 00000000012e3b60] tb:1/22050 samplefmt:s16p samplerate:22050 chlayout:0x3
[format_out_0_0 @ 00000000012e63e0] Setting 'sample_fmts' to value 's16'
[format_out_0_0 @ 00000000012e63e0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 000000000129f040] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 00000000012e6940] [SWR @ 00000000012e6b20] Using s16p internally between filters
[auto_resampler_0 @ 00000000012e6940] ch:2 chl:stereo fmt:s16p r:22050Hz -> ch:2 chl:stereo fmt:s16 r:22050Hz
Output #0, wav, to 'Common_Room.wav':
  Metadata:
    ISFT            : Lavf57.76.100
    Stream #0:0, 0, 1/22050: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, stereo, s16, 705 kb/s
    Metadata:
      encoder         : Lavc57.102.100 pcm_s16le
[mp2 @ 0000000001295920] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[out_0_0 @ 00000000012e6200] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
size=    6206kB time=00:01:12.04 bitrate= 705.6kbits/s speed= 922x    
video:0kB audio:6206kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.001227%
Input file #0 (Common_Room.mp2):
  Input stream #0:0 (audio): 1380 packets read (864596 bytes); 1379 frames decoded (1588608 samples); 
  Total: 1380 packets (864596 bytes) demuxed
Output file #0 (Common_Room.wav):
  Output stream #0:0 (audio): 1379 frames encoded (1588608 samples); 1379 packets muxed (6354432 bytes); 
  Total: 1379 packets (6354432 bytes) muxed
1379 frames successfully decoded, 1 decoding errors
[AVIOContext @ 00000000012e0680] Statistics: 4 seeks, 28 writeouts
[AVIOContext @ 0000000001057440] Statistics: 897492 bytes read, 2 seeks

Attachments (1)

Common_Room.mp2 (844.3 KB ) - added by koops 7 years ago.

Download all attachments as: .zip

Change History (13)

by koops, 7 years ago

Attachment: Common_Room.mp2 added

comment:1 by Carl Eugen Hoyos, 7 years ago

Why do you believe there is a bug in FFmpeg?
How was the sample created?

comment:2 by koops, 7 years ago

This sample is music from the game "Harry Potter and the Sorcerer's Stone". I have more MP2 files from this game and all have this error.

comment:3 by koops, 7 years ago

Last edited 7 years ago by koops (previous) (diff)

comment:4 by koops, 7 years ago

Also I believe that the last frame is not decoded by ffmpeg, but it is decoded by sox and Audacity.

comment:5 by Carl Eugen Hoyos, 7 years ago

So all mp2 files from the game "Harry Potter and the Sorcerer's Stone" end with a few bytes of garbage: How is the decoder (or parser) supposed to know that it should ignore them?

in reply to:  4 ; comment:6 by Carl Eugen Hoyos, 7 years ago

Replying to koops:

Also I believe that the last frame is not decoded by ffmpeg, but it is decoded by sox and Audacity.

This seems unlikely to me: The last frame consists of 47 bytes (instead of 626 or 627), has no frame header (all other frames start with "0xff 0xf5 0xa2") and contains (non-readable) uncompressed data.

comment:7 by koops, 7 years ago

Indeed the error is gone if I remove these last 47 bytes. However, the resulting wav's data chunk is completely different from Audacity's or sox's. How can I know the file is decoded correctly?

comment:8 by Hendrik, 7 years ago

Lossy codecs don't decode to a bit-exact result, so comparing them between decoders is not as easy as that. You could compare the PSNR, or just judge if it sounds good.

comment:9 by koops, 7 years ago

How can I calculate the PSNR?

in reply to:  9 comment:10 by Carl Eugen Hoyos, 7 years ago

Replying to koops:

How can I calculate the PSNR?

In this case, I don't think you can: You would need a reference file to able to compare which output is closer to the original.
You could use tests/tiny_psnr from your FFmpeg tree to compare the output files and show that they are nearly identical.
Note that I believe contrary to FFmpeg neither sox nor Audacity contain native mp2 decoders, both use a third-party library.

in reply to:  8 comment:11 by Balling, 3 years ago

Replying to Hendrik:

Lossy codecs don't decode to a bit-exact result, so comparing them between decoders is not as easy as that. You could compare the PSNR, or just judge if it sounds good.

I am sorry what? No, all lossy codecs should decode bitperfectly. WHAT??? And this is JUST MPEG-2 Audio Layer II, not even mp3.

Last edited 3 years ago by Balling (previous) (diff)

in reply to:  6 comment:12 by Balling, 3 years ago

Replying to Carl Eugen Hoyos:

Replying to koops:

Also I believe that the last frame is not decoded by ffmpeg, but it is decoded by sox and Audacity.

This seems unlikely to me: The last frame consists of 47 bytes (instead of 626 or 627), has no frame header (all other frames start with "0xff 0xf5 0xa2") and contains (non-readable) uncompressed data.

Synchronisation lost: 0 (0x00000000) that is how. See Mediainfo.

Note: See TracTickets for help on using tickets.