[FFmpeg-cvslog] avcodec/setts_bsf: add constants to modify packet duration

James Almer git at videolan.org
Mon Feb 28 17:17:31 EET 2022


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Mon Feb 14 11:28:13 2022 -0300| [825fb5f1cb1a1a64f6d2e4066639c88f224bf971] | committer: James Almer

avcodec/setts_bsf: add constants to modify packet duration

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=825fb5f1cb1a1a64f6d2e4066639c88f224bf971
---

 doc/bitstream_filters.texi | 12 ++++++++++++
 libavcodec/setts_bsf.c     | 25 ++++++++++++++++++++++++-
 libavcodec/version.h       |  2 +-
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 46654e9369..689bb52141 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -759,6 +759,9 @@ The demux timestamp in input.
 @item PTS
 The presentation timestamp in input.
 
+ at item DURATION
+The duration in input.
+
 @item STARTDTS
 The DTS of the first packet.
 
@@ -771,18 +774,27 @@ The previous input DTS.
 @item PREV_INPTS
 The previous input PTS.
 
+ at item PREV_INDURATION
+The previous input duration.
+
 @item PREV_OUTDTS
 The previous output DTS.
 
 @item PREV_OUTPTS
 The previous output PTS.
 
+ at item PREV_OUTDURATION
+The previous output duration.
+
 @item NEXT_DTS
 The next input DTS.
 
 @item NEXT_PTS
 The next input PTS.
 
+ at item NEXT_DURATION
+The next input duration.
+
 @item TB
 The timebase of stream packet belongs.
 
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 },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index bff9745669..991b4f69bc 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  59
 #define LIBAVCODEC_VERSION_MINOR  21
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list