From patchwork Mon Feb 14 22:41:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 34294 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:14aa:0:0:0:0 with SMTP id bz10csp5924071nkb; Mon, 14 Feb 2022 14:43:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyW52MCi1MlHreOYqcWzigaFZM5iwflR+RMQIg4eRGTmvSt6oFmQrZweNlxOiEXQu63OS4k X-Received: by 2002:a05:6402:1e91:: with SMTP id f17mr1067814edf.407.1644878593921; Mon, 14 Feb 2022 14:43:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644878593; cv=none; d=google.com; s=arc-20160816; b=NiNJK0IG4XDFFsWaDWFAPM3jRcPz+/FynWO1PKIGrZFouLH0l0tRmnBg5DaZ/fVof3 4w062lo3qml8cRzPSZSmvfhcY9fhkkTzHybJQS7QvpsqieHEqssODxnfOHWYL2mwxFg8 tET/+oFr1USSjODpgF5ecYIz31T3pvOC2Elm64Vdf/5ZH9aCfHrSHwr3IAjoD6UoqK5H +WagTEkUgAMTsm4yFKSxAdZjdDCi86jylN4It7MULxYrFOznMm0GPhOxTSFJGoaHNExj vDl/6z7AabNAl1vZkY/P1IHbPDm+MYfpIXhK07tZnYuEa8dhS2E6tUKaKxngJ3MPyISD NEBQ== 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=nvPAtj43JHWh8fbWt1clV+zuxra26LCsvBu3cuqvY7A=; b=K0FD0Fn7mq4zIPqZ/8NOVPCiBIGInDVAOeIKM78hTv79BLhmMfcJaQmdLNyslrDU4X m9DD87cOCTyjTXXtpmrjHiY18hFVKN2uFYkRK+M90qU9TikcLaDptxKJ28ZrCxMI4B1S hNn0ZPkSSF/2cTG+an20Oo/PN8JZleiCMQxlxGaV29NRGoKHcTzHlls+TFPiYqsyFrql 8DeWX68F6LspcUcmvR7qKx0dKDGbEVdMyi7UI5HYQleH8Cl5teYESI9Hl/9DUgV7bl20 Pkt7X+R8rH1scyWoD+hX5/6wCbxk8S7CwDCcM9LOicPkrhcM7wejkopYUmFAH7xBwwYt Iohg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CcqPfX2x; 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 hs6si7758878ejc.447.2022.02.14.14.43.13; Mon, 14 Feb 2022 14:43:13 -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=CcqPfX2x; 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 0090B68B1E9; Tue, 15 Feb 2022 00:42:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4116368B1C1 for ; Tue, 15 Feb 2022 00:42:22 +0200 (EET) Received: by mail-oi1-f177.google.com with SMTP id 4so18970471oil.11 for ; Mon, 14 Feb 2022 14:42:22 -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=944SdW6nEMSuoK6nMCtCLndulhEFnXqWPBSw2FySRjo=; b=CcqPfX2x41xjLD6GIbjV/zmoYMYh3LkmWzvtInkW0uQ8Krw6Fz9k64unvcOw0xM8EO MJrRWwmFvB9cbzFlO5Hf0YYgXgcbJHVj6ufbvXL0iL+GTuSdOn0Z+VMKHMPrH25aV2FQ bsRW2K7PBaMCppsMgOoYfVfdlCGftvU6DsrhwS8Lw34MGZTLiyyap1qRWxNMXJRCyrgv qUo1IV2Z/bChEX/ie8kjnnSO2MS8N95eh9bgVp7wKJZUmiWQ6XGQOssxyWVEsDDPRRy8 cE1ss4ad96mkJoRqhzNESGftg2DQ2+WfRsbuWdc4jv+XHHoBYm5/bm30X5fYN7oWNxnk WL0Q== 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=944SdW6nEMSuoK6nMCtCLndulhEFnXqWPBSw2FySRjo=; b=2guX5K9DLijlt3MBZ1zvONYJKY9eoPjdWhSeYy9Z5fuQoDLKHoo7yNb4BBXqA2RAx+ URY7k5wzQC1NAmM9SgaYumV04PQcTvfLOHuWy76xT5xwz5tTynQtsokXBmHT7HsoCW5I oIY6AMWB4/c7i4FQ9WP2ZADW8pY3sw6fTtm/xCr8bI0U75iPWz595EBYdg/0uQ6eXly5 QaKpnCDtidFgSmDWXMkG7mFRY86ngQP5JVhcG6fYyKgh6KXQTyEmpP9cU/ctrdTIMQYv jqSDzsJd/adFRTubI4dZR2DXZ+CWLzE4FdAfBxSJb4NKyuK/z1oFiyerEy2hlXgyM4ee LY0w== X-Gm-Message-State: AOAM530va1efYxk0QwMKuQtlhgnq80PbrYh+7uI1w+0Wd9Zh2kahJP71 ok/Rng868B3C7Obqm/Q+gunoAWWdCKBvQQ== X-Received: by 2002:aca:3787:0:b0:2cb:676a:47ed with SMTP id e129-20020aca3787000000b002cb676a47edmr470251oia.76.1644878541172; Mon, 14 Feb 2022 14:42:21 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id a8sm13199885otj.47.2022.02.14.14.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 14:42:20 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Feb 2022 19:41:56 -0300 Message-Id: <20220214224156.39862-6-jamrial@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214224156.39862-1-jamrial@gmail.com> References: <20220214224156.39862-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] 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: Y2eg8sQ27Bo4 Signed-off-by: James Almer --- Missing doc changes. 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 35266ee251..46f9a30103 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 }, };