[FFmpeg-devel] [FFmpeg-cvslog] avformat/mov: make STTS duration unsigned int

Michael Niedermayer michael at niedermayer.cc
Mon Nov 22 15:59:55 EET 2021


On Mon, Nov 22, 2021 at 06:57:32PM +0530, Gyan Doshi wrote:
> 
> 
> On 2021-11-22 06:50 pm, Michael Niedermayer wrote:
> > On Mon, Nov 22, 2021 at 02:17:24PM +0100, Michael Niedermayer wrote:
> > > On Mon, Nov 22, 2021 at 09:49:26AM +0000, Gyan Doshi wrote:
> > > > ffmpeg | branch: master | Gyan Doshi <ffmpeg at gyani.pro> | Tue Nov 16 19:02:32 2021 +0530| [203b0e3561dea1ec459be226d805abe73e7535e5] | committer: Gyan Doshi
> > > > 
> > > > avformat/mov: make STTS duration unsigned int
> > > > 
> > > > As per 8.6.1.2.2 of ISO/IEC 14496-12:2015(E), STTS sample offsets
> > > > are to be always stored as uint32_t. So far, they have been signed ints
> > > > which led to desync in files with very large offsets.
> > > > 
> > > > The MOVStts struct was used to store CTTS offsets as well. These can be
> > > > negative in version 1. So a new struct MOVCtts was created and all
> > > > declarations for CTTS usage changed to MOVCtts.
> > > > 
> > > > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=203b0e3561dea1ec459be226d805abe73e7535e5
> > > > ---
> > > > 
> > > >   libavformat/isom.h   |  9 +++++++--
> > > >   libavformat/mov.c    | 20 ++++++++++----------
> > > >   libavformat/movenc.c |  2 +-
> > > >   3 files changed, 18 insertions(+), 13 deletions(-)
> > > This breaks:
> > > 
> > > ./ffmpeg -i ~/videos/mp4-negative-stts-problem.mp4 -c copy  -t 3 -y file-negstts.mov
> > > 
> > > https://samples.ffmpeg.org/mov/mp4-negative-stts-problem.mp4
> > failure happens like this:
> > 
> > [mov @ 0x56332ba06800] Application provided duration: 4294966430 is invalid
> 
> That's triggered by this code in lavf/movenc.c
> 
> ----
>     if (pkt->duration < 0 || pkt->duration > INT_MAX) {
>         av_log(s, AV_LOG_ERROR, "Application provided duration: %"PRId64" is
> invalid\n", pkt->duration);
>         return AVERROR(EINVAL);
>     }
> ----
> 
> Since the spec allows duration up to uint32, the INT_MAX limit is wrong and
> is another separate bug.
> 
> I'll change that when I correct the muxer.

this problem seems unrelated to the mov muxer, here framecrc is used instead
of mov, it fails too and framecrc is happily accepting the wrong duration

 ./ffmpeg -i ~/videos/mp4-negative-stts-problem.mp4 -c copy  -t 3 -y -f framecrc -

you can see here that the audio stream is truncated once the
wrong duration occurs

0,          0,          0,     6399,    15493, 0x1bf11e9800 
1,          0,          0,     1023,      318, 0xe8c195ad
1,       1023,       1023,     1023,      543, 0x0d7b1ba9
1,       2046,       2046,     2362,      540, 0x71401059
0,       6399,       6399,     6399,    10770, 0x819bf607, F=0x0
1,       4408,       4408,     1023,      196, 0x19246a78
1,       5431,       5431,     1023,      453, 0xff79e208
0,      12798,      12798,     6399,     2103, 0x160b2eb3, F=0x0
1,       6454,       6454,      157,      446, 0x4394d6a2
1,       6611,       6611,     1023,      446, 0xa806de6b
1,       7634,       7634,     1023,      433, 0x606bdd56
1,       8657,       8657,     1023,      438, 0x4e13e0f0
0,      19197,      19197,     6399,     2637, 0xc6ba14ee, F=0x0
1,       9680,       9680,     1338,      426, 0x194bd9e9
1,      11018,      11018,     1023,      442, 0xfa35e018
0,      25596,      25596,     6399,     4770, 0x660c4900, F=0x0
1,      12041,      12041,     1023,      439, 0x35bcd9d1
1,      13064,      13064,     2362,      426, 0x9595e229
0,      31995,      31995,     6399,     5061, 0xc753d42f, F=0x0
1,      15426,      15426,     1023,      428, 0xcc04d5fd
1,      16449,      16449,     1023,      423, 0xcde7d049
1,      17472,      17472,     1023,      405, 0x01c4cba1
0,      38394,      38394,     6399,     6321, 0x5ef85181, F=0x0
1,      18495,      18495, 4294966430,      421, 0xcb82ccf8
0,      44793,      44793,     6399,     6516, 0x100d9a6c, F=0x0
0,      51192,      51192,     6399,     4947, 0xaa8b81a6, F=0x0
0,      57591,      57591,     6399,     4757, 0x9edc5d0e, F=0x0
0,      63990,      63990,     6399,     4790, 0x2e0f48a8, F=0x0
0,      70389,      70389,     6399,     4869, 0x37b68637, F=0x0
0,      76788,      76788,     6399,     4826, 0x05906c8b, F=0x0
0,      83187,      83187,     6399,     4755, 0xd45b2b49, F=0x0
0,      89586,      89586,     6399,     4849, 0x997d64a8, F=0x0
0,      95985,      95985,     6399,     4879, 0xf1707281, F=0x0
0,     102384,     102384,     6399,     4977, 0x50839ad0, F=0x0
0,     108783,     108783,     6399,     4740, 0xdd2d4998, F=0x0
0,     115182,     115182,     6399,     4798, 0x55905414, F=0x0
0,     121581,     121581,     6399,     4951, 0x0c41a6ce, F=0x0
0,     127980,     127980,     6399,     4691, 0x4a541c7c, F=0x0
0,     134379,     134379,     6399,     4796, 0x3b403cc5, F=0x0
0,     140778,     140778,     6399,     4757, 0x546d682c, F=0x0
0,     147177,     147177,     6399,     4896, 0xd3fa714c, F=0x0
0,     153576,     153576,     6399,     4823, 0x1a803f47, F=0x0
0,     159975,     159975,     6399,     4922, 0xbf4e8e4a, F=0x0
0,     166374,     166374,     6399,     4900, 0xb3b59ed7, F=0x0
0,     172773,     172773,     6399,     4820, 0xcf4d7751, F=0x0
0,     179172,     179172,     6399,     4805, 0x78e05cbc, F=0x0
0,     185571,     185571,     6399,     4801, 0xe3be5df6, F=0x0
0,     191970,     191970,     6399,     4798, 0x9a5f6003, F=0x0
0,     198369,     198369,     6399,     4702, 0x383d0604, F=0x0
0,     204768,     204768,     6399,     4755, 0xcf2c3849, F=0x0
0,     211167,     211167,     6399,     4869, 0x9edc8732, F=0x0
0,     217566,     217566,     6399,     4789, 0x429f4a81, F=0x0
0,     223965,     223965,     6399,     4841, 0xe3ff61d0, F=0x0
0,     230364,     230364,     6399,     4687, 0x57fd2093, F=0x0
0,     236763,     236763,     6399,     4907, 0x46899bf7, F=0x0
0,     243162,     243162,     6399,     4699, 0x7b1b38be, F=0x0
0,     249561,     249561,     6399,     4799, 0x407f2442, F=0x0
0,     255960,     255960,     6399,     4839, 0x5ea867fc, F=0x0
0,     262359,     262359,     6399,     4828, 0xc3c55618, F=0x0
0,     268758,     268758,     6399,     4777, 0x27898276, F=0x0
0,     275157,     275157,     6399,     4759, 0xe80f2b54, F=0x0
0,     281556,     281556,     6399,     4886, 0x7de69458, F=0x0
0,     287955,     287955,     6399,     4849, 0xfa946cc6, F=0x0
frame=   46 fps=0.0 q=-1.0 Lsize=       4kB time=00:00:02.99 bitrate=  11.4kbits/s speed= 241x    
video:231kB audio:7kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

before:

0,          0,          0,     6399,    15493, 0x1bf11e9800 bitrate=248000.0kbits/s speed=N/A    
1,          0,          0,     1023,      318, 0xe8c195ad
1,       1023,       1023,     1023,      543, 0x0d7b1ba9
1,       2046,       2046,     2362,      540, 0x71401059
0,       6399,       6399,     6399,    10770, 0x819bf607, F=0x0
1,       4408,       4408,     1023,      196, 0x19246a78
1,       5431,       5431,     1023,      453, 0xff79e208
0,      12798,      12798,     6399,     2103, 0x160b2eb3, F=0x0
1,       6454,       6454,      157,      446, 0x4394d6a2
1,       6611,       6611,     1023,      446, 0xa806de6b
1,       7634,       7634,     1023,      433, 0x606bdd56
1,       8657,       8657,     1023,      438, 0x4e13e0f0
0,      19197,      19197,     6399,     2637, 0xc6ba14ee, F=0x0
1,       9680,       9680,     1338,      426, 0x194bd9e9
1,      11018,      11018,     1023,      442, 0xfa35e018
0,      25596,      25596,     6399,     4770, 0x660c4900, F=0x0
1,      12041,      12041,     1023,      439, 0x35bcd9d1
1,      13064,      13064,     2362,      426, 0x9595e229
0,      31995,      31995,     6399,     5061, 0xc753d42f, F=0x0
1,      15426,      15426,     1023,      428, 0xcc04d5fd
1,      16449,      16449,     1023,      423, 0xcde7d049
1,      17472,      17472,     1023,      405, 0x01c4cba1
0,      38394,      38394,     6399,     6321, 0x5ef85181, F=0x0
1,      18495,      18495,        1,      421, 0xcb82ccf8
1,      18496,      18496,      156,      377, 0x2171bf8a
1,      18652,      18652,     1023,      388, 0x3a2bc526
1,      19675,      19675,     2362,      381, 0x1f40bc36
0,      44793,      44793,     6399,     6516, 0x100d9a6c, F=0x0
1,      22037,      22037,     1023,      389, 0x3a9dbd23
1,      23060,      23060,     1023,      372, 0x50f2b7fb
0,      51192,      51192,     6399,     4947, 0xaa8b81a6, F=0x0
1,      24083,      24083,     1023,      376, 0x37ecb23d
1,      25106,      25106,        1,      369, 0x4242ae16
1,      25107,      25107,      156,      360, 0x9f3dac15
1,      25263,      25263,     1023,      356, 0x43d9b213
1,      26286,      26286,     2362,      366, 0xdc24b833
0,      57591,      57591,     6399,     4757, 0x9edc5d0e, F=0x0
1,      28648,      28648,     1023,      365, 0x9a16a8a1
0,      63990,      63990,     6399,     4790, 0x2e0f48a8, F=0x0
1,      29671,      29671,     1023,      356, 0xb6aaaf7b
1,      30694,      30694,     2362,      346, 0x7d34a7fc
0,      70389,      70389,     6399,     4869, 0x37b68637, F=0x0
1,      33056,      33056,     1023,      359, 0x52e5b5fe
1,      34079,      34079,     1023,      373, 0x4e65aecb
1,      35102,      35102,     1023,      357, 0x47bead5f
0,      76788,      76788,     6399,     4826, 0x05906c8b, F=0x0
1,      36125,      36125,        1,      350, 0xbbd8a861
1,      36126,      36126,      156,      367, 0x46c6b965
1,      36282,      36282,     1023,      350, 0xfdbdb2de
1,      37305,      37305,     2362,      351, 0xe250a553
0,      83187,      83187,     6399,     4755, 0xd45b2b49, F=0x0
1,      39667,      39667,     1023,      366, 0xf9fbbb7f
1,      40690,      40690,     1023,      354, 0x0a42aec8
0,      89586,      89586,     6399,     4849, 0x997d64a8, F=0x0
1,      41713,      41713,     1023,      359, 0x989ba6f0
1,      42736,      42736,        1,      352, 0xede2ada7
1,      42737,      42737,      156,      361, 0xcb19accf
1,      42893,      42893,     1023,      365, 0xfca6ab47
1,      43916,      43916,     2362,      350, 0xe7a6a765
0,      95985,      95985,     6399,     4879, 0xf1707281, F=0x0
1,      46278,      46278,     1023,      352, 0x58e3ae9d
0,     102384,     102384,     6399,     4977, 0x50839ad0, F=0x0
1,      47301,      47301,     1023,      351, 0x8841a894
1,      48324,      48324,     1023,      361, 0x3bfdafc2
1,      49347,      49347,     1338,      347, 0x77809f72
0,     108783,     108783,     6399,     4740, 0xdd2d4998, F=0x0
1,      50685,      50685,     1023,      371, 0x008eb929
1,      51708,      51708,     1023,      369, 0x1a1cac03
1,      52731,      52731,      157,      353, 0x6f33b2fc
1,      52888,      52888,     1023,      350, 0x50eaa8ea
0,     115182,     115182,     6399,     4798, 0x55905414, F=0x0
1,      53911,      53911,     1023,      358, 0x67b4aee8
1,      54934,      54934,     1023,      349, 0x8758a634
0,     121581,     121581,     6399,     4951, 0x0c41a6ce, F=0x0
1,      55957,      55957,     1338,      373, 0x592aac4d
1,      57295,      57295,     1023,      351, 0xa5b7ab08
1,      58318,      58318,     1023,      372, 0x1542b5bf
0,     127980,     127980,     6399,     4691, 0x4a541c7c, F=0x0
1,      59341,      59341,      157,      350, 0x53c8a8da
1,      59498,      59498,     1023,      361, 0xa688a7de
1,      60521,      60521,     1023,      360, 0x8a23b0cb
1,      61544,      61544,     2362,      359, 0x702bb423
0,     134379,     134379,     6399,     4796, 0x3b403cc5, F=0x0
1,      63906,      63906,     1023,      368, 0x4a5ab5d5
0,     140778,     140778,     6399,     4757, 0x546d682c, F=0x0
1,      64929,      64929,     1023,      355, 0x8b13aaf5
1,      65952,      65952,     1023,      363, 0x257ab4c7
1,      66975,      66975,     1338,      359, 0xf11cb910
0,     147177,     147177,     6399,     4896, 0xd3fa714c, F=0x0
1,      68313,      68313,     1023,      351, 0x955eb0c7
1,      69336,      69336,     1023,      354, 0x0cf5b0bd
1,      70359,      70359,      157,      350, 0x31eeac25
1,      70516,      70516,     1023,      365, 0x5666aef7
0,     153576,     153576,     6399,     4823, 0x1a803f47, F=0x0
1,      71539,      71539,     1023,      349, 0x347fa933
1,      72562,      72562,     1023,      366, 0x6e03a357
0,     159975,     159975,     6399,     4922, 0xbf4e8e4a, F=0x0
1,      73585,      73585,     1338,      356, 0xa406aca0
1,      74923,      74923,     1023,      359, 0x1fd0b0e6
1,      75946,      75946,     1023,      346, 0x9e72a83a
0,     166374,     166374,     6399,     4900, 0xb3b59ed7, F=0x0
1,      76969,      76969,      157,      352, 0x6540b43a
1,      77126,      77126,     1023,      168, 0xd3f252f5
1,      78149,      78149,     1023,      180, 0x91c85dc1
1,      79172,      79172,     1023,      348, 0x3e75ac80
0,     172773,     172773,     6399,     4820, 0xcf4d7751, F=0x0
1,      80195,      80195,     1338,      381, 0xe880b819
1,      81533,      81533,     1023,      158, 0xa9f850a3
0,     179172,     179172,     6399,     4805, 0x78e05cbc, F=0x0
1,      82556,      82556,     1023,      191, 0x86d35b66
1,      83579,      83579,     2362,      364, 0xffb2ae32
0,     185571,     185571,     6399,     4801, 0xe3be5df6, F=0x0
1,      85941,      85941,     1023,      367, 0x9fe2b681
1,      86964,      86964,     1023,      365, 0xf136afbc
1,      87987,      87987,      157,      369, 0xaa38af1e
1,      88144,      88144,     1023,      362, 0x2085b12a
0,     191970,     191970,     6399,     4798, 0x9a5f6003, F=0x0
1,      89167,      89167,     1023,      372, 0xd909b5e3
1,      90190,      90190,     1023,      375, 0xb509b270
0,     198369,     198369,     6399,     4702, 0x383d0604, F=0x0
1,      91213,      91213,     1338,      381, 0x7a1bb855
1,      92551,      92551,     1023,      367, 0x274ab214
1,      93574,      93574,     1023,      373, 0xacafba90
0,     204768,     204768,     6399,     4755, 0xcf2c3849, F=0x0
1,      94597,      94597,      157,      374, 0xcf93bc2e
1,      94754,      94754,     1023,      377, 0xab87bada
1,      95777,      95777,     1023,      380, 0xb77cc682
1,      96800,      96800,     1023,      372, 0xe791be02
0,     211167,     211167,     6399,     4869, 0x9edc8732, F=0x0
1,      97823,      97823,     1338,      365, 0x3662b33e
1,      99161,      99161,     1023,      367, 0xe5bdb57d
0,     217566,     217566,     6399,     4789, 0x429f4a81, F=0x0
1,     100184,     100184,     1023,      391, 0x807cbc95
1,     101207,     101207,     2362,      395, 0xd291bdf8
0,     223965,     223965,     6399,     4841, 0xe3ff61d0, F=0x0
1,     103569,     103569,     1023,      375, 0x500eba63
1,     104592,     104592,     1023,      388, 0xd50dbb4c
1,     105615,     105615,     1023,      377, 0xe2c4bfcb
0,     230364,     230364,     6399,     4687, 0x57fd2093, F=0x0
1,     106638,     106638,        1,      394, 0x9a6bc1e9
1,     106639,     106639,      156,      383, 0x0fd2ccc8
1,     106795,     106795,     1023,      203, 0x2b256fc8
1,     107818,     107818,     2362,      186, 0x3a485c28
0,     236763,     236763,     6399,     4907, 0x46899bf7, F=0x0
1,     110180,     110180,     1023,      179, 0xb3b9599a
1,     111203,     111203,     1023,      186, 0x30e7573f
0,     243162,     243162,     6399,     4699, 0x7b1b38be, F=0x0
1,     112226,     112226,     1023,      208, 0x57d26643
1,     113249,     113249,        1,      417, 0xd2bbce0c
1,     113250,     113250,      156,      420, 0xea65ceb9
1,     113406,     113406,     1023,      420, 0x1f31d944
1,     114429,     114429,     2362,      425, 0x6f9dd3ed
0,     249561,     249561,     6399,     4799, 0x407f2442, F=0x0
1,     116791,     116791,     1023,      423, 0xc7f5cc1b
0,     255960,     255960,     6399,     4839, 0x5ea867fc, F=0x0
1,     117814,     117814,     1023,      417, 0xa699d1f1
1,     118837,     118837,     2362,      408, 0x5f09c93f
0,     262359,     262359,     6399,     4828, 0xc3c55618, F=0x0
1,     121199,     121199,     1023,      399, 0x9b91c992
1,     122222,     122222,     1023,      411, 0x9b98c882
1,     123245,     123245,     1023,      416, 0x75d0cd87
0,     268758,     268758,     6399,     4777, 0x27898276, F=0x0
1,     124268,     124268,        1,      414, 0xe3d5cc29
1,     124269,     124269,      156,      421, 0x4028ce41
1,     124425,     124425,     1023,      421, 0xbe0ddd6f
1,     125448,     125448,     2362,      422, 0x326cd143
0,     275157,     275157,     6399,     4759, 0xe80f2b54, F=0x0
1,     127810,     127810,     1023,      416, 0x6afacd91
1,     128833,     128833,     1023,      442, 0x34c8e0f3
0,     281556,     281556,     6399,     4886, 0x7de69458, F=0x0
1,     129856,     129856,     1023,      404, 0x34f1cee8
1,     130879,     130879,        1,      428, 0x22e7dcb8
1,     130880,     130880,      156,      415, 0x7f03d93c
1,     131036,     131036,     1023,      413, 0x2589d155
1,     132059,     132059,     2362,      425, 0xf762d484
0,     287955,     287955,     6399,     4849, 0xfa946cc6, F=0x0
frame=   46 fps=0.0 q=-1.0 Lsize=      11kB time=00:00:03.01 bitrate=  28.7kbits/s speed=3.64e+03x    
video:231kB audio:47kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20211122/f06b731d/attachment.sig>


More information about the ffmpeg-devel mailing list