From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 4/4 v2] avcodec/setts_bsf: add constants to modify packet duration Date: Wed, 23 Feb 2022 12:03:55 -0300 Message-ID: <20220223150355.944-4-jamrial@gmail.com> (raw) In-Reply-To: <20220223150355.944-1-jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com> --- 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 }, }; -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-02-23 15:05 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-23 15:03 [FFmpeg-devel] [PATCH 1/4 v2] ffmpeg: flush delayed frames in codec copy scenarios James Almer 2022-02-23 15:03 ` [FFmpeg-devel] [PATCH 2/4 v2] ffmpeg: ensure a keyframe was not seen before skipping packets James Almer 2022-03-31 11:47 ` Anton Khirnov 2022-03-31 11:51 ` James Almer 2022-02-23 15:03 ` [FFmpeg-devel] [PATCH 3/4] avcodec/setts_bsf: add NEXT_PTS/DTS expression constants James Almer 2022-02-23 15:03 ` James Almer [this message] 2022-02-28 12:30 ` [FFmpeg-devel] [PATCH 1/4 v2] ffmpeg: flush delayed frames in codec copy scenarios James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220223150355.944-4-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git