From patchwork Wed Feb 23 15:03:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 34493 X-Google-Smtp-Source: ABdhPJzFOGlVUfio7qLCwbuHoe56eaWHnHn+NaqIQNbMXZgeyq0ech2nwpqo363pH7Ckle+Qz/8H X-Received: by 2002:a17:906:fb8a:b0:6ce:c3e6:2ac4 with SMTP id lr10-20020a170906fb8a00b006cec3e62ac4mr137199ejb.40.1645628706055; Wed, 23 Feb 2022 07:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645628706; cv=none; d=google.com; s=arc-20160816; b=ckHUTMaj4Bg/4H4+0cvqBXg6Wt2RXXbivHfz9tvAxAjl4ci9vQNejnszLyEngpsQp/ KX8ldmcmFUuWu7Y4i4MbZwnHuzZ4jciXg+pEAMlYvbc4p6OmjSQraEg11z5p0bCXryWy /bYpTZAL3u5zxdBGUZT5uXr3kxG4jblepj2Z/apAa07glMiQOSwgV/HSDMnKc7P3YcJL LWG1fsbiC4r2WTR/8atzcmjTmmD7ObXVWDBCx3C57s7Xc2m4fY9GeZpI/ukqfLdzCSJm CHhBci6L/XF5BVyQt3u7SKwUZDiwsmCqRLOqYjchaTZEDu+7gsG7sC7uo9ABEWteqRsb /JNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=RKtFu/yD1deifmowYgZ0EtI2UkcZYHouqlidOCW5fuk=; b=nexaMBR3iBsBEOrD6TENYJMm87cjZRXqJGy4UVo5Cum3l9yTWZxZacV4PiAuW7dW26 ZHPFFYk9wj7CVssoMGuJTQXQOmL89xNxPwDV/RljiVEu8nYzVKAz2PLynxKnbdKvIyUL wp6l5mGbhPicnjRejb69JNBV+CmEmvo4QKTvd9D8inm/YmaRX7xyGMNKMYrogDFeZP9H T2bXq9ZCf715LMj6NknGzIsR6hxlTfE8dKDA83gKmumiNIbtIc3nLovxEv/a5OoYNm8c ZK23zWna+QHNNZxlbExldLSfCnbfPDAGFgPAVK2XyLMhhdyKJI/H5LFrviPGTGnBb0No Frpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YPsGmtOn; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h14si14920315edq.490.2022.02.23.07.05.05; Wed, 23 Feb 2022 07:05:05 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YPsGmtOn; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5EF368B1E5; Wed, 23 Feb 2022 17:04:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B634768B297 for ; Wed, 23 Feb 2022 17:04:27 +0200 (EET) Received: by mail-oo1-f42.google.com with SMTP id s203-20020a4a3bd4000000b003191c2dcbe8so22635955oos.9 for ; Wed, 23 Feb 2022 07:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=2HFwrcJ6aFaVv1/xHSGCK/Wx3LjeaRBCXTWc7L/5Jwg=; b=YPsGmtOnxCgb465KjhgiWfsR0W8wCii0/CWN4amNFoXYTIjhulQV8Ae3d/ApSMqaO5 XgaybG+I0fkJ5zssOorfTbv/ujDkDDPMpASjrAjtZhwIWWtelHe7aq9R9WoBhHwQ9kj1 kQpV52/bxnLyA8HHu2HVzSQWJImc49lhSriBtcIeJsAnjFVxOJ1tXkrmr9wA0F3E9rvY ztI9QwjtSuHdmqmVxd935ERkt6zJBZyHRwOcgoDNEjFiMAAoasX304uQFwZpOhQedh8M BTtsgew06hF3ibkvweDj9IKlCaQWgUo0Bu+XJgyp9ja2bXc3vXHrAdNlFHcGszK5G917 AZaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2HFwrcJ6aFaVv1/xHSGCK/Wx3LjeaRBCXTWc7L/5Jwg=; b=HDdBuCHTVU7TECW0pEDNlKyrFPMGOc0cAP6/Q3ob8yTfevxdiI8Q1XdnE0rkNPOFDw w7k3PKgmAUlMQcSdsT9u0yKJebgEuBkKxNeQzwazpWRxr6N/Og5flnfmxoicUGzVsuAM 1528A1983xHFRrGaGRFtzsVMLi3gnKlaKJbpxdjiRctgQSCYEjTVgs3rOLsh5bHYvsmr v9snYXVC5UszCdjc0mbJwzQsNJJ/Z/Iyx1CEUXXUfHEqS/yZlX0UuUh3CXcLQU2t/XpQ 7Ku4Y7gWOnZ5uziyy3Yn4AoTbeyD+7uyiC4g8cdi7PLy4ILECjxvsGEnjbgvhdIMrX3t wiXQ== X-Gm-Message-State: AOAM5333ZJzI11UlYD4lGQz28n8V+ZKIW2ibIuf/R0PPGr9eKOCHqxlL s3QSpm62AXlwGSZtKBCNRGY8PFzzuu2cZg== X-Received: by 2002:a05:6870:41cf:b0:d6:b8e4:868c with SMTP id z15-20020a05687041cf00b000d6b8e4868cmr893648oac.282.1645628665841; Wed, 23 Feb 2022 07:04:25 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id o2sm8571449otl.9.2022.02.23.07.04.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 07:04:25 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Feb 2022 12:03:55 -0300 Message-Id: <20220223150355.944-4-jamrial@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223150355.944-1-jamrial@gmail.com> References: <20220223150355.944-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4 v2] avcodec/setts_bsf: add constants to modify packet duration X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: xvEeqrnsdxtF Signed-off-by: James Almer --- No changes since last version. Already LGTM'd by Paul. libavcodec/setts_bsf.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/setts_bsf.c b/libavcodec/setts_bsf.c index f0243a1114..eadc4e4d34 100644 --- a/libavcodec/setts_bsf.c +++ b/libavcodec/setts_bsf.c @@ -35,12 +35,16 @@ static const char *const var_names[] = { "POS", ///< original position in the file of the frame "PREV_INPTS", ///< previous input PTS "PREV_INDTS", ///< previous input DTS + "PREV_INDURATION", ///< previous input duration "PREV_OUTPTS", ///< previous output PTS "PREV_OUTDTS", ///< previous output DTS + "PREV_OUTDURATION", ///< previous output duration "NEXT_PTS", ///< next input PTS "NEXT_DTS", ///< next input DTS + "NEXT_DURATION", ///< next input duration "PTS", ///< original PTS in the file of the frame "DTS", ///< original DTS in the file of the frame + "DURATION", ///< original duration in the file of the frame "STARTPTS", ///< PTS at start of movie "STARTDTS", ///< DTS at start of movie "TB", ///< timebase of the stream @@ -55,12 +59,16 @@ enum var_name { VAR_POS, VAR_PREV_INPTS, VAR_PREV_INDTS, + VAR_PREV_INDUR, VAR_PREV_OUTPTS, VAR_PREV_OUTDTS, + VAR_PREV_OUTDUR, VAR_NEXT_PTS, VAR_NEXT_DTS, + VAR_NEXT_DUR, VAR_PTS, VAR_DTS, + VAR_DURATION, VAR_STARTPTS, VAR_STARTDTS, VAR_TB, @@ -75,6 +83,7 @@ typedef struct SetTSContext { char *ts_str; char *pts_str; char *dts_str; + char *duration_str; int64_t frame_number; @@ -86,6 +95,7 @@ typedef struct SetTSContext { AVExpr *ts_expr; AVExpr *pts_expr; AVExpr *dts_expr; + AVExpr *duration_expr; AVPacket *prev_inpkt; AVPacket *prev_outpkt; @@ -109,6 +119,12 @@ static int setts_init(AVBSFContext *ctx) return ret; } + if ((ret = av_expr_parse(&s->duration_expr, s->duration_str, + var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) { + av_log(ctx, AV_LOG_ERROR, "Error while parsing duration expression '%s'\n", s->duration_str); + return ret; + } + if (s->pts_str) { if ((ret = av_expr_parse(&s->pts_expr, s->pts_str, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) { @@ -136,7 +152,7 @@ static int setts_init(AVBSFContext *ctx) static int setts_filter(AVBSFContext *ctx, AVPacket *pkt) { SetTSContext *s = ctx->priv_data; - int64_t new_ts, new_pts, new_dts; + int64_t new_ts, new_pts, new_dts, new_duration; int ret; ret = ff_bsf_get_packet_ref(ctx, pkt); @@ -159,18 +175,23 @@ static int setts_filter(AVBSFContext *ctx, AVPacket *pkt) s->var_values[VAR_POS] = s->cur_pkt->pos; s->var_values[VAR_PTS] = s->cur_pkt->pts; s->var_values[VAR_DTS] = s->cur_pkt->dts; + s->var_values[VAR_DURATION] = s->cur_pkt->duration; s->var_values[VAR_PREV_INPTS] = s->prev_inpkt->pts; s->var_values[VAR_PREV_INDTS] = s->prev_inpkt->dts; + s->var_values[VAR_PREV_INDUR] = s->prev_inpkt->duration; s->var_values[VAR_PREV_OUTPTS] = s->prev_outpkt->pts; s->var_values[VAR_PREV_OUTDTS] = s->prev_outpkt->dts; + s->var_values[VAR_PREV_OUTDUR] = s->prev_outpkt->duration; s->var_values[VAR_NEXT_PTS] = pkt->pts; s->var_values[VAR_NEXT_DTS] = pkt->dts; + s->var_values[VAR_NEXT_DUR] = pkt->duration; s->var_values[VAR_STARTPTS] = s->start_pts; s->var_values[VAR_STARTDTS] = s->start_dts; s->var_values[VAR_TB] = ctx->time_base_out.den ? av_q2d(ctx->time_base_out) : 0; s->var_values[VAR_SR] = ctx->par_in->sample_rate; new_ts = llrint(av_expr_eval(s->ts_expr, s->var_values, NULL)); + new_duration = llrint(av_expr_eval(s->duration_expr, s->var_values, NULL)); if (s->pts_str) { s->var_values[VAR_TS] = s->cur_pkt->pts; @@ -197,6 +218,7 @@ static int setts_filter(AVBSFContext *ctx, AVPacket *pkt) pkt->pts = new_pts; pkt->dts = new_dts; + pkt->duration = new_duration; ret = av_packet_ref(s->prev_outpkt, pkt); if (ret < 0) @@ -228,6 +250,7 @@ static const AVOption options[] = { { "ts", "set expression for packet PTS and DTS", OFFSET(ts_str), AV_OPT_TYPE_STRING, {.str="TS"}, 0, 0, FLAGS }, { "pts", "set expression for packet PTS", OFFSET(pts_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, { "dts", "set expression for packet DTS", OFFSET(dts_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, + { "duration", "set expression for packet duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str="DURATION"}, 0, 0, FLAGS }, { NULL }, };