2010-11-03 00:29:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Stefano Sabatini
|
|
|
|
* Copyright (c) 2008 Victor Paesa
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* video presentation timestamp (PTS) modification filter
|
|
|
|
*/
|
|
|
|
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2014-08-20 19:54:50 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2010-11-03 00:29:17 +02:00
|
|
|
#include "libavutil/eval.h"
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/internal.h"
|
2011-06-04 14:58:23 +03:00
|
|
|
#include "libavutil/mathematics.h"
|
2013-04-11 00:48:26 +03:00
|
|
|
#include "libavutil/opt.h"
|
2013-01-25 17:04:41 +03:00
|
|
|
#include "libavutil/time.h"
|
2013-04-10 17:28:38 +03:00
|
|
|
#include "audio.h"
|
2010-11-03 00:29:17 +02:00
|
|
|
#include "avfilter.h"
|
2019-09-30 13:53:59 +02:00
|
|
|
#include "filters.h"
|
2012-06-12 21:12:42 +03:00
|
|
|
#include "internal.h"
|
2012-05-19 11:37:56 +03:00
|
|
|
#include "video.h"
|
2010-11-03 00:29:17 +02:00
|
|
|
|
2012-02-20 11:42:33 +03:00
|
|
|
static const char *const var_names[] = {
|
2012-09-10 12:58:53 +03:00
|
|
|
"FRAME_RATE", ///< defined only for constant frame-rate video
|
2010-11-03 00:29:17 +02:00
|
|
|
"INTERLACED", ///< tell if the current frame is interlaced
|
2013-04-10 17:28:38 +03:00
|
|
|
"N", ///< frame / sample number (starting at zero)
|
2012-08-08 14:44:11 +03:00
|
|
|
"NB_CONSUMED_SAMPLES", ///< number of samples consumed by the filter (only audio)
|
|
|
|
"NB_SAMPLES", ///< number of samples in the current frame (only audio)
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
#if FF_API_FRAME_PKT
|
2010-11-03 00:29:17 +02:00
|
|
|
"POS", ///< original position in the file of the frame
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
#endif
|
2010-11-03 00:29:17 +02:00
|
|
|
"PREV_INPTS", ///< previous input PTS
|
2012-08-23 13:29:20 +03:00
|
|
|
"PREV_INT", ///< previous input time in seconds
|
2010-11-03 00:29:17 +02:00
|
|
|
"PREV_OUTPTS", ///< previous output PTS
|
2012-08-23 13:29:20 +03:00
|
|
|
"PREV_OUTT", ///< previous output time in seconds
|
2010-11-03 00:29:17 +02:00
|
|
|
"PTS", ///< original pts in the file of the frame
|
2012-08-08 14:44:11 +03:00
|
|
|
"SAMPLE_RATE", ///< sample rate (only audio)
|
|
|
|
"STARTPTS", ///< PTS at start of movie
|
2012-08-23 13:29:20 +03:00
|
|
|
"STARTT", ///< time at start of movie
|
|
|
|
"T", ///< original time in the file of the frame
|
2010-11-03 00:29:17 +02:00
|
|
|
"TB", ///< timebase
|
2013-01-25 17:04:41 +03:00
|
|
|
"RTCTIME", ///< wallclock (RTC) time in micro seconds
|
|
|
|
"RTCSTART", ///< wallclock (RTC) time at the start of the movie in micro seconds
|
2013-04-10 17:28:38 +03:00
|
|
|
"S", // Number of samples in the current frame
|
|
|
|
"SR", // Audio sample rate
|
2018-07-05 11:54:55 +02:00
|
|
|
"FR", ///< defined only for constant frame-rate video
|
2023-04-29 20:56:46 +02:00
|
|
|
"T_CHANGE", ///< time of first frame after latest command was applied
|
2010-11-03 00:29:17 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum var_name {
|
2012-09-10 12:58:53 +03:00
|
|
|
VAR_FRAME_RATE,
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_INTERLACED,
|
|
|
|
VAR_N,
|
2012-08-08 14:44:11 +03:00
|
|
|
VAR_NB_CONSUMED_SAMPLES,
|
|
|
|
VAR_NB_SAMPLES,
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
#if FF_API_FRAME_PKT
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_POS,
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
#endif
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_PREV_INPTS,
|
2012-08-23 13:29:20 +03:00
|
|
|
VAR_PREV_INT,
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_PREV_OUTPTS,
|
2012-08-23 13:29:20 +03:00
|
|
|
VAR_PREV_OUTT,
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_PTS,
|
2012-08-08 14:44:11 +03:00
|
|
|
VAR_SAMPLE_RATE,
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_STARTPTS,
|
2012-08-23 13:29:20 +03:00
|
|
|
VAR_STARTT,
|
|
|
|
VAR_T,
|
2010-11-03 00:29:17 +02:00
|
|
|
VAR_TB,
|
2013-01-25 17:04:41 +03:00
|
|
|
VAR_RTCTIME,
|
|
|
|
VAR_RTCSTART,
|
2013-04-10 17:28:38 +03:00
|
|
|
VAR_S,
|
|
|
|
VAR_SR,
|
2018-07-05 11:54:55 +02:00
|
|
|
VAR_FR,
|
2023-04-29 20:56:46 +02:00
|
|
|
VAR_T_CHANGE,
|
|
|
|
VAR_VARS_NB,
|
2010-11-03 00:29:17 +02:00
|
|
|
};
|
|
|
|
|
2014-04-11 12:54:15 +03:00
|
|
|
typedef struct SetPTSContext {
|
2013-04-11 00:48:26 +03:00
|
|
|
const AVClass *class;
|
|
|
|
char *expr_str;
|
2010-11-03 00:29:17 +02:00
|
|
|
AVExpr *expr;
|
|
|
|
double var_values[VAR_VARS_NB];
|
2012-08-08 14:44:11 +03:00
|
|
|
enum AVMediaType type;
|
2010-11-03 00:29:17 +02:00
|
|
|
} SetPTSContext;
|
|
|
|
|
2023-12-27 21:12:51 +02:00
|
|
|
#define V(name_) \
|
|
|
|
setpts->var_values[VAR_##name_]
|
|
|
|
|
2013-04-12 12:13:33 +03:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2010-11-03 00:29:17 +02:00
|
|
|
{
|
|
|
|
SetPTSContext *setpts = ctx->priv;
|
|
|
|
int ret;
|
|
|
|
|
2013-04-11 00:48:26 +03:00
|
|
|
if ((ret = av_expr_parse(&setpts->expr, setpts->expr_str,
|
2010-11-03 00:29:17 +02:00
|
|
|
var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) {
|
2013-04-11 00:48:26 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Error while parsing expression '%s'\n", setpts->expr_str);
|
2010-11-03 00:29:17 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-27 21:12:51 +02:00
|
|
|
V(N) = 0.0;
|
|
|
|
V(S) = 0.0;
|
|
|
|
V(PREV_INPTS) = NAN;
|
|
|
|
V(PREV_INT) = NAN;
|
|
|
|
V(PREV_OUTPTS) = NAN;
|
|
|
|
V(PREV_OUTT) = NAN;
|
|
|
|
V(STARTPTS) = NAN;
|
|
|
|
V(STARTT) = NAN;
|
|
|
|
V(T_CHANGE) = NAN;
|
2010-11-03 00:29:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_input(AVFilterLink *inlink)
|
|
|
|
{
|
2012-08-08 14:44:11 +03:00
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
SetPTSContext *setpts = ctx->priv;
|
2010-11-03 00:29:17 +02:00
|
|
|
|
2012-08-08 14:44:11 +03:00
|
|
|
setpts->type = inlink->type;
|
2023-12-27 21:12:51 +02:00
|
|
|
V(TB) = av_q2d(inlink->time_base);
|
|
|
|
V(RTCSTART) = av_gettime();
|
2010-11-03 00:29:17 +02:00
|
|
|
|
2023-12-27 21:12:51 +02:00
|
|
|
V(SR) = V(SAMPLE_RATE) =
|
2012-09-10 13:02:30 +03:00
|
|
|
setpts->type == AVMEDIA_TYPE_AUDIO ? inlink->sample_rate : NAN;
|
2012-08-08 14:44:11 +03:00
|
|
|
|
2023-12-27 21:12:51 +02:00
|
|
|
V(FRAME_RATE) = V(FR) =
|
|
|
|
inlink->frame_rate.num && inlink->frame_rate.den ?
|
|
|
|
av_q2d(inlink->frame_rate) : NAN;
|
2012-09-10 12:58:53 +03:00
|
|
|
|
|
|
|
av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f FRAME_RATE:%f SAMPLE_RATE:%f\n",
|
2023-12-27 21:12:51 +02:00
|
|
|
V(TB), V(FRAME_RATE), V(SAMPLE_RATE));
|
2010-11-03 00:29:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-03-27 14:55:26 +02:00
|
|
|
static int config_output_video(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
outlink->frame_rate = (AVRational){ 1, 0 };
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 21:00:37 +03:00
|
|
|
#define BUF_SIZE 64
|
|
|
|
|
|
|
|
static inline char *double2int64str(char *buf, double v)
|
|
|
|
{
|
|
|
|
if (isnan(v)) snprintf(buf, BUF_SIZE, "nan");
|
|
|
|
else snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)v);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2019-09-30 13:53:59 +02:00
|
|
|
static double eval_pts(SetPTSContext *setpts, AVFilterLink *inlink, AVFrame *frame, int64_t pts)
|
|
|
|
{
|
2023-12-27 21:12:51 +02:00
|
|
|
if (isnan(V(STARTPTS))) {
|
|
|
|
V(STARTPTS) = TS2D(pts);
|
|
|
|
V(STARTT ) = TS2T(pts, inlink->time_base);
|
2019-09-30 13:53:59 +02:00
|
|
|
}
|
2023-12-27 21:12:51 +02:00
|
|
|
if (isnan(V(T_CHANGE))) {
|
|
|
|
V(T_CHANGE) = TS2T(pts, inlink->time_base);
|
2023-04-29 20:56:46 +02:00
|
|
|
}
|
2023-12-27 21:12:51 +02:00
|
|
|
V(PTS ) = TS2D(pts);
|
|
|
|
V(T ) = TS2T(pts, inlink->time_base);
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
#if FF_API_FRAME_PKT
|
|
|
|
FF_DISABLE_DEPRECATION_WARNINGS
|
2023-12-27 21:12:51 +02:00
|
|
|
V(POS ) = !frame || frame->pkt_pos == -1 ? NAN : frame->pkt_pos;
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
FF_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
#endif
|
2023-12-27 21:12:51 +02:00
|
|
|
V(RTCTIME ) = av_gettime();
|
2019-09-30 13:53:59 +02:00
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
if (inlink->type == AVMEDIA_TYPE_VIDEO) {
|
2023-12-27 21:12:51 +02:00
|
|
|
V(INTERLACED) = !!(frame->flags & AV_FRAME_FLAG_INTERLACED);
|
2019-09-30 13:53:59 +02:00
|
|
|
} else if (inlink->type == AVMEDIA_TYPE_AUDIO) {
|
2023-12-27 21:12:51 +02:00
|
|
|
V(S) = frame->nb_samples;
|
|
|
|
V(NB_SAMPLES) = frame->nb_samples;
|
2019-09-30 13:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return av_expr_eval(setpts->expr, setpts->var_values, NULL);
|
|
|
|
}
|
2012-12-18 21:00:37 +03:00
|
|
|
#define d2istr(v) double2int64str((char[BUF_SIZE]){0}, v)
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
2010-11-03 00:29:17 +02:00
|
|
|
{
|
|
|
|
SetPTSContext *setpts = inlink->dst->priv;
|
2012-11-29 00:27:51 +03:00
|
|
|
int64_t in_pts = frame->pts;
|
2010-11-03 00:29:17 +02:00
|
|
|
double d;
|
2012-07-08 18:29:42 +03:00
|
|
|
|
2019-09-30 13:53:59 +02:00
|
|
|
d = eval_pts(setpts, inlink, frame, frame->pts);
|
2012-11-27 09:49:45 +03:00
|
|
|
frame->pts = D2TS(d);
|
2024-03-27 14:57:15 +02:00
|
|
|
frame->duration = 0;
|
2012-12-18 21:00:37 +03:00
|
|
|
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(inlink->dst, AV_LOG_TRACE,
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
"N:%"PRId64" PTS:%s T:%f",
|
2023-12-27 21:12:51 +02:00
|
|
|
(int64_t)V(N), d2istr(V(PTS)), V(T));
|
2012-12-18 21:00:37 +03:00
|
|
|
switch (inlink->type) {
|
|
|
|
case AVMEDIA_TYPE_VIDEO:
|
2015-04-20 03:19:29 +02:00
|
|
|
av_log(inlink->dst, AV_LOG_TRACE, " INTERLACED:%"PRId64,
|
2023-12-27 21:12:51 +02:00
|
|
|
(int64_t)V(INTERLACED));
|
2012-12-18 21:00:37 +03:00
|
|
|
break;
|
|
|
|
case AVMEDIA_TYPE_AUDIO:
|
2015-04-20 03:19:29 +02:00
|
|
|
av_log(inlink->dst, AV_LOG_TRACE, " NB_SAMPLES:%"PRId64" NB_CONSUMED_SAMPLES:%"PRId64,
|
2023-12-27 21:12:51 +02:00
|
|
|
(int64_t)V(NB_SAMPLES),
|
|
|
|
(int64_t)V(NB_CONSUMED_SAMPLES));
|
2012-12-18 21:00:37 +03:00
|
|
|
break;
|
|
|
|
}
|
2015-04-20 03:19:29 +02:00
|
|
|
av_log(inlink->dst, AV_LOG_TRACE, " -> PTS:%s T:%f\n", d2istr(d), TS2T(d, inlink->time_base));
|
2012-12-18 21:00:37 +03:00
|
|
|
|
2013-04-10 17:28:38 +03:00
|
|
|
if (inlink->type == AVMEDIA_TYPE_VIDEO) {
|
2023-12-27 21:12:51 +02:00
|
|
|
V(N) += 1.0;
|
2013-04-10 17:28:38 +03:00
|
|
|
} else {
|
2023-12-27 21:12:51 +02:00
|
|
|
V(N) += frame->nb_samples;
|
2013-04-10 17:28:38 +03:00
|
|
|
}
|
2010-11-03 00:29:17 +02:00
|
|
|
|
2023-12-27 21:12:51 +02:00
|
|
|
V(PREV_INPTS ) = TS2D(in_pts);
|
|
|
|
V(PREV_INT ) = TS2T(in_pts, inlink->time_base);
|
|
|
|
V(PREV_OUTPTS) = TS2D(frame->pts);
|
|
|
|
V(PREV_OUTT) = TS2T(frame->pts, inlink->time_base);
|
2012-08-08 14:44:11 +03:00
|
|
|
if (setpts->type == AVMEDIA_TYPE_AUDIO) {
|
2023-12-27 21:12:51 +02:00
|
|
|
V(NB_CONSUMED_SAMPLES) += frame->nb_samples;
|
2012-11-29 00:27:51 +03:00
|
|
|
}
|
|
|
|
return ff_filter_frame(inlink->dst->outputs[0], frame);
|
2010-11-03 00:29:17 +02:00
|
|
|
}
|
|
|
|
|
2019-09-30 13:53:59 +02:00
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
SetPTSContext *setpts = ctx->priv;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
AVFrame *in;
|
|
|
|
int status;
|
|
|
|
int64_t pts;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
|
|
|
|
|
|
|
ret = ff_inlink_consume_frame(inlink, &in);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (ret > 0)
|
|
|
|
return filter_frame(inlink, in);
|
|
|
|
|
|
|
|
if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
|
|
|
|
double d = eval_pts(setpts, inlink, NULL, pts);
|
|
|
|
|
lavu/frame: deprecate AVFrame.pkt_{pos,size}
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.
However,
- the fields are highly ad-hoc - there is no strong reason why
specifically those (and not any other) packet properties should have a
dedicated field in AVFrame; unlike e.g. the timestamps, there is no
fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
and even then it is not always the case that the encoded data was
stored in the file as a contiguous sequence of bytes (in order for pos
to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
passthrough of this information through lavfi in order to handle byte
seeking in ffplay. That is now implemented using arbitrary user data
passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
without using this field. Additonally, the values of this field
produced by libavcodec are flawed, as described in the previous
ffprobe conversion commit.
In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
2023-03-10 11:48:34 +02:00
|
|
|
av_log(ctx, AV_LOG_TRACE, "N:EOF PTS:%s T:%f -> PTS:%s T:%f\n",
|
2023-12-27 21:12:51 +02:00
|
|
|
d2istr(V(PTS)), V(T), d2istr(d), TS2T(d, inlink->time_base));
|
2019-09-30 13:53:59 +02:00
|
|
|
ff_outlink_set_status(outlink, status, D2TS(d));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FF_FILTER_FORWARD_WANTED(outlink, inlink);
|
|
|
|
|
|
|
|
return FFERROR_NOT_READY;
|
|
|
|
}
|
|
|
|
|
2010-11-03 00:29:17 +02:00
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
SetPTSContext *setpts = ctx->priv;
|
2010-11-08 16:06:49 +02:00
|
|
|
av_expr_free(setpts->expr);
|
2010-11-03 00:29:17 +02:00
|
|
|
setpts->expr = NULL;
|
|
|
|
}
|
|
|
|
|
2023-04-29 20:56:46 +02:00
|
|
|
static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg,
|
|
|
|
char *res, int res_len, int flags)
|
|
|
|
{
|
|
|
|
SetPTSContext *setpts = ctx->priv;
|
|
|
|
AVExpr *new_expr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!strcmp(cmd, "expr")) {
|
|
|
|
ret = av_expr_parse(&new_expr, arg, var_names, NULL, NULL, NULL, NULL, 0, ctx);
|
|
|
|
// Only free and replace previous expression if new one succeeds,
|
|
|
|
// otherwise defensively keep everything intact even if reporting an error.
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Error while parsing expression '%s'\n", arg);
|
|
|
|
} else {
|
|
|
|
av_expr_free(setpts->expr);
|
|
|
|
setpts->expr = new_expr;
|
2023-12-27 21:12:51 +02:00
|
|
|
V(T_CHANGE) = NAN;
|
2023-04-29 20:56:46 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2023-12-27 21:12:51 +02:00
|
|
|
#undef V
|
2023-04-29 20:56:46 +02:00
|
|
|
|
2013-04-12 16:46:52 +03:00
|
|
|
#define OFFSET(x) offsetof(SetPTSContext, x)
|
2020-06-13 08:26:39 +02:00
|
|
|
#define V AV_OPT_FLAG_VIDEO_PARAM
|
|
|
|
#define A AV_OPT_FLAG_AUDIO_PARAM
|
2023-04-29 20:56:46 +02:00
|
|
|
#define R AV_OPT_FLAG_RUNTIME_PARAM
|
2020-06-13 08:26:39 +02:00
|
|
|
#define F AV_OPT_FLAG_FILTERING_PARAM
|
2013-04-12 16:46:52 +03:00
|
|
|
|
2013-04-10 17:28:38 +03:00
|
|
|
#if CONFIG_SETPTS_FILTER
|
2020-06-13 08:26:39 +02:00
|
|
|
static const AVOption setpts_options[] = {
|
2023-04-29 20:56:46 +02:00
|
|
|
{ "expr", "Expression determining the frame timestamp", OFFSET(expr_str), AV_OPT_TYPE_STRING, { .str = "PTS" }, .flags = V|F|R },
|
2020-06-13 08:26:39 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
2013-05-27 14:14:43 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(setpts);
|
2013-04-12 16:46:52 +03:00
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_vf_setpts_inputs[] = {
|
2012-11-28 22:01:59 +03:00
|
|
|
{
|
2013-09-07 15:13:50 +03:00
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_input,
|
2012-11-28 22:01:59 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-03-27 14:55:26 +02:00
|
|
|
static const AVFilterPad outputs_video[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_output_video,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_vf_setpts = {
|
2023-04-29 20:56:46 +02:00
|
|
|
.name = "setpts",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Set PTS for the output video frame."),
|
|
|
|
.init = init,
|
|
|
|
.activate = activate,
|
|
|
|
.uninit = uninit,
|
|
|
|
.process_command = process_command,
|
|
|
|
.flags = AVFILTER_FLAG_METADATA_ONLY,
|
2012-08-08 14:44:11 +03:00
|
|
|
|
2010-11-03 00:29:17 +02:00
|
|
|
.priv_size = sizeof(SetPTSContext),
|
2013-02-25 23:21:29 +03:00
|
|
|
.priv_class = &setpts_class,
|
2013-04-11 00:48:26 +03:00
|
|
|
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_INPUTS(avfilter_vf_setpts_inputs),
|
2024-03-27 14:55:26 +02:00
|
|
|
FILTER_OUTPUTS(outputs_video),
|
2013-04-11 00:48:26 +03:00
|
|
|
};
|
2013-05-01 11:59:21 +03:00
|
|
|
#endif /* CONFIG_SETPTS_FILTER */
|
2013-04-11 00:48:26 +03:00
|
|
|
|
2013-04-10 17:28:38 +03:00
|
|
|
#if CONFIG_ASETPTS_FILTER
|
2013-05-01 11:59:21 +03:00
|
|
|
|
2020-06-13 08:26:39 +02:00
|
|
|
static const AVOption asetpts_options[] = {
|
2023-04-29 20:56:46 +02:00
|
|
|
{ "expr", "Expression determining the frame timestamp", OFFSET(expr_str), AV_OPT_TYPE_STRING, { .str = "PTS" }, .flags = A|F|R },
|
2020-06-13 08:26:39 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
2013-05-27 14:14:43 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(asetpts);
|
2013-04-11 00:48:26 +03:00
|
|
|
|
2013-04-10 17:28:38 +03:00
|
|
|
static const AVFilterPad asetpts_inputs[] = {
|
2012-10-11 16:41:56 +03:00
|
|
|
{
|
2013-09-07 15:13:50 +03:00
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_input,
|
2012-10-11 16:41:56 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_af_asetpts = {
|
2023-04-29 20:56:46 +02:00
|
|
|
.name = "asetpts",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Set PTS for the output audio frame."),
|
|
|
|
.init = init,
|
|
|
|
.activate = activate,
|
|
|
|
.uninit = uninit,
|
|
|
|
.process_command = process_command,
|
|
|
|
.priv_size = sizeof(SetPTSContext),
|
|
|
|
.priv_class = &asetpts_class,
|
|
|
|
.flags = AVFILTER_FLAG_METADATA_ONLY,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_INPUTS(asetpts_inputs),
|
2023-08-03 00:59:02 +02:00
|
|
|
FILTER_OUTPUTS(ff_audio_default_filterpad),
|
2010-11-03 00:29:17 +02:00
|
|
|
};
|
2013-05-01 11:59:21 +03:00
|
|
|
#endif /* CONFIG_ASETPTS_FILTER */
|