[FFmpeg-user] 2 or maybe 3 trimming bugs

Mark Filipak markfilipak.imdb at gmail.com
Mon Jan 15 10:28:46 EET 2024


Interested and knowledgeable folks, please confirm my results prior to trac submission. I'd like to 
know what happens in other use-cases. If you want this video, I could make a shortened version that 
would allow testing of the front trim, and we could figure out how to get it to you.

Thanks
--Mark.


set SOURCE=h:\BDMV\STREAM\00305.m2ts
set TARGET=c:\FANNY AND ALEXANDER [1982(1983)] 1of4.m2ts

: This is the Windows cmd script that made the target.

: Issues:

: 1.
: 59 bogus packets are made in the target preceding frame 481: 58 audio
: and frame 480, plus one that follows frame 134046: frame 134048. Note:
: Even if I made a mistake placing the trim, bogus packets shouldn't be
: there. Note that video timebase == audio timebase.
: Clue: The bogus end frame's DTS == the valid end frame's PTS.

: 2.
: Something actually changes this bogus audio packet:
:   1,   2798640,   2798640,  960,   1084, 0xe54d2b6f
: to this:
:   1,   2798640,   2798640,  960,     60, 0xec16103f
: Granted, it's silent audio, but how could a remux delete 1024 bytes?
: Note: That's exactly 1 disc sector.

: -Begin-

: Determine '-ss' and '-to'

: start -- MPV says to start at 0:20.062 sec -- MPV rounds.
: (20.062 sec)*(24/1.001 fps) = 481.[006993..] frames, i.e., 0..480
: (frame 481)/(24/1.001 fps) = 20.061708[3..] sec

: end -- MPV says to end at 1:33:10.835 (i.e., 5590.835 sec) -- MPV rounds.
: (5590.835 sec)*(24/1.001 fps) = 134045.[994005..] frames, i.e., 481..134046
: (frame 134046)/(24/1.001 fps) = 5590.83525[0..] sec

set TRIM=-framespan 481..134046          ...gee, this would be simple
set TRIM=-ss 20.061708333 -to 5590.83525
: PTS = 2854113.75[0..]..504223732.5[0..]
set CODE=-c copy -sn -dn
ffmpeg %TRIM% -copyts -i %SOURCE% -map 0 %CODE% -muxdelay 0 "%TARGET%"
pause
exit

Tip: Highlight the 6 fields and search on them to switch back-n-forth.

   The source.

   ffmpeg -i %SOURCE% -map 0 -copyts -c copy -f framecrc -

    --------------------starts---------------------
     in this video, '0': video, '1': audio, '2': subtitles
    /     DTS        PTS     dur   bytes     crc
   0,   1044806,   1048560, 3753, 640646, 0x900a1a7a                 0
   0,   1048560,   1056067, 3753, 640646, 0xe5c6cd7c                 2
   1,   1048560,   1048560,  960,   1084, 0xe54d2b6f
   1,   1049520,   1049520,  960,   1084, 0xe54d2b6f
   1,   1050480,   1050480,  960,   1084, 0xe54d2b6f
   1,   1051440,   1051440,  960,   1084, 0xe54d2b6f
   0,   1052313,   1052313, 3753, 640646, 0xe7f0c204                 1

   463 more video & 1815 more audio packets here                     3..465

   0,   2794053,   2801561, 3753,  73475, 0x95247b28                 467
   1,   2794800,   2794800,  960,   1084, 0xe54d2b6f
   1,   2795760,   2795760,  960,   1084, 0xe54d2b6f
   1,   2796720,   2796720,  960,   1084, 0xe54d2b6f
   1,   2797680,   2797680,  960,   1084, 0xe54d2b6f
   0,   2797807,   2797807, 3753,  66185, 0xffbb475c                 466
   1,   2798640,   2798640,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2799600,   2799600,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2800560,   2800560,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2801520,   2801520,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2801561,   2809068, 3753,  68631, 0x23461eb7                 469
   1,   2802480,   2802480,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2803440,   2803440,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2804400,   2804400,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2805315,   2805315, 3753,  60778, 0x9e687e73                 468
   1,   2805360,   2805360,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2806320,   2806320,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2807280,   2807280,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2808240,   2808240,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2809068,   2816576, 3753,  61104, 0x2eda8064                 471
   1,   2809200,   2809200,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2810160,   2810160,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2811120,   2811120,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2812080,   2812080,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2812822,   2812822, 3753,  56227, 0xdea54c0e                 470
   1,   2813040,   2813040,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2814000,   2814000,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2814960,   2814960,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2815920,   2815920,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2816576,   2824083, 3753,  51687, 0xcace633b                 473
   1,   2816880,   2816880,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2817840,   2817840,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2818800,   2818800,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2819760,   2819760,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2820330,   2820330, 3753,  50741, 0x3f745fcc                 472
   1,   2820720,   2820720,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2821680,   2821680,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2822640,   2822640,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2823600,   2823600,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2824083,   2835345, 3753,  32612, 0x84e2722c                 476
   1,   2824560,   2824560,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2825520,   2825520,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2826480,   2826480,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2827440,   2827440,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2827837,   2827837, 3753,  41799, 0x58c2c17c                 474
   1,   2828400,   2828400,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2829360,   2829360,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2830320,   2830320,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2831280,   2831280,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2831591,   2831591, 3753,  35986, 0x0859e6ae                 475
   1,   2832240,   2832240,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2833200,   2833200,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2834160,   2834160,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2835120,   2835120,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2835345,   2846606, 3753,  12050, 0x02bb34c9                 479
   1,   2836080,   2836080,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2837040,   2837040,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2838000,   2838000,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2838960,   2838960,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2839098,   2839098, 3753,  25719, 0x6f77b9b6                 477
   1,   2839920,   2839920,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2840880,   2840880,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2841840,   2841840,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2842800,   2842800,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2842852,   2842852, 3753,  22455, 0xaa9655b8                 478
   1,   2843760,   2843760,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2844720,   2844720,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2845680,   2845680,  960,   1084, 0xe54d2b6f <== makes bogus
+-----------------------------------------------------------------------+
¦ 0,   2846606,   2854113, 3753, 640646, 0x3a5a0c45 <== copy        481 ¦
+-----------------------------------------------------------------------+
   1,   2846640,   2846640,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2847600,   2847600,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2848560,   2848560,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2849520,   2849520,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2850360,   2850360, 3753, 640646, 0xfed1d09a <== makes bogus 480
   1,   2850480,   2850480,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2851440,   2851440,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2852400,   2852400,  960,   1084, 0xe54d2b6f <== makes bogus
   1,   2853360,   2853360,  960,   1084, 0xe54d2b6f <== makes bogus
   0,   2854113,   2861621, 3753, 640646, 0x02208727 <== copy        483
   1,   2854320,   2854320,  960,   1084, 0xe54d2b6f <== copy
   1,   2855280,   2855280,  960,   1084, 0xe54d2b6f <== copy
   1,   2856240,   2856240,  960,   1084, 0xe54d2b6f <== copy
   1,   2857200,   2857200,  960,   1084, 0xe54d2b6f <== copy
   0,   2857867,   2857867, 3753, 640646, 0x108abb16 <== copy        482
    -------------------continues-------------------
   0, 504212471, 504212471, 3753,    578, 0x415815b3 <== copy        134043
   1, 504213360, 504213360,  960,   1400, 0x8bdea5c1 <== copy
   1, 504214320, 504214320,  960,   1396, 0xeff0a5d0 <== copy
   1, 504215280, 504215280,  960,   1400, 0x2457b15f <== copy
+--------------------------------------------------------------------------+
¦ 0, 504216225, 504223732, 3753, 640646, 0x23141ebc <== copy        134046 ¦
+--------------------------------------------------------------------------+
   1, 504216240, 504216240,  960,   1396, 0x0c5ba512 <== copy
   1, 504217200, 504217200,  960,   1392, 0xc090a40f <== copy
   1, 504218160, 504218160,  960,   1408, 0xd071b6bd <== copy
   1, 504219120, 504219120,  960,   1400, 0xdffda506 <== copy
   0, 504219978, 504219978, 3753, 640646, 0x5ef78a61 <== copy        134045
   1, 504220080, 504220080,  960,   1392, 0x90a09e3a <== copy
   1, 504221040, 504221040,  960,   1400, 0xffdfa198 <== copy
   1, 504222000, 504222000,  960,   1400, 0x5eed993b <== copy
   1, 504222960, 504222960,  960,   1392, 0x102da26e <== copy
   0, 504223732, 504231240, 3753, 640646, 0x31a0cd7f <== makes bogus 134048
   1, 504223920, 504223920,  960,   1392, 0xe1e7a692
   1, 504224880, 504224880,  960,   1392, 0xb6f6b094
   1, 504225840, 504225840,  960,   1404, 0x7793971b
   1, 504226800, 504226800,  960,   1400, 0x2270a846
   0, 504227486, 504227486, 3753, 640646, 0xfb0ec7ee                 134047
    ---------------continues-to-end----------------

   The target.

   ffmpeg -i %TARGET% -map 0 -copyts -c copy -f framecrc -

    --------------------starts---------------------
     in this copy, '0': video, '1': audio
    /     DTS        PTS     dur   bytes     crc
   1,   2798640,   2798640,  960,     60, 0xec16103f <== bogus *changes*
   1,   2799600,   2799600,  960,   1084, 0xe54d2b6f <== bogus
   1,   2800560,   2800560,  960,   1084, 0xe54d2b6f <== bogus
   1,   2801520,   2801520,  960,   1084, 0xe54d2b6f <== bogus

   1,   2802480,   2802480,  960,   1084, 0xe54d2b6f <== bogus
   1,   2803440,   2803440,  960,   1084, 0xe54d2b6f <== bogus
   1,   2804400,   2804400,  960,   1084, 0xe54d2b6f <== bogus

   1,   2805360,   2805360,  960,   1084, 0xe54d2b6f <== bogus
   1,   2806320,   2806320,  960,   1084, 0xe54d2b6f <== bogus
   1,   2807280,   2807280,  960,   1084, 0xe54d2b6f <== bogus
   1,   2808240,   2808240,  960,   1084, 0xe54d2b6f <== bogus

   1,   2809200,   2809200,  960,   1084, 0xe54d2b6f <== bogus
   1,   2810160,   2810160,  960,   1084, 0xe54d2b6f <== bogus
   1,   2811120,   2811120,  960,   1084, 0xe54d2b6f <== bogus
   1,   2812080,   2812080,  960,   1084, 0xe54d2b6f <== bogus

   1,   2813040,   2813040,  960,   1084, 0xe54d2b6f <== bogus
   1,   2814000,   2814000,  960,   1084, 0xe54d2b6f <== bogus
   1,   2814960,   2814960,  960,   1084, 0xe54d2b6f <== bogus
   1,   2815920,   2815920,  960,   1084, 0xe54d2b6f <== bogus

   1,   2816880,   2816880,  960,   1084, 0xe54d2b6f <== bogus
   1,   2817840,   2817840,  960,   1084, 0xe54d2b6f <== bogus
   1,   2818800,   2818800,  960,   1084, 0xe54d2b6f <== bogus
   1,   2819760,   2819760,  960,   1084, 0xe54d2b6f <== bogus

   1,   2820720,   2820720,  960,   1084, 0xe54d2b6f <== bogus
   1,   2821680,   2821680,  960,   1084, 0xe54d2b6f <== bogus
   1,   2822640,   2822640,  960,   1084, 0xe54d2b6f <== bogus
   1,   2823600,   2823600,  960,   1084, 0xe54d2b6f <== bogus

   1,   2824560,   2824560,  960,   1084, 0xe54d2b6f <== bogus
   1,   2825520,   2825520,  960,   1084, 0xe54d2b6f <== bogus
   1,   2826480,   2826480,  960,   1084, 0xe54d2b6f <== bogus
   1,   2827440,   2827440,  960,   1084, 0xe54d2b6f <== bogus

   1,   2828400,   2828400,  960,   1084, 0xe54d2b6f <== bogus
   1,   2829360,   2829360,  960,   1084, 0xe54d2b6f <== bogus
   1,   2830320,   2830320,  960,   1084, 0xe54d2b6f <== bogus
   1,   2831280,   2831280,  960,   1084, 0xe54d2b6f <== bogus

   1,   2832240,   2832240,  960,   1084, 0xe54d2b6f <== bogus
   1,   2833200,   2833200,  960,   1084, 0xe54d2b6f <== bogus
   1,   2834160,   2834160,  960,   1084, 0xe54d2b6f <== bogus
   1,   2835120,   2835120,  960,   1084, 0xe54d2b6f <== bogus

   1,   2836080,   2836080,  960,   1084, 0xe54d2b6f <== bogus
   1,   2837040,   2837040,  960,   1084, 0xe54d2b6f <== bogus
   1,   2838000,   2838000,  960,   1084, 0xe54d2b6f <== bogus
   1,   2838960,   2838960,  960,   1084, 0xe54d2b6f <== bogus

   1,   2839920,   2839920,  960,   1084, 0xe54d2b6f <== bogus
   1,   2840880,   2840880,  960,   1084, 0xe54d2b6f <== bogus
   1,   2841840,   2841840,  960,   1084, 0xe54d2b6f <== bogus
   1,   2842800,   2842800,  960,   1084, 0xe54d2b6f <== bogus

   1,   2843760,   2843760,  960,   1084, 0xe54d2b6f <== bogus
   1,   2844720,   2844720,  960,   1084, 0xe54d2b6f <== bogus
   1,   2845680,   2845680,  960,   1084, 0xe54d2b6f <== bogus
+-----------------------------------------------------------------------+
¦ 0,   2846606,   2854113, 3753, 640646, 0x3a5a0c45 <== copy        481 ¦
+-----------------------------------------------------------------------+
   1,   2846640,   2846640,  960,   1084, 0xe54d2b6f <== bogus
   1,   2847600,   2847600,  960,   1084, 0xe54d2b6f <== bogus
   1,   2848560,   2848560,  960,   1084, 0xe54d2b6f <== bogus
   1,   2849520,   2849520,  960,   1084, 0xe54d2b6f <== bogus
   0,   2850360,   2850360, 3753, 640646, 0xfed1d09a <== bogus       480
   1,   2850480,   2850480,  960,   1084, 0xe54d2b6f <== bogus
   1,   2851440,   2851440,  960,   1084, 0xe54d2b6f <== bogus
   1,   2852400,   2852400,  960,   1084, 0xe54d2b6f <== bogus
   1,   2853360,   2853360,  960,   1084, 0xe54d2b6f <== bogus
   0,   2854113,   2861621, 3753, 640646, 0x02208727                 483
   1,   2854320,   2854320,  960,   1084, 0xe54d2b6f
   1,   2855280,   2855280,  960,   1084, 0xe54d2b6f
   1,   2856240,   2856240,  960,   1084, 0xe54d2b6f
   1,   2857200,   2857200,  960,   1084, 0xe54d2b6f
   0,   2857867,   2857867, 3753, 640646, 0x108abb16                 482
    -------------------continues-------------------
   0, 504212471, 504212471, 3753,    578, 0x415815b3                 134043
   1, 504213360, 504213360,  960,   1400, 0x8bdea5c1
   1, 504214320, 504214320,  960,   1396, 0xeff0a5d0
   1, 504215280, 504215280,  960,   1400, 0x2457b15f
+--------------------------------------------------------------------------+
¦ 0, 504216225, 504223732, 3753, 640646, 0x23141ebc                 134046 ¦
+--------------------------------------------------------------------------+
   1, 504216240, 504216240,  960,   1396, 0x0c5ba512
   1, 504217200, 504217200,  960,   1392, 0xc090a40f
   1, 504218160, 504218160,  960,   1408, 0xd071b6bd
   1, 504219120, 504219120,  960,   1400, 0xdffda506
   0, 504219978, 504219978, 3753, 640646, 0x5ef78a61                 134045
   1, 504220080, 504220080,  960,   1392, 0x90a09e3a
   1, 504221040, 504221040,  960,   1400, 0xffdfa198
   1, 504222000, 504222000,  960,   1400, 0x5eed993b
   1, 504222960, 504222960,  960,   1392, 0x102da26e
   0, 504223732, 504231240, 3753, 640646, 0x31a0cd7f <== bogus       134048
    ---------------------ends----------------------


More information about the ffmpeg-user mailing list