This makes the muxer cut fragments only once all the conditions
are fulfilled, not when either of them is.

This makes sense if one e.g. wants to cut at keyframes, but
only if the fragment is over a certain duration, while the
opposite (cut at keyframes, or at any packet after a certain
duration) is less useful.

Alternatively, a separate option for minimum fragment duration
could be added, which is taken as AND in addition to the other
conditions.
---
 libavformat/movenc.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 10bcedc..e6d59c2 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2837,14 +2837,15 @@ static int mov_write_packet_internal(AVFormatContext 
*s, AVPacket *pkt)
 
     if (!size) return 0; /* Discard 0 sized packets */
 
-    if ((mov->max_fragment_duration && trk->entry &&
+    if ((!mov->max_fragment_duration || (trk->entry &&
          av_rescale_q(pkt->dts - trk->cluster[0].dts,
                       s->streams[pkt->stream_index]->time_base,
-                      AV_TIME_BASE_Q) >= mov->max_fragment_duration) ||
-         (mov->max_fragment_size && mov->mdat_size + size >= 
mov->max_fragment_size) ||
-         (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME &&
+                      AV_TIME_BASE_Q) >= mov->max_fragment_duration)) &&
+         (!mov->max_fragment_size || mov->mdat_size + size >= 
mov->max_fragment_size) &&
+         (!(mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME) || (
           enc->codec_type == AVMEDIA_TYPE_VIDEO &&
-          trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) {
+          trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) &&
+         !(mov->flags & FF_MOV_FLAG_FRAG_CUSTOM)) {
         mov_flush_fragment(s);
     }
 
-- 
1.7.3.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to