[FFmpeg-user] Packet corrupt on cut, notice on concat

Mark Filipak markfilipak.imdb at gmail.com
Mon Feb 19 19:47:08 EET 2024


On 19/02/2024 01.16, Greg Oliver wrote:
> I usually do not chime in on your emails where people flame you for writing
> a book or being a troll because I usually learn something from the
> discussions.

Hi Greg. I'm not writing a book. That's something someone made up.

> Lately you have not posted one example clip or logs from anything you have
> asked questions about.

That's because there's no errors in my logs. What I'm doing is correct. What I have been posting is 
framecrc outputs that prove what I say.

SUMMARY:
I'm cutting solely on packets that contain I-frames. I'm joining packets that contain I-frames on 
both sides of the join. There's no decoding, no encoding. There's only remuxing. I'm well aware of 
DTS-order versus PTS-order.

I began with
ffmpeg -ss <starttime> -to <endtime> -i this.m2ts
of course. It cut at the right place but the output included 52 audio frames and a B-frame that 
should have been cut. The join was not correct of course and the MPV player behaved as one would 
expect from a bad join.

I tried
ffmpeg -i this.m2ts -ss <starttime> -to <endtime>
but that cut at the wrong PTSs -- hundreds of packets early. There were other issues, too. No one 
could explain that behavior.

I asked if there is a way to discard specific packets based on PTSs. Gyan suggested I try
ffmpeg -i this.m2ts -bsf noise
I used '-bsf noise' to do _all_ the cutting and that appeared to work beautifully. The outputs 
appeared to be perfect in every way.

It was when I joined (concatenated) those segments what I discovered another problem: FFmpeg had 
corrupted the final B-frame just before the ending I-frame. When I 'moved' the cuts and join around 
in time, the 'corruption' followed the moves, always the final B-frame just before the ending I-frame.

The video is 24/1.001fps, so ticks-per-frame is 3753.75. Because PTSs are integers, 3753.75 tick 
intervals must be turned into integer PTSs. That was when I discovered that FFmpeg is not truncating 
correctly, so PTSs are not correct.

> You're being vague and Gyan just gave you something
> to try and you refused to try with just more questions.

Gyan suggested I add '-mpegts_flags +initial_discontinuity'. I tried it.
ffmpeg -copyts -i "concat:this1.m2ts|this2.m2ts" -map 0 -mpegts_flags +initial_discontinuity -c copy 
-dn -muxdelay 0 "that.m2ts"
The result:
"Packet corrupt (stream = 0, dts = 504201210)" and the same glitch in MPV. Do I know whether the 
corruption is from the cutting or the joining? Of course not.

> Sorry, but I find this list valuable and you are starting to put a bad
> taste in my mouth.

I'm so sorry about that. I don't know how to solve problems any other way than to try, try, try.

> And Reindl and Paul - I don't need any smart ass
> comments.  Reindal, I think that we are almost on all the same lists and
> everyone hates you, and Paul, you're ego would be bad in certain circles of
> technology people.

I think both Paul and Harold are trying to be helpful in their own ways. I'm a behaviorist, so I 
don't 'talk' about motives at all.

I think there are many bugs -- that's expected in an application that evolved as a collection of 
use-cases. I think I'm hitting them. I need help from a patient and persistent person who can read 
the source code.

I have a few best friends on ffmpeg-user but they don't participate much. I have a sneaking 
suspicion that Paul just might become my best-best friend on ffmpeg-user, but don't tell him.

I first got involved in video at Atari Advanced Engineering in the early 1980s where I redesigned 
its 2600 game system to produce NTSC/PAL/SECAM signals & timing that was 100% 
NTSC-/PAL-/SECAM-complaint. I have designed hundreds of hardware state machines for circuits, chips, 
and systems that I designed (and often invented) in Silicon Valley in California during the next 25 
years. They are/were used in games, test equipment, networking, NATO fighters and tanks, and various 
other design projects. Maybe half of what I designed was programmable. I program mostly in assembly 
language though I have written device drivers and test programs in about 10 other languages. In 
Silicon Valley, almost all my friends were codesmiths. :-)

--Mark.





More information about the ffmpeg-user mailing list