movenc: Combine the fragmentation conditions with AND instead of OR

Message ID 1332180284-54562-2-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö March 19, 2012, 6:04 p.m.
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(-)

Patch

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);
     }