From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 6A1314E178 for ; Fri, 13 Feb 2026 17:03:14 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'BHC/teNtB3XeZdxEIyowkCIKc4bbUCxMQlBWOB8I9OQ=', expected b'XdIxm9c9V1jPxddhAlovNf3Y/aF5ClbPJbi2gKDOqlM=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1771002175; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=BHC/teNtB3XeZdxEIyowkCIKc4bbUCxMQlBWOB8I9OQ=; b=JJ2xjVhPlhqJfeaCoF4Nl8E72zj7p4+wtiHzWqRdZOGqv3ZDS3R+6e4SzYey6UsK+KVBG j1wAZeEiaVKB4TtZKVesSszTJSdf14QdZQ/sYCpBNU/DHDHw3HYTBe7hl+UlfUosSE/XXhy H+PGSn1ozURZiBxVO1VD2RvnaqcU3FYF2lJhddLbCm5UyIrGieXQsWYT+RFouk9etVJBhqS Dmk8FhEbM7BmqTkgDjwXL6pAAUTjc2bZynZiLGCTg1N2qSfVqIBF+UwSz1vl5eh1kQ7G4Cw yFu7qKdCzeVonobdSoK3vU3vqZlIsegVbK5GvmJ0Kzds47Ewzj/3/X6SHmzg== Received: from [172.20.0.3] (unknown [172.20.0.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 30DC56910FC; Fri, 13 Feb 2026 19:02:55 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1771002167; b=d5ZzMfY4lgrAE75uf3I0tq8d05QxOGKkbYpxWOhndIhiP0KDHV4EOVZNk126ZxdJmyznn okYmFm4If1w8clsiDmW1aEZwYNE/3pN8m84AvVbTPpC93/H9KaWVdkmOmfH0It21Nnx9YYX hveAIl9kT39sAu/TYu2V+UNR+p6gkWq+wAMR3y6myT6EmuyZSmaRcvskAUBF9bVmnQ2jagv 71twJQXDhWWy+TyN+/XcvbHyj9QBFmBtF5muVb+eErmP3V6LA3abw6nCxN4mfdv4VHeSQQY lxwMqCfeFvGBbGxTTSC82WZW6psymIIBV6DL0uvvw7+AYpghNmlry0yhS32g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1771002167; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=QBg8H3bAtcmXg6d181GYm0i+6uLyGVvPUSJ+dUqeonU=; b=YyGE0iQ7sKukPhNqNih4Kwz0XeBso+DkzcyAo9fiRAZ1QCeg87MPGftcc2rLDset7ZLDn O07ZCUCO3jsgZNQW1UW84Tf+rrKpcsaE2oIsaF9+KKpPCbOx1xJ2LNhxDoYRxdbRPI9wQ8X c9N0mmYe4XYzZw27BV0pFUKLkWfgdUvKEwgbkqFPcmetCareNVKRaPJidgHbHvZAGoPB3VC rrxhWFsh4cYJyEX1N1sQF31daExEcvjuZPkBoRphr1Zh2pwXP4DZlRckbkWN96HfMmX5PFN Rrv7tfeh/hqtQTUp95qLQBCX8Y377WoPpdr4CawicMaoDlLls7c9WJdRhVag== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1771002158; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=XdIxm9c9V1jPxddhAlovNf3Y/aF5ClbPJbi2gKDOqlM=; b=RLibpysHVhcEORbzlkZ6+7b0PgdH+kfafB+02eYFsxoXSnUum0VJNseemJR9Xr3UdgNz3 JeiE1X5MyEWoVJMu2KyToVMqd0DseHPf+29LsL3DF/MuarRpawIL740mHP0wEVj2gnRbDHU dLqdVbA31wvyIgwoXavmvOjST3gB1yh1+QWIkVTgwjFwcyR3lyFvRPil94zdln1Vt+qyHsW Fj0PQstmMKmqUP9f/8RQkjroKse9OaKvS8K8YY9tdQcJI4fEoN8/eyv59BZtnVwOLe+3YAO cDj5BUNZI1Xt7cwi9zzExTZnByuxlU9ylnytO23dOUxVwvXFLsiRCDCmgqiw== Received: from c8d966988b92 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 381A369109F for ; Fri, 13 Feb 2026 19:02:38 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Feb 2026 17:02:37 -0000 Message-ID: <177100215839.25.8088908160414546155@009cbcb3d8cd> Message-ID-Hash: ZFCDGZ2LTY6KFCX2V4VHLMBD7LRUQO4C X-Message-ID-Hash: ZFCDGZ2LTY6KFCX2V4VHLMBD7LRUQO4C X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] avcodec/encode: add a helper to convert from a duration to samples (PR #21746) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: James Almer via ffmpeg-devel Cc: James Almer Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21746 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21746 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21746.patch >>From c42c5fe94c4332a6ef758dca617f5e8cb8aa894b Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:00:10 -0300 Subject: [PATCH 1/6] avcodec/encode: add a helper to convert from a duration to samples Signed-off-by: James Almer --- libavcodec/encode.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/encode.h b/libavcodec/encode.h index 82bd3c9431..b66b387030 100644 --- a/libavcodec/encode.h +++ b/libavcodec/encode.h @@ -99,6 +99,18 @@ static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *av avctx->time_base); } +/** + * Rescale from time base to AVCodecContext.sample_rate. + */ +static av_always_inline int64_t ff_samples_from_time_base(const AVCodecContext *avctx, + int64_t duration) +{ + if (!duration) + return duration; + return av_rescale_q(duration, avctx->time_base, + (AVRational){ 1, avctx->sample_rate }); +} + /** * Check if the elements of codec context matrices (intra_matrix, inter_matrix or * chroma_intra_matrix) are within the specified range. -- 2.52.0 >>From 6ce1c604682b9a4a2429aaac2e0b8cd4d3854f2c Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:01:28 -0300 Subject: [PATCH 2/6] avcodec/libfdk-aacenc: rescale packet duration when calculating discarded samples Signed-off-by: James Almer --- libavcodec/libfdk-aacenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 1a3f127d37..6c28633fba 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -530,7 +530,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); - discard_padding = avctx->frame_size - avpkt->duration; + discard_padding = avctx->frame_size - ff_samples_from_time_base(avctx, avpkt->duration); // Check if subtraction resulted in an overflow if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n"); -- 2.52.0 >>From 35bbcdf7efdacd9f92dfd8cac6b676d169d08669 Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:01:54 -0300 Subject: [PATCH 3/6] avcodec/libmp3lame: rescale packet duration when calculating discarded samples Signed-off-by: James Almer --- libavcodec/libmp3lame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 01b8985b8c..339505ccfe 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -285,7 +285,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); - discard_padding = avctx->frame_size - avpkt->duration; + discard_padding = avctx->frame_size - ff_samples_from_time_base(avctx, avpkt->duration); // Check if subtraction resulted in an overflow if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n"); -- 2.52.0 >>From 7f3199617cc6add47b7d74e4ea1c658b74baf9c3 Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:02:07 -0300 Subject: [PATCH 4/6] avcodec/libopusenc: rescale packet duration when calculating discarded samples Signed-off-by: James Almer --- libavcodec/libopusenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c index 131886c8ea..927776bbca 100644 --- a/libavcodec/libopusenc.c +++ b/libavcodec/libopusenc.c @@ -511,7 +511,7 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&opus->afq, opus->opts.packet_size, &avpkt->pts, &avpkt->duration); - discard_padding = opus->opts.packet_size - avpkt->duration; + discard_padding = opus->opts.packet_size - ff_samples_from_time_base(avctx, avpkt->duration); // Check if subtraction resulted in an overflow if ((discard_padding < opus->opts.packet_size) != (avpkt->duration > 0)) return AVERROR(EINVAL); -- 2.52.0 >>From ff2b1a636f5d33848da4f2e37d33fba6bb6cec6c Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:02:20 -0300 Subject: [PATCH 5/6] avcodec/libvorbisenc: rescale packet duration when calculating discarded samples Signed-off-by: James Almer --- libavcodec/libvorbisenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c index a3f02f3cb9..c54ebebae8 100644 --- a/libavcodec/libvorbisenc.c +++ b/libavcodec/libvorbisenc.c @@ -421,7 +421,7 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, duration, &avpkt->pts, &avpkt->duration); - discard_padding = ff_samples_to_time_base(avctx, duration) - avpkt->duration; + discard_padding = duration - ff_samples_from_time_base(avctx, avpkt->duration); if (discard_padding > 0) { uint8_t *side_data = av_packet_new_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, -- 2.52.0 >>From 9241f44121715428a71bb42383c3661663e1cf93 Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:03:26 -0300 Subject: [PATCH 6/6] avcodec/opus/enc: rescale packet duration when calculating discarded samples Signed-off-by: James Almer --- libavcodec/opus/enc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavcodec/opus/enc.c b/libavcodec/opus/enc.c index 65e6a09575..587e4ed69d 100644 --- a/libavcodec/opus/enc.c +++ b/libavcodec/opus/enc.c @@ -548,7 +548,7 @@ static int opus_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { OpusEncContext *s = avctx->priv_data; - int ret, frame_size, alloc_size = 0; + int ret, frame_size, discard_padding, alloc_size = 0; if (frame) { /* Add new frame to queue */ if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) @@ -600,11 +600,13 @@ static int opus_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* Remove samples from queue and skip if needed */ ff_af_queue_remove(&s->afq, s->packet.frames*frame_size, &avpkt->pts, &avpkt->duration); - if (s->packet.frames*frame_size > avpkt->duration) { + + discard_padding = s->packet.frames*frame_size - ff_samples_from_time_base(avctx, avpkt->duration); + if (discard_padding > 0) { uint8_t *side = av_packet_new_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if (!side) return AVERROR(ENOMEM); - AV_WL32(&side[4], s->packet.frames*frame_size - avpkt->duration); + AV_WL32(&side[4], discard_padding); } *got_packet_ptr = 1; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org