[FFmpeg-devel] [PATCH] avformat/movenc: Don't auto flush fragment if no frame available

Hu Weiwen sehuww at mail.scut.edu.cn
Mon Aug 9 17:23:42 EEST 2021


Even if FF_MOV_FLAG_FRAG_EVERY_FRAME is set, don't flush if no frame available.

This fixes an issue that we overwrite the track duration, causing it to be
out-of-sync with the last written packet in previous fragment.

Signed-off-by: Hu Weiwen <sehuww at mail.scut.edu.cn>
---
Hi Martin,

I can confirm your patch "movenc: Don't try to fix the fragment end duration if none will be written"[1] does fix my
issue reported in [2]. But I think my current patch would be a better fix. It is more self-explanatory, and more
consistent in the case of FF_MOV_FLAG_FRAG_KEYFRAME.

Also, I think my original patch [2] still has its value. "frag_start" seems to be redundant, and it is only updated
relative to its previous value. This is bad because any potential error updating it will have infinite impact on future
packets.

[1]: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210805123421.10527-1-martin@martin.st/
[2]: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210718102232.1382376-1-sehuww@mail.scut.edu.cn/

 libavformat/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 57062f45c57..72fe8df12c2 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5929,7 +5929,7 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt)
             (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME &&
              par->codec_type == AVMEDIA_TYPE_VIDEO &&
              trk->entry && pkt->flags & AV_PKT_FLAG_KEY) ||
-            (mov->flags & FF_MOV_FLAG_FRAG_EVERY_FRAME)) {
+            (mov->flags & FF_MOV_FLAG_FRAG_EVERY_FRAME && trk->entry)) {
         if (frag_duration >= mov->min_fragment_duration) {
             // Set the duration of this track to line up with the next
             // sample in this track. This avoids relying on AVPacket
-- 
2.25.1



More information about the ffmpeg-devel mailing list