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

* [FFmpeg-devel] [PATCH 1/2] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets
  2024-02-20 16:33 [FFmpeg-devel] [PATCH 0/2] fix an mpegts scenario with unaligned pes Nicolas Gaullier
@ 2024-02-20 16:33 ` Nicolas Gaullier
  2024-02-21  4:32   ` Michael Niedermayer
  2024-02-20 16:33 ` [FFmpeg-devel] [PATCH 2/2] lavf/demux: duplicate side_data in parse_packet() Nicolas Gaullier
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Gaullier @ 2024-02-20 16:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Nicolas Gaullier

Fix fetch_timestamp when the frame start is in a previous packet.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 libavcodec/parser.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index efc28b8918..853b5323b0 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -153,11 +153,11 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
     }
 
     if (s->fetch_timestamp) {
-        s->fetch_timestamp = 0;
         s->last_pts        = s->pts;
         s->last_dts        = s->dts;
         s->last_pos        = s->pos;
-        ff_fetch_timestamp(s, 0, 0, 0);
+        ff_fetch_timestamp(s, FFMIN(s->fetch_timestamp, 0), 0, 0);
+        s->fetch_timestamp = 0;
     }
     /* WARNING: the returned index can be negative */
     index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf,
@@ -179,7 +179,7 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
 
         /* offset of the next frame */
         s->next_frame_offset = s->cur_offset + index;
-        s->fetch_timestamp   = 1;
+        s->fetch_timestamp   = index >= 0 ? 1 : index;
     } else {
         /* Don't return a pointer to dummy_buf. */
         *poutbuf = NULL;
-- 
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

* [FFmpeg-devel] [PATCH 2/2] lavf/demux: duplicate side_data in parse_packet()
  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-20 16:33 ` Nicolas Gaullier
  1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Gaullier @ 2024-02-20 16:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Nicolas Gaullier

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 libavformat/demux.c                           |  23 ++-
 tests/ref/fate/concat-demuxer-simple2-lavf-ts | 164 +++++++++---------
 tests/ref/fate/ts-demux                       |   8 +-
 3 files changed, 104 insertions(+), 91 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2e1d0ed66d..722bb35c4c 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1186,7 +1186,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
     FFStream *const sti = ffstream(st);
     const uint8_t *data = pkt->data;
     int size = pkt->size;
-    int ret = 0, got_output = flush;
+    int ret = 0, got_output = flush, pkt_side_data_consumed = 0;
 
     if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         // preserve 0-size sync packets
@@ -1231,10 +1231,19 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
         }
 
         if (pkt->side_data) {
-            out_pkt->side_data       = pkt->side_data;
-            out_pkt->side_data_elems = pkt->side_data_elems;
-            pkt->side_data          = NULL;
-            pkt->side_data_elems    = 0;
+            if (!pkt_side_data_consumed) {
+                out_pkt->side_data       = pkt->side_data;
+                out_pkt->side_data_elems = pkt->side_data_elems;
+                pkt_side_data_consumed = 1;
+            } else for (int i = 0; i < pkt->side_data_elems; i++) {
+                const AVPacketSideData *const src_sd = &pkt->side_data[i];
+                uint8_t *dst_data = av_packet_new_side_data(out_pkt, src_sd->type, src_sd->size);
+                if (!dst_data) {
+                    ret = AVERROR(ENOMEM);
+                    goto fail;
+                }
+                memcpy(dst_data, src_sd->data, src_sd->size);
+            }
         }
 
         /* set the duration */
@@ -1286,6 +1295,10 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
     }
 
 fail:
+    if (pkt_side_data_consumed) {
+        pkt->side_data          = NULL;
+        pkt->side_data_elems    = 0;
+    }
     if (ret < 0)
         av_packet_unref(out_pkt);
     av_packet_unref(pkt);
diff --git a/tests/ref/fate/concat-demuxer-simple2-lavf-ts b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
index 548cab01c6..ee49e331f3 100644
--- a/tests/ref/fate/concat-demuxer-simple2-lavf-ts
+++ b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
@@ -7,19 +7,19 @@ video|1|18982|0.210911|15382|0.170911|3600|0.040000|13092|84788|___|MPEGTS Strea
 video|1|22582|0.250911|18982|0.210911|3600|0.040000|12755|98700|___|MPEGTS Stream ID|224
 video|1|26182|0.290911|22582|0.250911|3600|0.040000|12023|111860|___|MPEGTS Stream ID|224
 audio|0|0|0.000000|0|0.000000|2351|0.026122|208|152844|K__|MPEGTS Stream ID|192
-audio|0|2351|0.026122|2351|0.026122|2351|0.026122|209|N/A|K__
-audio|0|4702|0.052244|4702|0.052244|2351|0.026122|209|N/A|K__
-audio|0|7053|0.078367|7053|0.078367|2351|0.026122|209|N/A|K__
-audio|0|9404|0.104489|9404|0.104489|2351|0.026122|209|N/A|K__
-audio|0|11755|0.130611|11755|0.130611|2351|0.026122|209|N/A|K__
-audio|0|14106|0.156733|14106|0.156733|2351|0.026122|209|N/A|K__
-audio|0|16457|0.182856|16457|0.182856|2351|0.026122|209|N/A|K__
-audio|0|18808|0.208978|18808|0.208978|2351|0.026122|209|N/A|K__
-audio|0|21159|0.235100|21159|0.235100|2351|0.026122|209|N/A|K__
-audio|0|23510|0.261222|23510|0.261222|2351|0.026122|209|N/A|K__
-audio|0|25861|0.287344|25861|0.287344|2351|0.026122|209|N/A|K__
-audio|0|28212|0.313467|28212|0.313467|2351|0.026122|209|N/A|K__
-audio|0|30563|0.339589|30563|0.339589|2351|0.026122|209|N/A|K__
+audio|0|2351|0.026122|2351|0.026122|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|4702|0.052244|4702|0.052244|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|7053|0.078367|7053|0.078367|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|9404|0.104489|9404|0.104489|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|11755|0.130611|11755|0.130611|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|14106|0.156733|14106|0.156733|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|16457|0.182856|16457|0.182856|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|18808|0.208978|18808|0.208978|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|21159|0.235100|21159|0.235100|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|23510|0.261222|23510|0.261222|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|25861|0.287344|25861|0.287344|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|28212|0.313467|28212|0.313467|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|30563|0.339589|30563|0.339589|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|29782|0.330911|26182|0.290911|3600|0.040000|14098|124268|___|MPEGTS Stream ID|224
 video|1|33382|0.370911|29782|0.330911|3600|0.040000|13329|139120|___|MPEGTS Stream ID|224
 video|1|36982|0.410911|33382|0.370911|3600|0.040000|12135|155852|___|MPEGTS Stream ID|224
@@ -31,35 +31,35 @@ video|1|54982|0.610911|51382|0.570911|3600|0.040000|13449|240640|___|MPEGTS Stre
 video|1|58582|0.650911|54982|0.610911|3600|0.040000|12398|254552|___|MPEGTS Stream ID|224
 video|1|62182|0.690911|58582|0.650911|3600|0.040000|13455|267336|___|MPEGTS Stream ID|224
 audio|0|32915|0.365722|32915|0.365722|2351|0.026122|209|308508|K__|MPEGTS Stream ID|192
-audio|0|35266|0.391844|35266|0.391844|2351|0.026122|209|N/A|K__
-audio|0|37617|0.417967|37617|0.417967|2351|0.026122|209|N/A|K__
-audio|0|39968|0.444089|39968|0.444089|2351|0.026122|209|N/A|K__
-audio|0|42319|0.470211|42319|0.470211|2351|0.026122|209|N/A|K__
-audio|0|44670|0.496333|44670|0.496333|2351|0.026122|209|N/A|K__
-audio|0|47021|0.522456|47021|0.522456|2351|0.026122|209|N/A|K__
-audio|0|49372|0.548578|49372|0.548578|2351|0.026122|209|N/A|K__
-audio|0|51723|0.574700|51723|0.574700|2351|0.026122|209|N/A|K__
-audio|0|54074|0.600822|54074|0.600822|2351|0.026122|209|N/A|K__
-audio|0|56425|0.626944|56425|0.626944|2351|0.026122|209|N/A|K__
-audio|0|58776|0.653067|58776|0.653067|2351|0.026122|209|N/A|K__
-audio|0|61127|0.679189|61127|0.679189|2351|0.026122|209|N/A|K__
-audio|0|63478|0.705311|63478|0.705311|2351|0.026122|209|N/A|K__
+audio|0|35266|0.391844|35266|0.391844|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|37617|0.417967|37617|0.417967|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|39968|0.444089|39968|0.444089|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|42319|0.470211|42319|0.470211|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|44670|0.496333|44670|0.496333|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|47021|0.522456|47021|0.522456|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|49372|0.548578|49372|0.548578|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|51723|0.574700|51723|0.574700|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|54074|0.600822|54074|0.600822|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|56425|0.626944|56425|0.626944|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|58776|0.653067|58776|0.653067|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|61127|0.679189|61127|0.679189|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|63478|0.705311|63478|0.705311|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|65782|0.730911|62182|0.690911|3600|0.040000|13836|281624|___|MPEGTS Stream ID|224
 video|1|69382|0.770911|65782|0.730911|3600|0.040000|12163|295912|___|MPEGTS Stream ID|224
 video|1|72982|0.810911|69382|0.770911|3600|0.040000|12692|311516|___|MPEGTS Stream ID|224
 video|1|76582|0.850911|72982|0.810911|3600|0.040000|10824|325052|___|MPEGTS Stream ID|224
 video|1|80182|0.890911|76582|0.850911|3600|0.040000|11286|336144|___|MPEGTS Stream ID|224
 audio|0|65829|0.731433|65829|0.731433|2351|0.026122|209|386716|K__|MPEGTS Stream ID|192
-audio|0|68180|0.757556|68180|0.757556|2351|0.026122|209|N/A|K__
-audio|0|70531|0.783678|70531|0.783678|2351|0.026122|209|N/A|K__
-audio|0|72882|0.809800|72882|0.809800|2351|0.026122|209|N/A|K__
-audio|0|75233|0.835922|75233|0.835922|2351|0.026122|209|N/A|K__
-audio|0|77584|0.862044|77584|0.862044|2351|0.026122|209|N/A|K__
-audio|0|79935|0.888167|79935|0.888167|2351|0.026122|209|N/A|K__
-audio|0|82286|0.914289|82286|0.914289|2351|0.026122|209|N/A|K__
-audio|0|84637|0.940411|84637|0.940411|2351|0.026122|209|N/A|K__
-audio|0|86988|0.966533|86988|0.966533|2351|0.026122|209|N/A|K__
-audio|0|89339|0.992656|89339|0.992656|2351|0.026122|209|N/A|K__
+audio|0|68180|0.757556|68180|0.757556|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|70531|0.783678|70531|0.783678|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|72882|0.809800|72882|0.809800|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|75233|0.835922|75233|0.835922|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|77584|0.862044|77584|0.862044|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|79935|0.888167|79935|0.888167|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|82286|0.914289|82286|0.914289|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|84637|0.940411|84637|0.940411|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|86988|0.966533|86988|0.966533|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|89339|0.992656|89339|0.992656|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|83782|0.930911|80182|0.890911|3600|0.040000|12678|347800|___|MPEGTS Stream ID|224
 video|1|87382|0.970911|83782|0.930911|3600|0.040000|24711|361336|K__
 video|1|91964|1.021822|88364|0.981822|3600|0.040000|24801|564|K__|MPEGTS Stream ID|224
@@ -71,19 +71,19 @@ video|1|109964|1.221822|106364|1.181822|3600|0.040000|13092|84788|___|MPEGTS Str
 video|1|113564|1.261822|109964|1.221822|3600|0.040000|12755|98700|___|MPEGTS Stream ID|224
 video|1|117164|1.301822|113564|1.261822|3600|0.040000|12023|111860|___|MPEGTS Stream ID|224
 audio|0|90982|1.010911|90982|1.010911|2351|0.026122|208|152844|K__|MPEGTS Stream ID|192
-audio|0|93333|1.037033|93333|1.037033|2351|0.026122|209|N/A|K__
-audio|0|95684|1.063156|95684|1.063156|2351|0.026122|209|N/A|K__
-audio|0|98035|1.089278|98035|1.089278|2351|0.026122|209|N/A|K__
-audio|0|100386|1.115400|100386|1.115400|2351|0.026122|209|N/A|K__
-audio|0|102737|1.141522|102737|1.141522|2351|0.026122|209|N/A|K__
-audio|0|105088|1.167644|105088|1.167644|2351|0.026122|209|N/A|K__
-audio|0|107439|1.193767|107439|1.193767|2351|0.026122|209|N/A|K__
-audio|0|109790|1.219889|109790|1.219889|2351|0.026122|209|N/A|K__
-audio|0|112141|1.246011|112141|1.246011|2351|0.026122|209|N/A|K__
-audio|0|114492|1.272133|114492|1.272133|2351|0.026122|209|N/A|K__
-audio|0|116843|1.298256|116843|1.298256|2351|0.026122|209|N/A|K__
-audio|0|119194|1.324378|119194|1.324378|2351|0.026122|209|N/A|K__
-audio|0|121545|1.350500|121545|1.350500|2351|0.026122|209|N/A|K__
+audio|0|93333|1.037033|93333|1.037033|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|95684|1.063156|95684|1.063156|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|98035|1.089278|98035|1.089278|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|100386|1.115400|100386|1.115400|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|102737|1.141522|102737|1.141522|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|105088|1.167644|105088|1.167644|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|107439|1.193767|107439|1.193767|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|109790|1.219889|109790|1.219889|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|112141|1.246011|112141|1.246011|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|114492|1.272133|114492|1.272133|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|116843|1.298256|116843|1.298256|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|119194|1.324378|119194|1.324378|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|121545|1.350500|121545|1.350500|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|120764|1.341822|117164|1.301822|3600|0.040000|14098|124268|___|MPEGTS Stream ID|224
 video|1|124364|1.381822|120764|1.341822|3600|0.040000|13329|139120|___|MPEGTS Stream ID|224
 video|1|127964|1.421822|124364|1.381822|3600|0.040000|12135|155852|___|MPEGTS Stream ID|224
@@ -95,51 +95,51 @@ video|1|145964|1.621822|142364|1.581822|3600|0.040000|13449|240640|___|MPEGTS St
 video|1|149564|1.661822|145964|1.621822|3600|0.040000|12398|254552|___|MPEGTS Stream ID|224
 video|1|153164|1.701822|149564|1.661822|3600|0.040000|13455|267336|___|MPEGTS Stream ID|224
 audio|0|123897|1.376633|123897|1.376633|2351|0.026122|209|308508|K__|MPEGTS Stream ID|192
-audio|0|126248|1.402756|126248|1.402756|2351|0.026122|209|N/A|K__
-audio|0|128599|1.428878|128599|1.428878|2351|0.026122|209|N/A|K__
-audio|0|130950|1.455000|130950|1.455000|2351|0.026122|209|N/A|K__
-audio|0|133301|1.481122|133301|1.481122|2351|0.026122|209|N/A|K__
-audio|0|135652|1.507244|135652|1.507244|2351|0.026122|209|N/A|K__
-audio|0|138003|1.533367|138003|1.533367|2351|0.026122|209|N/A|K__
-audio|0|140354|1.559489|140354|1.559489|2351|0.026122|209|N/A|K__
-audio|0|142705|1.585611|142705|1.585611|2351|0.026122|209|N/A|K__
-audio|0|145056|1.611733|145056|1.611733|2351|0.026122|209|N/A|K__
-audio|0|147407|1.637856|147407|1.637856|2351|0.026122|209|N/A|K__
-audio|0|149758|1.663978|149758|1.663978|2351|0.026122|209|N/A|K__
-audio|0|152109|1.690100|152109|1.690100|2351|0.026122|209|N/A|K__
-audio|0|154460|1.716222|154460|1.716222|2351|0.026122|209|N/A|K__
+audio|0|126248|1.402756|126248|1.402756|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|128599|1.428878|128599|1.428878|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|130950|1.455000|130950|1.455000|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|133301|1.481122|133301|1.481122|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|135652|1.507244|135652|1.507244|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|138003|1.533367|138003|1.533367|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|140354|1.559489|140354|1.559489|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|142705|1.585611|142705|1.585611|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|145056|1.611733|145056|1.611733|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|147407|1.637856|147407|1.637856|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|149758|1.663978|149758|1.663978|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|152109|1.690100|152109|1.690100|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|154460|1.716222|154460|1.716222|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|156764|1.741822|153164|1.701822|3600|0.040000|13836|281624|___|MPEGTS Stream ID|224
 video|1|160364|1.781822|156764|1.741822|3600|0.040000|12163|295912|___|MPEGTS Stream ID|224
 video|1|163964|1.821822|160364|1.781822|3600|0.040000|12692|311516|___|MPEGTS Stream ID|224
 video|1|167564|1.861822|163964|1.821822|3600|0.040000|10824|325052|___|MPEGTS Stream ID|224
 video|1|171164|1.901822|167564|1.861822|3600|0.040000|11286|336144|___|MPEGTS Stream ID|224
 audio|0|156811|1.742344|156811|1.742344|2351|0.026122|209|386716|K__|MPEGTS Stream ID|192
-audio|0|159162|1.768467|159162|1.768467|2351|0.026122|209|N/A|K__
-audio|0|161513|1.794589|161513|1.794589|2351|0.026122|209|N/A|K__
-audio|0|163864|1.820711|163864|1.820711|2351|0.026122|209|N/A|K__
-audio|0|166215|1.846833|166215|1.846833|2351|0.026122|209|N/A|K__
-audio|0|168566|1.872956|168566|1.872956|2351|0.026122|209|N/A|K__
-audio|0|170917|1.899078|170917|1.899078|2351|0.026122|209|N/A|K__
-audio|0|173268|1.925200|173268|1.925200|2351|0.026122|209|N/A|K__
-audio|0|175619|1.951322|175619|1.951322|2351|0.026122|209|N/A|K__
-audio|0|177970|1.977444|177970|1.977444|2351|0.026122|209|N/A|K__
-audio|0|180321|2.003567|180321|2.003567|2351|0.026122|209|N/A|K__
+audio|0|159162|1.768467|159162|1.768467|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|161513|1.794589|161513|1.794589|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|163864|1.820711|163864|1.820711|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|166215|1.846833|166215|1.846833|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|168566|1.872956|168566|1.872956|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|170917|1.899078|170917|1.899078|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|173268|1.925200|173268|1.925200|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|175619|1.951322|175619|1.951322|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|177970|1.977444|177970|1.977444|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|180321|2.003567|180321|2.003567|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|174764|1.941822|171164|1.901822|3600|0.040000|12678|347800|___|MPEGTS Stream ID|224
 video|1|178364|1.981822|174764|1.941822|3600|0.040000|24711|361336|K__
 video|1|139582|1.550911|135982|1.510911|3600|0.040000|12692|311516|___|MPEGTS Stream ID|224
 video|1|143182|1.590911|139582|1.550911|3600|0.040000|10824|325052|___|MPEGTS Stream ID|224
 video|1|146782|1.630911|143182|1.590911|3600|0.040000|11286|336144|___|MPEGTS Stream ID|224
 audio|0|132429|1.471433|132429|1.471433|2351|0.026122|209|386716|K__|MPEGTS Stream ID|192
-audio|0|134780|1.497556|134780|1.497556|2351|0.026122|209|N/A|K__
-audio|0|137131|1.523678|137131|1.523678|2351|0.026122|209|N/A|K__
-audio|0|139482|1.549800|139482|1.549800|2351|0.026122|209|N/A|K__
-audio|0|141833|1.575922|141833|1.575922|2351|0.026122|209|N/A|K__
-audio|0|144184|1.602044|144184|1.602044|2351|0.026122|209|N/A|K__
-audio|0|146535|1.628167|146535|1.628167|2351|0.026122|209|N/A|K__
-audio|0|148886|1.654289|148886|1.654289|2351|0.026122|209|N/A|K__
-audio|0|151237|1.680411|151237|1.680411|2351|0.026122|209|N/A|K__
-audio|0|153588|1.706533|153588|1.706533|2351|0.026122|209|N/A|K__
-audio|0|155939|1.732656|155939|1.732656|2351|0.026122|209|N/A|K__
+audio|0|134780|1.497556|134780|1.497556|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|137131|1.523678|137131|1.523678|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|139482|1.549800|139482|1.549800|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|141833|1.575922|141833|1.575922|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|144184|1.602044|144184|1.602044|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|146535|1.628167|146535|1.628167|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|148886|1.654289|148886|1.654289|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|151237|1.680411|151237|1.680411|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|153588|1.706533|153588|1.706533|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
+audio|0|155939|1.732656|155939|1.732656|2351|0.026122|209|N/A|K__|MPEGTS Stream ID|192
 video|1|150382|1.670911|146782|1.630911|3600|0.040000|12678|347800|___|MPEGTS Stream ID|224
 video|1|153982|1.710911|150382|1.670911|3600|0.040000|24711|361336|K__
 video|1|161182|1.790911|157582|1.750911|3600|0.040000|12135|155852|___|MPEGTS Stream ID|224
diff --git a/tests/ref/fate/ts-demux b/tests/ref/fate/ts-demux
index b01f525c38..4274a0e145 100644
--- a/tests/ref/fate/ts-demux
+++ b/tests/ref/fate/ts-demux
@@ -10,11 +10,11 @@ packet|codec_type=video|stream_index=0|pts=3912677354|pts_time=43474.192822|dts=
 packet|codec_type=video|stream_index=0|pts=3912683360|pts_time=43474.259556|dts=3912678855|dts_time=43474.209500|duration=1501|duration_time=0.016678|size=61720|pos=325240|flags=___|data_hash=CRC32:7e6594e5|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=224
 packet|codec_type=video|stream_index=0|pts=3912680357|pts_time=43474.226189|dts=3912680357|dts_time=43474.226189|duration=1501|duration_time=0.016678|size=17416|pos=390852|flags=___|data_hash=CRC32:31c8b89d|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=224
 packet|codec_type=audio|stream_index=1|pts=3912633305|pts_time=43473.703389|dts=3912633305|dts_time=43473.703389|duration=2880|duration_time=0.032000|size=1536|pos=218080|flags=K__|data_hash=CRC32:25b60d38|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=189
-packet|codec_type=audio|stream_index=1|pts=3912636185|pts_time=43473.735389|dts=3912636185|dts_time=43473.735389|duration=2880|duration_time=0.032000|size=1536|pos=N/A|flags=K__|data_hash=CRC32:d4e30aaf
-packet|codec_type=audio|stream_index=1|pts=3912639065|pts_time=43473.767389|dts=3912639065|dts_time=43473.767389|duration=2880|duration_time=0.032000|size=1536|pos=N/A|flags=K__|data_hash=CRC32:32d6d14d
+packet|codec_type=audio|stream_index=1|pts=3912636185|pts_time=43473.735389|dts=3912636185|dts_time=43473.735389|duration=2880|duration_time=0.032000|size=1536|pos=N/A|flags=K__|data_hash=CRC32:d4e30aaf|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=189
+packet|codec_type=audio|stream_index=1|pts=3912639065|pts_time=43473.767389|dts=3912639065|dts_time=43473.767389|duration=2880|duration_time=0.032000|size=1536|pos=N/A|flags=K__|data_hash=CRC32:32d6d14d|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=189
 packet|codec_type=audio|stream_index=2|pts=3912634060|pts_time=43473.711778|dts=3912634060|dts_time=43473.711778|duration=2880|duration_time=0.032000|size=768|pos=235564|flags=K__|data_hash=CRC32:34b350c9|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=189
-packet|codec_type=audio|stream_index=2|pts=3912636940|pts_time=43473.743778|dts=3912636940|dts_time=43473.743778|duration=2880|duration_time=0.032000|size=768|pos=N/A|flags=K__|data_hash=CRC32:457881f8
-packet|codec_type=audio|stream_index=2|pts=3912639820|pts_time=43473.775778|dts=3912639820|dts_time=43473.775778|duration=2880|duration_time=0.032000|size=768|pos=N/A|flags=K__|data_hash=CRC32:1abb0d9a
+packet|codec_type=audio|stream_index=2|pts=3912636940|pts_time=43473.743778|dts=3912636940|dts_time=43473.743778|duration=2880|duration_time=0.032000|size=768|pos=N/A|flags=K__|data_hash=CRC32:457881f8|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=189
+packet|codec_type=audio|stream_index=2|pts=3912639820|pts_time=43473.775778|dts=3912639820|dts_time=43473.775778|duration=2880|duration_time=0.032000|size=768|pos=N/A|flags=K__|data_hash=CRC32:1abb0d9a|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=189
 packet|codec_type=video|stream_index=0|pts=3912681858|pts_time=43474.242867|dts=3912681858|dts_time=43474.242867|duration=1501|duration_time=0.016678|size=18144|pos=409464|flags=___|data_hash=CRC32:826f8e8e|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=224
 packet|codec_type=video|stream_index=0|pts=3912687864|pts_time=43474.309600|dts=3912683360|dts_time=43474.259556|duration=1501|duration_time=0.016678|size=56848|pos=428640|flags=___|data_hash=CRC32:6b15be8c|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=224
 packet|codec_type=video|stream_index=0|pts=3912684861|pts_time=43474.276233|dts=3912684861|dts_time=43474.276233|duration=1501|duration_time=0.016678|size=16296|pos=489176|flags=___|data_hash=CRC32:911b1649|side_datum/mpegts_stream_id:side_data_type=MPEGTS Stream ID|side_datum/mpegts_stream_id:id=224
-- 
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

* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Niedermayer @ 2024-02-21  4:32 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 2506 bytes --]

On Tue, Feb 20, 2024 at 05:33:01PM +0100, Nicolas Gaullier wrote:
> Fix fetch_timestamp when the frame start is in a previous packet.
> 
> Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
> ---
>  libavcodec/parser.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

This change looses pts

--- /tmp/old	2024-02-21 05:21:13.201646780 +0100
+++ /tmp/new	2024-02-21 05:20:52.205417887 +0100
@@ -1,174 +1,172 @@
 [mpegts  read_frame_internal stream=2, pts=310332330, dts=310332330, size=49072, duration=0, flags=0
-[mpegts  read_frame_internal stream=2, pts=310348800, dts=310348800, size=16516, duration=0, flags=0
-[mpegts  read_frame_internal stream=2, pts=310356000, dts=310356000, size=16876, duration=0, flags=0
-[mpegts  read_frame_internal stream=2, pts=310366800, dts=310366800, size=51652, duration=0, flags=0
-[mpegts  read_frame_internal stream=2, pts=310363200, dts=NOPTS, size=15588, duration=0, flags=0
-[mpegts  read_frame_internal stream=2, pts=310370400, dts=NOPTS, size=21476, duration=0, flags=0
-[mpegts  read_frame_internal stream=2, pts=310402800, dts=NOPTS, size=276868, duration=3600, flags=1
-[mpegts  read_frame_internal stream=2, pts=310388400, dts=NOPTS, size=85884, duration=3600, flags=0
-[mpegts  read_frame_internal stream=2, pts=310381200, dts=NOPTS, size=45761, duration=3600, flags=0
+[mpegts  read_frame_internal stream=2, pts=NOPTS, dts=NOPTS, size=16516, duration=0, flags=0
+[mpegts  read_frame_internal stream=2, pts=310348800, dts=310348800, size=16876, duration=0, flags=0
+[mpegts  read_frame_internal stream=2, pts=310356000, dts=310356000, size=51652, duration=0, flags=0
+[mpegts  read_frame_internal stream=2, pts=310366800, dts=310366800, size=15588, duration=0, flags=0
+[mpegts  read_frame_internal stream=2, pts=310363200, dts=NOPTS, size=21476, duration=0, flags=0
+[mpegts  read_frame_internal stream=2, pts=310370400, dts=NOPTS, size=276868, duration=3600, flags=1
+[mpegts  read_frame_internal stream=2, pts=NOPTS, dts=NOPTS, size=85884, duration=3600, flags=0
+[mpegts  read_frame_internal stream=2, pts=310388400, dts=NOPTS, size=45761, duration=3600, flags=0


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"You are 36 times more likely to die in a bathtub than at the hands of a
terrorist. Also, you are 2.5 times more likely to become a president and
2 times more likely to become an astronaut, than to die in a terrorist
attack." -- Thoughty2


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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

* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets
  2024-02-21  4:32   ` Michael Niedermayer
@ 2024-02-23 12:52     ` Nicolas Gaullier
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Gaullier @ 2024-02-23 12:52 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

>De : ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> De la part de Michael Niedermayer
>Envoyé : mercredi 21 février 2024 05:32
>On Tue, Feb 20, 2024 at 05:33:01PM +0100, Nicolas Gaullier wrote:
>> Fix fetch_timestamp when the frame start is in a previous packet.
>> 
>> Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
>> ---
>>  libavcodec/parser.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>
>This change looses pts

I missed it : some broken streams are missing the zero_byte which makes the current h264 parser code to borrow a terminating null byte in the previous frame if available.
It seems there is currently no issue with that behaviour, but with my patch fixing the fetch_timestamp mechanism, it becomes one.
So, what is somewhat tricky is to guess if we are facing a broken stream or a conformant stream which actually has its zero_byte in the previous frame.
In my experience (including the sample from Michael and a sample of mine where there is no available null byte at the end of the frame),
the "usual broken streams" are missing the zero_byte for the first NAL unit which is an AUD, but the following NAL still has this zero_byte.
The following patch is a proposal to detect and overcome such a situation:
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=10877
At the end, this patch is required to handle broken streams and thus prepare the ground for the fetch_timestamp patch.

Another option would be for example to handle the data_alignment_indicator in the mpegts demuxer to force the alignment (ex: with a parser state reset),
but it seems it would involve some big unhappy changes in the code, with demux and parser tied together. Moreover, I don't think it is reliable and there might exists
broken stream with unaligned packets that we would still like to support.

Any inputs concerning broken streams for other codecs is welcome. For example, it may be required to handle broken hevc streams alike h264 ones: I have no opinion/ samples for that matter.

Nicolas
_______________________________________________
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