diff mbox

[FFmpeg-devel] fftools/ffmpeg: Check AVPacket->duration for being positive not just non zero

Message ID 20180517002219.2037-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer May 17, 2018, 12:22 a.m. UTC
Some demuxers (mov, microdvd at least) set duration negative.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 fftools/ffmpeg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Derek Buitenhuis May 17, 2018, 2:01 p.m. UTC | #1
On Thu, May 17, 2018 at 1:22 AM, Michael Niedermayer
<michael@niedermayer.cc> wrote:
> Some demuxers (mov, microdvd at least) set duration negative.
>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  fftools/ffmpeg.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

The patch itself seems reasonable, though I am curious when
the mov demuxer produces negative durations. Is it due to edit
list applications / discard packets, or is it just read in directly
from the mov's sample duration box?

- Derek
diff mbox

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5a19a09d9a..3aa2175b5d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2619,7 +2619,7 @@  static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             ret = decode_video    (ist, repeating ? NULL : &avpkt, &got_output, &duration_pts, !pkt,
                                    &decode_failed);
             if (!repeating || !pkt || got_output) {
-                if (pkt && pkt->duration) {
+                if (pkt && pkt->duration > 0) {
                     duration_dts = av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
                 } else if(ist->dec_ctx->framerate.num != 0 && ist->dec_ctx->framerate.den != 0) {
                     int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict+1 : ist->dec_ctx->ticks_per_frame;
@@ -2715,7 +2715,7 @@  static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
                 AVRational time_base_q = AV_TIME_BASE_Q;
                 int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
                 ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
-            } else if (pkt->duration) {
+            } else if (pkt->duration > 0) {
                 ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
             } else if(ist->dec_ctx->framerate.num != 0) {
                 int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame;