This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new 7d77562d2a avformat/hlsenc: provide next packet timing before fMP4 
fragment flush
7d77562d2a is described below

commit 7d77562d2a18adca969431e5c870870eb8b5edb9
Author:     Kostazol <[email protected]>
AuthorDate: Wed Aug 19 23:00:57 2026 +0700
Commit:     stevenliu <[email protected]>
CommitDate: Thu Aug 20 07:19:13 2026 +0000

    avformat/hlsenc: provide next packet timing before fMP4 fragment flush
    
    Pass the next HLS boundary packet timing to the child MOV muxer before 
flushing an fMP4 fragment. The MOV helper only shrinks an overlapping 
accumulated fragment duration; normal boundaries remain unchanged and the 
boundary packet itself is not modified.
---
 libavformat/hlsenc.c |  8 ++++++++
 libavformat/movenc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 libavformat/movenc.h |  3 +++
 3 files changed, 53 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 50f19f9694..4726a4a708 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -53,6 +53,9 @@
 #include "hlsplaylist.h"
 #include "internal.h"
 #include "mux.h"
+#if CONFIG_MP4_MUXER
+#include "movenc.h"
+#endif
 #include "os_support.h"
 #include "url.h"
 
@@ -2520,6 +2523,11 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
         int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || 
(hls->max_seg_size > 0);
         double cur_duration;
 
+#if CONFIG_MP4_MUXER
+        if (hls->segment_type == SEGMENT_TYPE_FMP4 && is_ref_pkt &&
+            pkt->dts != AV_NOPTS_VALUE)
+            ff_mov_set_fragment_end_hint(oc, stream_index, pkt, st->time_base);
+#endif
         av_write_frame(oc, NULL); /* Flush any buffered data */
         new_start_pos = avio_tell(oc->pb);
         vs->size = new_start_pos - vs->start_pos;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 2a3226c70f..367caecee9 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6948,6 +6948,48 @@ static int check_pkt(AVFormatContext *s, MOVTrack *trk, 
AVPacket *pkt)
     return 0;
 }
 
+int ff_mov_set_fragment_end_hint(AVFormatContext *s, int stream_index,
+                                 const AVPacket *pkt, AVRational src_time_base)
+{
+    MOVMuxContext *mov = s->priv_data;
+    AVStream *st;
+    MOVTrack *track;
+    int64_t offset, dts, pts, candidate_duration;
+
+    if (!(mov->flags & FF_MOV_FLAG_FRAGMENT) ||
+        stream_index < 0 || stream_index >= s->nb_streams ||
+        pkt->dts == AV_NOPTS_VALUE)
+        return 0;
+
+    st = s->streams[stream_index];
+    track = st->priv_data;
+    if (!track->entry || track->start_dts == AV_NOPTS_VALUE)
+        return 0;
+
+    if (ff_get_muxer_ts_offset(s, stream_index, &offset) < 0)
+        return 0;
+
+    dts = av_rescale_q(pkt->dts, src_time_base, st->time_base) + offset;
+    pts = pkt->pts == AV_NOPTS_VALUE
+        ? AV_NOPTS_VALUE
+        : av_rescale_q(pkt->pts, src_time_base, st->time_base) + offset;
+    if (track->dts_shift != AV_NOPTS_VALUE)
+        dts += track->dts_shift;
+
+    candidate_duration = dts - track->start_dts;
+    if (dts <= track->cluster[track->entry - 1].dts ||
+        candidate_duration < 0 || candidate_duration >= track->track_duration)
+        return 0;
+
+    track->track_duration = candidate_duration;
+    track->end_pts = pts != AV_NOPTS_VALUE ? pts : dts;
+    if (!(pkt->flags & AV_PKT_FLAG_DISCARD))
+        track->elst_end_pts = track->end_pts;
+    track->end_reliable = 1;
+
+    return 1;
+}
+
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     MOVMuxContext *mov = s->priv_data;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 5d1e7099b4..c375659c93 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -303,6 +303,9 @@ typedef struct MOVMuxContext {
 
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
 
+int ff_mov_set_fragment_end_hint(AVFormatContext *s, int stream_index,
+                                 const AVPacket *pkt, AVRational 
src_time_base);
+
 int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index);
 int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
                              int track_index, int sample,

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to