Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 0/2] fix an mpegts scenario with unaligned pes
@ 2024-02-20 16:33 Nicolas Gaullier
  2024-02-20 16:33 ` [FFmpeg-devel] [PATCH 1/2] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets Nicolas Gaullier
  2024-02-20 16:33 ` [FFmpeg-devel] [PATCH 2/2] lavf/demux: duplicate side_data in parse_packet() Nicolas Gaullier
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Gaullier @ 2024-02-20 16:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Nicolas Gaullier

This is the scenario:
- unaligned PES and NAL encoding
- the first NAL of the access unit begins at the very end of a ts packet, sometimes only the 0x00 of the trailing byte (unfortunately, this is still conformant to the standards!)
- the video frame is so small (ex: typically still picture) it fits in a ts packet and a new PES is immediately started

Two sample files can be found here:
a) https://0x0.st/HDwD.ts
b) https://0x0.st/HDwd.ts

For sample a, the first NAL (AUD) is splited this way:
0x00 / 0x00 0x00 0x01 0x09
And for sample b:
0x00 0x00 0x00 / 0x01 0x09

ffmpeg -i input.ts -f null /dev/null
=> Application provided invalid, non monotonically increasing dts...

The parser can usually deal with unaligned packets thanks to the parser state, but here a new PES starts just right after the split and fetch_timestamp() does not know that the start of the PES was on the previous frame.

An alternative straightforward fix directly in the mpegts demuxer is possible but really ugly, see:
https://pastebin.com/J286CXDr

I hope this proposal is looking better. It consists in two patches to get an identical output.
The first patch fixes the fetch_timestamp mechanism.
The second patch is to make parse_packet duplicate the side_data when spliting packets. It is not clear to me if this is required nor correct in a general manner?


Nicolas Gaullier (2):
  avcodec/parser: fix fetch_timestamp in a scenario with unaligned
    packets
  lavf/demux: duplicate side_data in parse_packet()

 libavcodec/parser.c                           |   6 +-
 libavformat/demux.c                           |  23 ++-
 tests/ref/fate/concat-demuxer-simple2-lavf-ts | 164 +++++++++---------
 tests/ref/fate/ts-demux                       |   8 +-
 4 files changed, 107 insertions(+), 94 deletions(-)

-- 
2.30.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-23 12:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-20 16:33 [FFmpeg-devel] [PATCH 0/2] fix an mpegts scenario with unaligned pes Nicolas Gaullier
2024-02-20 16:33 ` [FFmpeg-devel] [PATCH 1/2] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets Nicolas Gaullier
2024-02-21  4:32   ` Michael Niedermayer
2024-02-23 12:52     ` Nicolas Gaullier
2024-02-20 16:33 ` [FFmpeg-devel] [PATCH 2/2] lavf/demux: duplicate side_data in parse_packet() Nicolas Gaullier

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git