[FFmpeg-user] Unresolved concatenation and subtitle problems

Mark Filipak markfilipak.imdb at gmail.com
Sun Dec 31 05:12:40 EET 2023


The saga continues...

I'm trimming h:\BDMV\STREAM\00305.m2ts, making e:\00305.mkv
FFmpeg appears to be adding soundless audio frames before the 1st video frame.
Concatenating e:\00306.mkv, made the same way, produces stutter & flashing at the join.
This report concentrates on the '-ss' trim of e:\00305.mkv.

About 00305.m2ts:
The 1st video packet is DTS=1044806, PTS=1048560.
                             +---------+
     ... DTS precedes PTS by ¦ 1 frame ¦ <== remember this.
                             +---------+
                          --------------------------------+
Now, I want to trim to   ¦ 20.061708[3..]..1:33:10.83525 ¦ exactly.
                          +-------------------------------+
                          +-------------------------------+
Therefore, I want        ¦ PTS=1805553.75..503175172.5   ¦ exactly.
                          +-------------------------------+
(At least, I think I do.)
'-showinfo' says this:
   "n:   481 pts:  1805553 ... type:I".
                          +-------------------------------+
Therefore, I want frames ¦            481..134046        ¦ exactly.
                          +-------------------------------+
But is frame 481 actually at PTS=1805553? No.
Why do I say that? Because '-framecrc' says this:
   +-----------------------------------------------+
   ¦ 1,    1805040,    1805040,      960,     1084 ¦
   ¦ 1,    1806000,    1806000,      960,     1084 ¦
   +-----------------------------------------------+
There is no packet with PTS=1805553 -- doesn't exist.

So, what if I ignore that and just do this:
<windows script>
   set SOURCE=h:\BDMV\STREAM\00305.m2ts
   set TRIM=-ss 20.061708333333333333333333333333 -to 1:33:10.83525
   set ARGS=-map 0 -c copy -dn
   set TARGET=e:\00305.mkv
   ffmpeg -report %TRIM% -i %SOURCE% %ARGS% %TARGET%
</windows script>

MPV plays it but shows 0:00.616 as the start time.
'-framecrc' shows 43 (presumably soundless) audio packets (DTS=0..448, PTS=0..448) preceding the 1st 
video packet (DTS=449, PTS=616).
                             +----------+
     ... DTS precedes PTS by ¦ 4 frames ¦
                             +----------+
The same thing probably happens at the '-to' trim point of 00305.m2ts, and it does happen at the 
'-ss' trim point of 00306.m2ts, so when I concat 00305.mkv & 00306.mkv, the join is messed up.
For 2 seconds, MPV stutters 5 times and flashes the first image frame of 00306.mkv 3 times:
   stop-pause-go- -stop-pause-go- -stop-flash-pause-go- -stop-flash-pause-go- -stop-flash-pause-go.
Then MPV continues as though nothing had happened.
Each of the 5 stutters are like micro-movies in which running time stops but frames 'run'.
Audio & subs flow though all that without a hitch. That tells me that audio packets are actually 
'running the show'.

What '-showinfo' is calling "PTS" is not PTS, it's ticks.
Ticks relative to the 1st video packet, but not to _all_ packets.

Since '-showinfo' lies about PTSs, I can't know 'N'.
And 'framecrc' doesn't show 'N's, so I'm in the dark regarding the true identity of the frame and 
its true PTS.

I also created e:\00305DTS-STARTDTS÷90.mkv
<windows script>
   set SOURCE=h:\BDMV\STREAM\00305.m2ts
   set TRIM=-ss 20.061708333333333333333333333333 -to 1:33:10.83525
   set BSFV=-bsf:v setts=dts=DTS-STARTDTS/90:pts=PTS-STARTPTS/90
   set BSFA=-bsf:a setts=dts=DTS-STARTDTS/90:pts=PTS-STARTPTS/90
   set ARGS=-map 0 %BSFV% %BSFA% -c copy -dn
   set TARGET=e:\00305_DTS-STARTDTS÷90.mkv
   ffmpeg -report %TRIM% -i %SOURCE% %ARGS% %TARGET%
</windows script>
and got similar results.

I'm like you. I just want perfect video. I'll really appreciate help.

-- Mark.


More information about the ffmpeg-user mailing list