movenc: fix crashes if a stream is empty.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 12 Feb 2012 11:05:43 +0000 (12:05 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Fri, 17 Feb 2012 16:04:10 +0000 (17:04 +0100)
For some reason this always happens with -f ismv.
See trac issue #996.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
libavformat/movenc.c

index 1f56fe1..d1337a0 100644 (file)
@@ -287,6 +287,8 @@ static unsigned compute_avg_bitrate(MOVTrack *track)
 {
     uint64_t size = 0;
     int i;
+    if (!track->track_duration)
+        return 0;
     for (i = 0; i < track->entry; i++)
         size += track->cluster[i].size;
     return size * 8 * track->timescale / track->track_duration;
@@ -2052,7 +2054,8 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
         mov->tracks[i].time = mov->time;
         mov->tracks[i].track_id = i+1;
 
-        build_chunks(&mov->tracks[i]);
+        if (mov->tracks[i].entry)
+            build_chunks(&mov->tracks[i]);
     }
 
     if (mov->chapter_track)