Opened 4 years ago

Closed 15 months ago

Last modified 15 months ago

#8234 closed defect (invalid)

mp4 file with id3v2 tag detected as mp4 but still fails decoding

Reported by: Mattias Wadman Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mov aac id3v2
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

Looks like a mp4 file with a id3v2 tag prepended. ffmpeg detect it as mp4 but for some reason seems do not like the aac data.
If i remove the id3v2 tag the file decodes fine.

VLC seems to be able to play it but i'm not sure how weird files ffmpeg is suppose tolerate. Seems strange that it gets detect as mp4 but still fails.

How to reproduce:

% curl -OLJ 'https://pinecast.com/listen/8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3'

% shasum '8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3'
1150800df2f3d09e54668ce898ed85d57a18aad6  8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3

% ffmpeg-master -v 9 -loglevel 99 -y  -i '8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3' test.wav
ffmpeg version git-2019-10-10-a76a516 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.0 (Alpine 8.3.0)
  configuration: --enable-debug
  libavutil      56. 35.100 / 56. 35.100
  libavcodec     58. 59.102 / 58. 59.102
  libavformat    58. 33.100 / 58. 33.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 62.100 /  7. 62.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-i' ... matched as input url with argument '8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3'.
Reading option 'test.wav' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url 8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3.
Successfully parsed a group of options.
Opening an input file: 8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3.
[NULL @ 0x7f72cfd80140] Opening '8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3' for reading
[file @ 0x7f72cfd80980] Setting default whitelist 'file,crypto'
Probing mp3 score:12 size:2048
Probing mp3 score:12 size:4096
Probing mp3 score:12 size:8192
Probing mp3 score:12 size:16384
Probing mov,mp4,m4a,3gp,3g2,mj2 score:100 size:9224
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=32768 and score=100
id3v2 ver:3 flags:00 len:23534
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'ftyp' parent:'root' sz: 28 8 76711459
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] ISO: File Type Major Brand: M4A 
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'free' parent:'root' sz: 57308 36 76711459
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'mdat' parent:'root' sz: 75776820 57344 76711459
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'moov' parent:'root' sz: 853759 75834164 76711459
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'mvhd' parent:'moov' sz: 108 8 853751
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] time scale = 44100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'trak' parent:'moov' sz: 853393 116 853751
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'tkhd' parent:'trak' sz: 92 8 853385
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'mdia' parent:'trak' sz: 853293 100 853385
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'mdhd' parent:'mdia' sz: 32 8 853285
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'hdlr' parent:'mdia' sz: 34 40 853285
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] ctype=[0][0][0][0]
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] stype=soun
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'minf' parent:'mdia' sz: 853219 74 853285
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'smhd' parent:'minf' sz: 16 8 853211
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'dinf' parent:'minf' sz: 36 24 853211
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'dref' parent:'dinf' sz: 28 8 28
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'stbl' parent:'minf' sz: 853159 60 853211
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'stsd' parent:'stbl' sz: 103 8 853151
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] size=87 4CC=mp4a codec_type=1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] audio channels 2
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] version =0, isom =1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'esds' parent:'stsd' sz: 51 8 51
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] MPEG-4 description: tag=0x03 len=34
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] MPEG-4 description: tag=0x04 len=20
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] esds object type id 0x40
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] MPEG-4 description: tag=0x05 len=2
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] Specific MPEG-4 header len=2
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] mp4a config channels 2 obj 2 ext obj 0 sample rate 44100 ext sample rate 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'stts' parent:'stbl' sz: 24 111 853151
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] track[0].stts.entries = 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] sample_count=203965, sample_duration=1024
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'stsc' parent:'stbl' sz: 40 135 853151
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] track[0].stsc.entries = 2
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'stsz' parent:'stbl' sz: 815880 175 853151
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] sample_size = 0 sample_count = 203965
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] type:'stco' parent:'stbl' sz: 37104 816055 853151
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 0, offset e000, dts 0, size 254, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 1, offset e0fe, dts 1024, size 410, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 2, offset e298, dts 2048, size 383, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 3, offset e417, dts 3072, size 334, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 4, offset e565, dts 4096, size 371, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 5, offset e6d8, dts 5120, size 380, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 6, offset e854, dts 6144, size 385, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 7, offset e9d5, dts 7168, size 347, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 8, offset eb30, dts 8192, size 490, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 9, offset ed1a, dts 9216, size 376, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 10, offset ee92, dts 10240, size 341, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 11, offset efe7, dts 11264, size 320, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 12, offset f127, dts 12288, size 350, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 13, offset f285, dts 13312, size 375, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 14, offset f3fc, dts 14336, size 362, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 15, offset f566, dts 15360, size 380, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 16, offset f6e2, dts 16384, size 390, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 17, offset f868, dts 17408, size 333, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 18, offset f9b5, dts 18432, size 374, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 19, offset fb2b, dts 19456, size 365, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 20, offset fc98, dts 20480, size 368, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 21, offset fe08, dts 21504, size 389, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 22, offset ff8d, dts 22528, size 414, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 23, offset 1012b, dts 23552, size 344, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 24, offset 10283, dts 24576, size 376, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 25, offset 103fb, dts 25600, size 373, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 26, offset 10570, dts 26624, size 364, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 27, offset 106dc, dts 27648, size 386, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 28, offset 1085e, dts 28672, size 343, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 29, offset 109b5, dts 29696, size 370, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 30, offset 10b27, dts 30720, size 368, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 31, offset 10c97, dts 31744, size 410, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f72cfd80140] AVIndex stream 0, sample 32, offset 10e31, dts 32768, size 329, distance 0, keyframe 1

....

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] AVIndex stream 0, sample 203961, offset 4851d5e, dts 208856064, size 371, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] AVIndex stream 0, sample 203962, offset 4851ed1, dts 208857088, size 372, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] AVIndex stream 0, sample 203963, offset 4852045, dts 208858112, size 371, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] AVIndex stream 0, sample 203964, offset 48521b8, dts 208859136, size 372, distance 0, keyframe 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] type:'udta' parent:'moov' sz: 250 853509 853751
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] type:'meta' parent:'udta' sz: 242 8 242
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] type:'hdlr' parent:'meta' sz: 34 8 230
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] ctype=[0][0][0][0]
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] stype=mdir
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] type:'ilst' parent:'meta' sz: 196 42 230
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] type:'----' parent:'ilst' sz: 188 8 188
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] on_parse_exit_offset=76711459
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] Discarding ID3 tags because more suitable tags were found.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] demuxer does not support additional id3 data, skipping
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] Before avformat_find_stream_info() pos: 76711459 bytes read:919295 seeks:2 nb_streams:1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] stream 0, sample 0, dts 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] demuxer injecting skip 2112 / discard 0
[aac @ 0x5578c498f0c0] stereo with SCE
[aac @ 0x5578c498f0c0] channel element 0.0 duplicate
[aac @ 0x5578c498f0c0] channel element 0.0 is not allocated
[aac @ 0x5578c498f0c0] skip 2112 / discard 0 samples due to side data
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] stream 0: start_time: 0.048 duration: 4736.058
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] format: start_time: 0.048 duration: 4736.058 (estimate from stream) bitrate=129 kb/s
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] After avformat_find_stream_info() pos: 57598 bytes read:952063 seeks:3 frames:1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '8d4f78b0-b320-45a5-adb1-fd49136d4d29.mp3?source=rss&ext=asset.mp3':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A mp42isom
    creation_time   : 2019-10-09T04:21:13.000000Z
    iTunSMPB        :  00000000 00000840 000001C0 000000000C72EA00 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  Duration: 01:18:56.06, start: 0.047891, bitrate: 129 kb/s
    Stream #0:0(eng), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2019-10-09T04:21:13.000000Z
Successfully opened the file.
Parsing a group of options: output url test.wav.
Successfully parsed a group of options.
Opening an output file: test.wav.
[file @ 0x5578c497af40] Setting default whitelist 'file,crypto'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[aac @ 0x5578c4986300] stereo with SCE
[aac @ 0x5578c4986300] channel element 0.0 duplicate
[aac @ 0x5578c4986300] channel element 0.0 is not allocated
[aac @ 0x5578c4986300] skip 2112 / discard 0 samples due to side data
Error while decoding stream #0:0: Invalid data found when processing input
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] stream 0, sample 1, dts 23220
[aac @ 0x5578c4986300] stereo with SCE
[aac @ 0x5578c4986300] channel element 0.0 duplicate
[aac @ 0x5578c4986300] channel element 0.0 is not allocated
Error while decoding stream #0:0: Invalid data found when processing input
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] stream 0, sample 2, dts 46440
[aac @ 0x5578c4986300] stereo with SCE
[aac @ 0x5578c4986300] channel element 0.0 duplicate
[aac @ 0x5578c4986300] channel element 0.0 is not allocated
Error while decoding stream #0:0: Invalid data found when processing input
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f326d877140] stream 0, sample 3, dts 69660
[aac @ 0x5578c4986300] stereo with SCE
[aac @ 0x5578c4986300] channel element 0.0 duplicate
[aac @ 0x5578c4986300] channel element 0.0 is not allocated

...

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Attachments (1)

8d4f78b0-b320-45a5-adb1-fd49136d4d29_cut.mp3 (2.4 MB ) - added by Carl Eugen Hoyos 4 years ago.

Change History (7)

comment:1 by Carl Eugen Hoyos, 4 years ago

Component: ffmpegundetermined
Keywords: mov aac added; mp4 id3v2 removed
Version: unspecifiedgit-master

comment:2 by Carl Eugen Hoyos, 4 years ago

Component: undeterminedavformat
Keywords: id3v2 added

by Carl Eugen Hoyos, 4 years ago

comment:3 by Mattias Wadman, 15 months ago

Ran into this again and was about to file an issue and rediscovered this ticket. Seems to still be an issue with ffmpeg master as of today.

File to reproduce can be create with:

./ffmpeg -f lavfi -i sine -t 20ms -c aac aac.mp4
(echo -ne "ID3\0x02\0x00\x00\x00\x00\x00\x00" ; cat aac.mp4) > id3v2_aac

# seems to decode and skip id3v2 tag but fails decoding with
# [aac @ 0x7fdb761097c0] channel element 3.2 is not allocated
# Error while decoding stream #0:0: Invalid data found when processing input
# [aac @ 0x7fdb761097c0] channel element 2.12 is not allocated
# Error while decoding stream #0:0: Invalid data found when processing input
./ffmpeg -i id3v2_aac -f null -

comment:4 by Mattias Wadman, 15 months ago

Problem seems to be that the mov demuxer does not correctly compensate for tags when when calculating the sample offset. With this patch it works:

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 64fb7065d5..2c45e50ed0 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -326,6 +326,7 @@ typedef struct MOVContext {
         int64_t extent_offset;
     } *avif_info;
     int avif_info_size;
+    int64_t header_offset;
 } MOVContext;

 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 29bd3103e3..50a8e3308b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4140,7 +4140,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)

         for (i = 0; i < sc->chunk_count; i++) {
             int64_t next_offset = i+1 < sc->chunk_count ? sc->chunk_offsets[i+1] : INT64_MAX;
-            current_offset = sc->chunk_offsets[i];
+            current_offset = mov->header_offset + sc->chunk_offsets[i];
             while (mov_stsc_index_valid(stsc_index, sc->stsc_count) &&
                 i + 1 == sc->stsc_data[stsc_index + 1].first)
                 stsc_index++;
@@ -8416,6 +8416,7 @@ static int mov_read_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }

+    mov->header_offset = avio_tell(pb);
     mov->fc = s;
     mov->trak_index = -1;
     /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */

comment:5 by quinkblack, 15 months ago

Resolution: invalid
Status: newclosed

MP4 depends on absolute file offset. Prepend ID3 tag without change moov index is invalid. ID3 should be put in ID32 box, which is contained by meta box.

https://web.archive.org/web/20180309234838/http://mp4ra.org/specs.html#id3v2

comment:6 by Mattias Wadman, 15 months ago

Yes maybe this is beyond what ffmpeg should workaroud, and sorry by "does not correctly compensate" i didn't mean ffmpeg was doing something wrong, more what was needed to make the specific file work.

But it feels a bit confusing that ffmpeg do support reading id3v2 tags in the mp4 case but it will fail to decode samples if there was any prepended tags. Would it make sense to fail early in the mov demuxer with a more useful error? but what would be the condition, if file position > 0 when reading header it should fail, could that mess up other case like fragmented mp4?

Note: See TracTickets for help on using tickets.