[FFmpeg-cvslog] lavc/libvpxenc: send frame durations to the encoder
Anton Khirnov
git at videolan.org
Mon May 15 11:36:52 EEST 2023
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu May 4 11:35:31 2023 +0200| [f618004bc1fa31f4952ea420c3969ee4999d079b] | committer: Anton Khirnov
lavc/libvpxenc: send frame durations to the encoder
Adapt similar code from libaomenc - stop using ticks_per_frame except as
a last resort.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f618004bc1fa31f4952ea420c3969ee4999d079b
---
libavcodec/libvpxenc.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index a20e949842..f70cc87c41 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1692,6 +1692,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
vpx_svc_layer_id_t layer_id;
int layer_id_valid = 0;
+ unsigned long duration = 0;
if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) {
struct vpx_codec_enc_cfg cfg = *enccfg;
@@ -1820,8 +1821,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
#endif
}
+ if (frame && frame->duration > ULONG_MAX) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Frame duration too large: %"PRId64"\n", frame->duration);
+ } else if (frame && frame->duration)
+ duration = frame->duration;
+ else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
+ else
+ duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
+
res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding frame");
return AVERROR_INVALIDDATA;
@@ -1829,7 +1840,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
if (ctx->is_alpha) {
res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding alpha frame");
return AVERROR_INVALIDDATA;
More information about the ffmpeg-cvslog
mailing list