[10/18] mov: Don't use a negative duration for setting other fields

Message ID 1379358389-64839-10-git-send-email-martin@martin.st
State Committed
Commit 7f8d41eb097e8d4223c9caf97dd332a2fdb29d52
Headers show

Commit Message

Martin Storsjö Sept. 16, 2013, 7:06 p.m.
Some files have the duration set to -1 in the mdhd atom, more
or less legitimately. (We produce such files ourselves, for the
initial duration in fragmented mp4 files.)

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
---
 libavformat/mov.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Luca Barbato Sept. 16, 2013, 9:38 p.m. | #1
On 16/09/13 21:06, Martin Storsjö wrote:
> Some files have the duration set to -1 in the mdhd atom, more
> or less legitimately. (We produce such files ourselves, for the
> initial duration in fragmented mp4 files.)
> 

Ok.

Patch

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 9c72426..77ba444 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2130,7 +2130,7 @@  static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
                                              ((double)st->codec->width * sc->height), INT_MAX);
         }
 
-        if (st->duration != AV_NOPTS_VALUE)
+        if (st->duration != AV_NOPTS_VALUE && st->duration > 0)
             av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
                       sc->time_scale*st->nb_frames, st->duration, INT_MAX);
     }
@@ -2863,7 +2863,7 @@  static int mov_read_header(AVFormatContext *s)
         for (i = 0; i < s->nb_streams; i++) {
             AVStream *st = s->streams[i];
             MOVStreamContext *sc = st->priv_data;
-            if (st->duration)
+            if (st->duration > 0)
                 st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration;
         }
     }