[FFmpeg-cvslog] lavc: use AVFrame.duration instead of AVFrame.pkt_duration

Anton Khirnov git at videolan.org
Tue Jul 19 13:36:42 EEST 2022


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Jul 11 10:20:12 2022 +0200| [ac2cda4296dbbaf2580ec3aa404bb2f3a393159c] | committer: Anton Khirnov

lavc: use AVFrame.duration instead of AVFrame.pkt_duration

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ac2cda4296dbbaf2580ec3aa404bb2f3a393159c
---

 libavcodec/crystalhd.c |  2 +-
 libavcodec/cuviddec.c  |  2 +-
 libavcodec/decode.c    | 14 ++++++++++----
 libavcodec/encode.c    | 11 ++++++++++-
 libavcodec/gifdec.c    |  2 +-
 libavcodec/libdav1d.c  |  2 +-
 libavcodec/mfenc.c     |  2 +-
 libavcodec/rawdec.c    |  2 +-
 8 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c
index 555b1d2b6b..bdc2ecc116 100644
--- a/libavcodec/crystalhd.c
+++ b/libavcodec/crystalhd.c
@@ -546,7 +546,7 @@ static inline CopyRet copy_frame(AVCodecContext *avctx,
     frame->pts = pkt_pts;
 
     frame->pkt_pos = -1;
-    frame->pkt_duration = 0;
+    frame->duration = 0;
     frame->pkt_size = -1;
 
     if (!priv->need_second_field) {
diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 7dbd4c9ec1..82c40fc64e 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -624,7 +624,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
          * So set pkt_pts and clear all the other pkt_ fields.
          */
         frame->pkt_pos = -1;
-        frame->pkt_duration = 0;
+        frame->duration = 0;
         frame->pkt_size = -1;
 
         frame->interlaced_frame = !parsed_frame.is_deinterlacing && !parsed_frame.dispinfo.progressive_frame;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 1893caa6a6..14ce4c2e2f 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -394,8 +394,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
                         frame->pts += diff_ts;
                     if(frame->pkt_dts!=AV_NOPTS_VALUE)
                         frame->pkt_dts += diff_ts;
-                    if (frame->pkt_duration >= diff_ts)
-                        frame->pkt_duration -= diff_ts;
+                    if (frame->duration >= diff_ts)
+                        frame->duration -= diff_ts;
                 } else {
                     av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
                 }
@@ -417,7 +417,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                     int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
                                                    (AVRational){1, avctx->sample_rate},
                                                    avctx->pkt_timebase);
-                    frame->pkt_duration = diff_ts;
+                    frame->duration = diff_ts;
                 } else {
                     av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
                 }
@@ -549,6 +549,12 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
                                                          frame->pts,
                                                          frame->pkt_dts);
 
+#if FF_API_PKT_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
+        frame->pkt_duration = frame->duration;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
         /* the only case where decode data is not set should be decoders
          * that do not call ff_get_buffer() */
         av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
@@ -1267,7 +1273,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
     if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
         frame->pts = pkt->pts;
         frame->pkt_pos      = pkt->pos;
-        frame->pkt_duration = pkt->duration;
+        frame->duration     = pkt->duration;
         frame->pkt_size     = pkt->size;
 
         for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 1f39ab1a2f..310fe20777 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -339,7 +339,7 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
                     return ret;
 
                 avctx->internal->last_audio_frame = 1;
-                return 0;
+                goto finish;
             } else if (src->nb_samples > avctx->frame_size) {
                 av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d)\n", src->nb_samples, avctx->frame_size);
                 return AVERROR(EINVAL);
@@ -351,6 +351,15 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
     if (ret < 0)
         return ret;
 
+finish:
+
+#if FF_API_PKT_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (dst->pkt_duration && dst->pkt_duration != dst->duration)
+        dst->duration = dst->pkt_duration;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
     return 0;
 }
 
diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
index 032fb0c66c..84ff8aa789 100644
--- a/libavcodec/gifdec.c
+++ b/libavcodec/gifdec.c
@@ -475,7 +475,7 @@ static int gif_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     s->frame->pts     = avpkt->pts;
     s->frame->pkt_dts = avpkt->dts;
-    s->frame->pkt_duration = avpkt->duration;
+    s->frame->duration = avpkt->duration;
 
     if (avpkt->size >= 6) {
         s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 ||
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 1e35743867..b120d55190 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -415,7 +415,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
     frame->pkt_dts = p->m.timestamp;
     frame->pkt_pos = p->m.offset;
     frame->pkt_size = p->m.size;
-    frame->pkt_duration = p->m.duration;
+    frame->duration = p->m.duration;
     frame->key_frame = p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY;
 
     switch (p->frame_hdr->frame_type) {
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index a6fa6ffa25..d5c241d169 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -344,7 +344,7 @@ static IMFSample *mf_v_avframe_to_sample(AVCodecContext *avctx, const AVFrame *f
         return NULL;
     }
 
-    IMFSample_SetSampleDuration(sample, mf_to_mf_time(avctx, frame->pkt_duration));
+    IMFSample_SetSampleDuration(sample, mf_to_mf_time(avctx, frame->duration));
 
     return sample;
 }
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 34e49c26ca..e1bb542d51 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -234,7 +234,7 @@ static int raw_decode(AVCodecContext *avctx, AVFrame *frame,
         return res;
 
     frame->pkt_pos      = avctx->internal->last_pkt_props->pos;
-    frame->pkt_duration = avctx->internal->last_pkt_props->duration;
+    frame->duration     = avctx->internal->last_pkt_props->duration;
 
     if (context->tff >= 0) {
         frame->interlaced_frame = 1;



More information about the ffmpeg-cvslog mailing list