]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cuvid.c
avformat/flvenc: Add () around &
[ffmpeg] / libavcodec / cuvid.c
index 120b04594598970af7a33a0aedda544955f2175b..19a7772258edf84b2d817d0810a08c81ab984e9a 100644 (file)
@@ -258,7 +258,10 @@ static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
         if (avpkt->pts != AV_NOPTS_VALUE) {
             cupkt.flags = CUVID_PKT_TIMESTAMP;
-            cupkt.timestamp = av_rescale_q(avpkt->pts, avctx->pkt_timebase, (AVRational){1, 10000000});
+            if (avctx->pkt_timebase.num && avctx->pkt_timebase.den)
+                cupkt.timestamp = av_rescale_q(avpkt->pts, avctx->pkt_timebase, (AVRational){1, 10000000});
+            else
+                cupkt.timestamp = avpkt->pts;
         }
     } else {
         cupkt.flags = CUVID_PKT_ENDOFSTREAM;
@@ -269,8 +272,13 @@ static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     av_packet_unref(&filtered_packet);
 
     if (ret < 0) {
-        if (ctx->internal_error)
-            ret = ctx->internal_error;
+        goto error;
+    }
+
+    // cuvidParseVideoData doesn't return an error just because stuff failed...
+    if (ctx->internal_error) {
+        av_log(avctx, AV_LOG_ERROR, "cuvid decode callback error\n");
+        ret = ctx->internal_error;
         goto error;
     }
 
@@ -363,7 +371,10 @@ static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
         frame->width = avctx->width;
         frame->height = avctx->height;
-        frame->pts = av_rescale_q(dispinfo.timestamp, (AVRational){1, 10000000}, avctx->pkt_timebase);
+        if (avctx->pkt_timebase.num && avctx->pkt_timebase.den)
+            frame->pts = av_rescale_q(dispinfo.timestamp, (AVRational){1, 10000000}, avctx->pkt_timebase);
+        else
+            frame->pts = dispinfo.timestamp;
 
         /* CUVIDs opaque reordering breaks the internal pkt logic.
          * So set pkt_pts and clear all the other pkt_ fields.
@@ -679,6 +690,9 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
 
     ctx->ever_flushed = 0;
 
+    if (!avctx->pkt_timebase.num || !avctx->pkt_timebase.den)
+        av_log(avctx, AV_LOG_WARNING, "Invalid pkt_timebase, passing timestamps as-is.\n");
+
     return 0;
 
 error: