* [FFmpeg-devel] [PATCH 2/6] avcodec/bsf: add a capabilities field to AVBitStreamFilter
2022-02-14 22:41 [FFmpeg-devel] [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios James Almer
@ 2022-02-14 22:41 ` James Almer
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 3/6] avcodec/bsf: set delay capability on the list filter James Almer
` (4 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: James Almer @ 2022-02-14 22:41 UTC (permalink / raw)
To: ffmpeg-devel
And a first flag to signal that the bsf buffers packets and needs to
be drained
Signed-off-by: James Almer <jamrial@gmail.com>
---
Missing APIChanges entry and version bump.
libavcodec/bsf.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h
index 8c5355d186..798c6470ee 100644
--- a/libavcodec/bsf.h
+++ b/libavcodec/bsf.h
@@ -87,6 +87,12 @@ typedef struct AVBSFContext {
AVRational time_base_out;
} AVBSFContext;
+/**
+ * The bitstream filter requires flushing with NULL input at the end in order
+ * to drain all buffered packets and give the complete and correct output.
+ */
+#define AV_BSF_CAP_DELAY (1 << 0)
+
typedef struct AVBitStreamFilter {
const char *name;
@@ -108,6 +114,12 @@ typedef struct AVBitStreamFilter {
*/
const AVClass *priv_class;
+ /**
+ * Filter capabilities.
+ * see AV_BSF_CAP_*
+ */
+ int capabilities;
+
/*****************************************************************
* No fields below this line are part of the public API. They
* may not be used outside of libavcodec and can be changed and
--
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH 3/6] avcodec/bsf: set delay capability on the list filter
2022-02-14 22:41 [FFmpeg-devel] [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios James Almer
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 2/6] avcodec/bsf: add a capabilities field to AVBitStreamFilter James Almer
@ 2022-02-14 22:41 ` James Almer
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used James Almer
` (3 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: James Almer @ 2022-02-14 22:41 UTC (permalink / raw)
To: ffmpeg-devel
AVBitStreamFilter structures are const, so we can't set its capabilities based
on the filters added to the list.
Set the delay cap to ensure correct behavior if any bsf in the list sets it.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/bsf.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index 8ba021cb47..a784aaaa95 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -406,6 +406,7 @@ static const AVBitStreamFilter list_bsf = {
.filter = bsf_list_filter,
.flush = bsf_list_flush,
.close = bsf_list_close,
+ .capabilities = AV_BSF_CAP_DELAY,
};
struct AVBSFList {
--
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
2022-02-14 22:41 [FFmpeg-devel] [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios James Almer
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 2/6] avcodec/bsf: add a capabilities field to AVBitStreamFilter James Almer
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 3/6] avcodec/bsf: set delay capability on the list filter James Almer
@ 2022-02-14 22:41 ` James Almer
2022-02-15 11:41 ` Anton Khirnov
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 5/6] avcodec/setts_bsf: add NEXT_PTS/DTS expression constants James Almer
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: James Almer @ 2022-02-14 22:41 UTC (permalink / raw)
To: ffmpeg-devel
A keyframe could be buffered in the bsf and not be output until more packets
had been fed to it.
Signed-off-by: James Almer <jamrial@gmail.com>
---
fftools/ffmpeg.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6aa0986f02..48d9016b4c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2026,7 +2026,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
}
if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
- !ost->copy_initial_nonkeyframes)
+ !ost->copy_initial_nonkeyframes &&
+ !(ost->bsf_ctx && ost->bsf_ctx->filter->capabilities & AV_BSF_CAP_DELAY))
return;
if (!ost->frame_number && !ost->copy_prior_start) {
--
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used James Almer
@ 2022-02-15 11:41 ` Anton Khirnov
2022-02-15 11:48 ` James Almer
0 siblings, 1 reply; 14+ messages in thread
From: Anton Khirnov @ 2022-02-15 11:41 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2022-02-14 23:41:54)
> A keyframe could be buffered in the bsf and not be output until more packets
> had been fed to it.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> fftools/ffmpeg.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 6aa0986f02..48d9016b4c 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2026,7 +2026,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
> }
>
> if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
> - !ost->copy_initial_nonkeyframes)
> + !ost->copy_initial_nonkeyframes &&
> + !(ost->bsf_ctx && ost->bsf_ctx->filter->capabilities & AV_BSF_CAP_DELAY))
> return;
Wouldn't it be simpler to add an OutputStream field that tracks whether
we've seen a keyframe packet yet? No new API required.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
2022-02-15 11:41 ` Anton Khirnov
@ 2022-02-15 11:48 ` James Almer
2022-02-15 12:03 ` Anton Khirnov
0 siblings, 1 reply; 14+ messages in thread
From: James Almer @ 2022-02-15 11:48 UTC (permalink / raw)
To: ffmpeg-devel
On 2/15/2022 8:41 AM, Anton Khirnov wrote:
> Quoting James Almer (2022-02-14 23:41:54)
>> A keyframe could be buffered in the bsf and not be output until more packets
>> had been fed to it.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> fftools/ffmpeg.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
>> index 6aa0986f02..48d9016b4c 100644
>> --- a/fftools/ffmpeg.c
>> +++ b/fftools/ffmpeg.c
>> @@ -2026,7 +2026,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
>> }
>>
>> if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
>> - !ost->copy_initial_nonkeyframes)
>> + !ost->copy_initial_nonkeyframes &&
>> + !(ost->bsf_ctx && ost->bsf_ctx->filter->capabilities & AV_BSF_CAP_DELAY))
>> return;
>
> Wouldn't it be simpler to add an OutputStream field that tracks whether
> we've seen a keyframe packet yet? No new API required.
Probably. It would also only trigger when a keyframe was seen instead of
unconditionally for all delay flagged bsfs.
I still think this new API is a good addition, either way. Only a
handful of bsfs buffer packets and require the caller to flush them
after sending NULL (av1_frame_merge, vp9_superframe, and setts after
this set) so library users could have all this time never signaled EOF
and never noticed anything wrong, much like it happened here.
The presence of this flag might help library users know they really need
to signal EOF.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
2022-02-15 11:48 ` James Almer
@ 2022-02-15 12:03 ` Anton Khirnov
2022-02-15 12:12 ` James Almer
0 siblings, 1 reply; 14+ messages in thread
From: Anton Khirnov @ 2022-02-15 12:03 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2022-02-15 12:48:09)
>
>
> On 2/15/2022 8:41 AM, Anton Khirnov wrote:
> > Quoting James Almer (2022-02-14 23:41:54)
> >> A keyframe could be buffered in the bsf and not be output until more packets
> >> had been fed to it.
> >>
> >> Signed-off-by: James Almer <jamrial@gmail.com>
> >> ---
> >> fftools/ffmpeg.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> >> index 6aa0986f02..48d9016b4c 100644
> >> --- a/fftools/ffmpeg.c
> >> +++ b/fftools/ffmpeg.c
> >> @@ -2026,7 +2026,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
> >> }
> >>
> >> if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
> >> - !ost->copy_initial_nonkeyframes)
> >> + !ost->copy_initial_nonkeyframes &&
> >> + !(ost->bsf_ctx && ost->bsf_ctx->filter->capabilities & AV_BSF_CAP_DELAY))
> >> return;
> >
> > Wouldn't it be simpler to add an OutputStream field that tracks whether
> > we've seen a keyframe packet yet? No new API required.
>
> Probably. It would also only trigger when a keyframe was seen instead of
> unconditionally for all delay flagged bsfs.
>
> I still think this new API is a good addition, either way. Only a
> handful of bsfs buffer packets and require the caller to flush them
> after sending NULL (av1_frame_merge, vp9_superframe, and setts after
> this set) so library users could have all this time never signaled EOF
> and never noticed anything wrong, much like it happened here.
> The presence of this flag might help library users know they really need
> to signal EOF.
I don't see where the advantage would be. The callers still need to have
the flushing code, so might as well always call it.
The disadvantage for us is more complixity and we have to maintain the
list of delay BSFs.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
2022-02-15 12:03 ` Anton Khirnov
@ 2022-02-15 12:12 ` James Almer
2022-02-21 15:34 ` Anton Khirnov
0 siblings, 1 reply; 14+ messages in thread
From: James Almer @ 2022-02-15 12:12 UTC (permalink / raw)
To: ffmpeg-devel
On 2/15/2022 9:03 AM, Anton Khirnov wrote:
> Quoting James Almer (2022-02-15 12:48:09)
>>
>>
>> On 2/15/2022 8:41 AM, Anton Khirnov wrote:
>>> Quoting James Almer (2022-02-14 23:41:54)
>>>> A keyframe could be buffered in the bsf and not be output until more packets
>>>> had been fed to it.
>>>>
>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>> ---
>>>> fftools/ffmpeg.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
>>>> index 6aa0986f02..48d9016b4c 100644
>>>> --- a/fftools/ffmpeg.c
>>>> +++ b/fftools/ffmpeg.c
>>>> @@ -2026,7 +2026,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
>>>> }
>>>>
>>>> if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
>>>> - !ost->copy_initial_nonkeyframes)
>>>> + !ost->copy_initial_nonkeyframes &&
>>>> + !(ost->bsf_ctx && ost->bsf_ctx->filter->capabilities & AV_BSF_CAP_DELAY))
>>>> return;
>>>
>>> Wouldn't it be simpler to add an OutputStream field that tracks whether
>>> we've seen a keyframe packet yet? No new API required.
>>
>> Probably. It would also only trigger when a keyframe was seen instead of
>> unconditionally for all delay flagged bsfs.
>>
>> I still think this new API is a good addition, either way. Only a
>> handful of bsfs buffer packets and require the caller to flush them
>> after sending NULL (av1_frame_merge, vp9_superframe, and setts after
>> this set) so library users could have all this time never signaled EOF
>> and never noticed anything wrong, much like it happened here.
>> The presence of this flag might help library users know they really need
>> to signal EOF.
>
> I don't see where the advantage would be. The callers still need to have
> the flushing code, so might as well always call it.
Then we probably need to enforce it in the doxy, or at least strongly
suggest it with a @note or @warning line to ensure you get complete output.
Right now it's optional, mentioned as "If you send a NULL packet, it
will trigger EOF", meaning not doing so is still a valid scenario, and
there's nothing letting the user know he's got packets stuck in the bsf
even after receive_packet() returned EAGAIN if they don't.
>
> The disadvantage for us is more complixity and we have to maintain the
> list of delay BSFs.
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
2022-02-15 12:12 ` James Almer
@ 2022-02-21 15:34 ` Anton Khirnov
0 siblings, 0 replies; 14+ messages in thread
From: Anton Khirnov @ 2022-02-21 15:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2022-02-15 13:12:51)
> On 2/15/2022 9:03 AM, Anton Khirnov wrote:
> > Quoting James Almer (2022-02-15 12:48:09)
> >>
> >>
> >> On 2/15/2022 8:41 AM, Anton Khirnov wrote:
> >>> Quoting James Almer (2022-02-14 23:41:54)
> >>>> A keyframe could be buffered in the bsf and not be output until more packets
> >>>> had been fed to it.
> >>>>
> >>>> Signed-off-by: James Almer <jamrial@gmail.com>
> >>>> ---
> >>>> fftools/ffmpeg.c | 3 ++-
> >>>> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> >>>> index 6aa0986f02..48d9016b4c 100644
> >>>> --- a/fftools/ffmpeg.c
> >>>> +++ b/fftools/ffmpeg.c
> >>>> @@ -2026,7 +2026,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
> >>>> }
> >>>>
> >>>> if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
> >>>> - !ost->copy_initial_nonkeyframes)
> >>>> + !ost->copy_initial_nonkeyframes &&
> >>>> + !(ost->bsf_ctx && ost->bsf_ctx->filter->capabilities & AV_BSF_CAP_DELAY))
> >>>> return;
> >>>
> >>> Wouldn't it be simpler to add an OutputStream field that tracks whether
> >>> we've seen a keyframe packet yet? No new API required.
> >>
> >> Probably. It would also only trigger when a keyframe was seen instead of
> >> unconditionally for all delay flagged bsfs.
> >>
> >> I still think this new API is a good addition, either way. Only a
> >> handful of bsfs buffer packets and require the caller to flush them
> >> after sending NULL (av1_frame_merge, vp9_superframe, and setts after
> >> this set) so library users could have all this time never signaled EOF
> >> and never noticed anything wrong, much like it happened here.
> >> The presence of this flag might help library users know they really need
> >> to signal EOF.
> >
> > I don't see where the advantage would be. The callers still need to have
> > the flushing code, so might as well always call it.
>
> Then we probably need to enforce it in the doxy, or at least strongly
> suggest it with a @note or @warning line to ensure you get complete output.
> Right now it's optional, mentioned as "If you send a NULL packet, it
> will trigger EOF", meaning not doing so is still a valid scenario, and
> there's nothing letting the user know he's got packets stuck in the bsf
> even after receive_packet() returned EAGAIN if they don't.
The doxy for av_bsf_send_packet() already says:
If pkt is empty, it signals the end of the stream and will cause the
filter to output any packets it may have buffered internally.
But I can write something more explicit.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH 5/6] avcodec/setts_bsf: add NEXT_PTS/DTS expression constants
2022-02-14 22:41 [FFmpeg-devel] [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios James Almer
` (2 preceding siblings ...)
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used James Almer
@ 2022-02-14 22:41 ` James Almer
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration James Almer
2022-02-15 15:56 ` [FFmpeg-devel] [PATCH 2/4] ffmpeg: ensure a keyframe was not seen before skipping packets James Almer
5 siblings, 0 replies; 14+ messages in thread
From: James Almer @ 2022-02-14 22:41 UTC (permalink / raw)
To: ffmpeg-devel
They correspond to the relevant fields in the packet that follows the one where
the expressions are being applied to.
Signed-off-by: James Almer <jamrial@gmail.com>
---
Missing doc changes.
libavcodec/setts_bsf.c | 76 ++++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 25 deletions(-)
diff --git a/libavcodec/setts_bsf.c b/libavcodec/setts_bsf.c
index d604f91f71..35266ee251 100644
--- a/libavcodec/setts_bsf.c
+++ b/libavcodec/setts_bsf.c
@@ -37,6 +37,8 @@ static const char *const var_names[] = {
"PREV_INDTS", ///< previous input DTS
"PREV_OUTPTS", ///< previous output PTS
"PREV_OUTDTS", ///< previous output DTS
+ "NEXT_PTS", ///< next input PTS
+ "NEXT_DTS", ///< next input DTS
"PTS", ///< original PTS in the file of the frame
"DTS", ///< original DTS in the file of the frame
"STARTPTS", ///< PTS at start of movie
@@ -55,6 +57,8 @@ enum var_name {
VAR_PREV_INDTS,
VAR_PREV_OUTPTS,
VAR_PREV_OUTDTS,
+ VAR_NEXT_PTS,
+ VAR_NEXT_DTS,
VAR_PTS,
VAR_DTS,
VAR_STARTPTS,
@@ -76,16 +80,16 @@ typedef struct SetTSContext {
int64_t start_pts;
int64_t start_dts;
- int64_t prev_inpts;
- int64_t prev_indts;
- int64_t prev_outpts;
- int64_t prev_outdts;
double var_values[VAR_VARS_NB];
AVExpr *ts_expr;
AVExpr *pts_expr;
AVExpr *dts_expr;
+
+ AVPacket *prev_inpkt;
+ AVPacket *prev_outpkt;
+ AVPacket *cur_pkt;
} SetTSContext;
static int setts_init(AVBSFContext *ctx)
@@ -93,6 +97,12 @@ static int setts_init(AVBSFContext *ctx)
SetTSContext *s = ctx->priv_data;
int ret;
+ s->prev_inpkt = av_packet_alloc();
+ s->prev_outpkt = av_packet_alloc();
+ s->cur_pkt = av_packet_alloc();
+ if (!s->prev_inpkt || !s->prev_outpkt || !s->cur_pkt)
+ return AVERROR(ENOMEM);
+
if ((ret = av_expr_parse(&s->ts_expr, s->ts_str,
var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Error while parsing ts expression '%s'\n", s->ts_str);
@@ -118,10 +128,6 @@ static int setts_init(AVBSFContext *ctx)
s->frame_number= 0;
s->start_pts = AV_NOPTS_VALUE;
s->start_dts = AV_NOPTS_VALUE;
- s->prev_inpts = AV_NOPTS_VALUE;
- s->prev_indts = AV_NOPTS_VALUE;
- s->prev_outpts = AV_NOPTS_VALUE;
- s->prev_outdts = AV_NOPTS_VALUE;
s->var_values[VAR_NOPTS] = AV_NOPTS_VALUE;
return 0;
@@ -134,24 +140,31 @@ static int setts_filter(AVBSFContext *ctx, AVPacket *pkt)
int ret;
ret = ff_bsf_get_packet_ref(ctx, pkt);
- if (ret < 0)
+ if (ret < 0 && (ret != AVERROR_EOF || !s->cur_pkt->data))
return ret;
+ if (!s->cur_pkt->data) {
+ av_packet_move_ref(s->cur_pkt, pkt);
+ return AVERROR(EAGAIN);
+ }
+
if (s->start_pts == AV_NOPTS_VALUE)
- s->start_pts = pkt->pts;
+ s->start_pts = s->cur_pkt->pts;
if (s->start_dts == AV_NOPTS_VALUE)
- s->start_dts = pkt->dts;
+ s->start_dts = s->cur_pkt->dts;
s->var_values[VAR_N] = s->frame_number++;
- s->var_values[VAR_TS] = pkt->dts;
- s->var_values[VAR_POS] = pkt->pos;
- s->var_values[VAR_PTS] = pkt->pts;
- s->var_values[VAR_DTS] = pkt->dts;
- s->var_values[VAR_PREV_INPTS] = s->prev_inpts;
- s->var_values[VAR_PREV_INDTS] = s->prev_indts;
- s->var_values[VAR_PREV_OUTPTS] = s->prev_outpts;
- s->var_values[VAR_PREV_OUTDTS] = s->prev_outdts;
+ s->var_values[VAR_TS] = s->cur_pkt->dts;
+ 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_PREV_INPTS] = s->prev_inpkt->pts;
+ s->var_values[VAR_PREV_INDTS] = s->prev_inpkt->dts;
+ s->var_values[VAR_PREV_OUTPTS] = s->prev_outpkt->pts;
+ s->var_values[VAR_PREV_OUTDTS] = s->prev_outpkt->dts;
+ s->var_values[VAR_NEXT_PTS] = pkt->pts;
+ s->var_values[VAR_NEXT_DTS] = pkt->dts;
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;
@@ -160,27 +173,35 @@ static int setts_filter(AVBSFContext *ctx, AVPacket *pkt)
new_ts = llrint(av_expr_eval(s->ts_expr, s->var_values, NULL));
if (s->pts_str) {
- s->var_values[VAR_TS] = pkt->pts;
+ s->var_values[VAR_TS] = s->cur_pkt->pts;
new_pts = llrint(av_expr_eval(s->pts_expr, s->var_values, NULL));
} else {
new_pts = new_ts;
}
if (s->dts_str) {
- s->var_values[VAR_TS] = pkt->dts;
+ s->var_values[VAR_TS] = s->cur_pkt->dts;
new_dts = llrint(av_expr_eval(s->dts_expr, s->var_values, NULL));
} else {
new_dts = new_ts;
}
- s->prev_inpts = pkt->pts;
- s->prev_indts = pkt->dts;
- s->prev_outpts = new_pts;
- s->prev_outdts = new_dts;
+ av_packet_unref(s->prev_inpkt);
+ av_packet_unref(s->prev_outpkt);
+ av_packet_move_ref(s->prev_inpkt, s->cur_pkt);
+ av_packet_move_ref(s->cur_pkt, pkt);
+
+ ret = av_packet_ref(pkt, s->prev_inpkt);
+ if (ret < 0)
+ return ret;
pkt->pts = new_pts;
pkt->dts = new_dts;
+ ret = av_packet_ref(s->prev_outpkt, pkt);
+ if (ret < 0)
+ av_packet_unref(pkt);
+
return ret;
}
@@ -188,6 +209,10 @@ static void setts_close(AVBSFContext *bsf)
{
SetTSContext *s = bsf->priv_data;
+ av_packet_free(&s->prev_inpkt);
+ av_packet_free(&s->prev_outpkt);
+ av_packet_free(&s->cur_pkt);
+
av_expr_free(s->ts_expr);
s->ts_expr = NULL;
av_expr_free(s->pts_expr);
@@ -220,4 +245,5 @@ const AVBitStreamFilter ff_setts_bsf = {
.init = setts_init,
.close = setts_close,
.filter = setts_filter,
+ .capabilities = AV_BSF_CAP_DELAY,
};
--
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration
2022-02-14 22:41 [FFmpeg-devel] [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios James Almer
` (3 preceding siblings ...)
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 5/6] avcodec/setts_bsf: add NEXT_PTS/DTS expression constants James Almer
@ 2022-02-14 22:41 ` James Almer
2022-02-22 16:49 ` James Almer
2022-02-15 15:56 ` [FFmpeg-devel] [PATCH 2/4] ffmpeg: ensure a keyframe was not seen before skipping packets James Almer
5 siblings, 1 reply; 14+ messages in thread
From: James Almer @ 2022-02-14 22:41 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
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 },
};
--
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration James Almer
@ 2022-02-22 16:49 ` James Almer
2022-02-22 16:55 ` Paul B Mahol
0 siblings, 1 reply; 14+ messages in thread
From: James Almer @ 2022-02-22 16:49 UTC (permalink / raw)
To: ffmpeg-devel
On 2/14/2022 7:41 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> Missing doc changes.
>
> libavcodec/setts_bsf.c | 25 ++++++++++++++++++++++++-
> 1 file changed, 24 insertions(+), 1 deletion(-)
Ping for set.
Original patches 2, 3 and 4 are withdrawn, so the set is:
[PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios
[PATCH 2/4] ffmpeg: ensure a keyframe was not seen before skipping packets
[PATCH 5/6] avcodec/setts_bsf: add NEXT_PTS/DTS expression constants
[PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration
2022-02-22 16:49 ` James Almer
@ 2022-02-22 16:55 ` Paul B Mahol
0 siblings, 0 replies; 14+ messages in thread
From: Paul B Mahol @ 2022-02-22 16:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, Feb 22, 2022 at 5:50 PM James Almer <jamrial@gmail.com> wrote:
> On 2/14/2022 7:41 PM, James Almer wrote:
> > Signed-off-by: James Almer <jamrial@gmail.com>
> > ---
> > Missing doc changes.
> >
> > libavcodec/setts_bsf.c | 25 ++++++++++++++++++++++++-
> > 1 file changed, 24 insertions(+), 1 deletion(-)
>
> Ping for set.
>
> Original patches 2, 3 and 4 are withdrawn, so the set is:
> [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios
> [PATCH 2/4] ffmpeg: ensure a keyframe was not seen before skipping packets
> [PATCH 5/6] avcodec/setts_bsf: add NEXT_PTS/DTS expression constants
> [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration
>
setts_bsf changes LGTM
> _______________________________________________
> 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".
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH 2/4] ffmpeg: ensure a keyframe was not seen before skipping packets
2022-02-14 22:41 [FFmpeg-devel] [PATCH 1/6] ffmpeg: flush delayed frames in codec copy scenarios James Almer
` (4 preceding siblings ...)
2022-02-14 22:41 ` [FFmpeg-devel] [PATCH 6/6] avcodec/setts_bsf: add constants to modify packet duration James Almer
@ 2022-02-15 15:56 ` James Almer
5 siblings, 0 replies; 14+ messages in thread
From: James Almer @ 2022-02-15 15:56 UTC (permalink / raw)
To: ffmpeg-devel
A keyframe could be buffered in the bsf and not be output until more packets
had been fed to it.
Signed-off-by: James Almer <jamrial@gmail.com>
---
This replaces/supersedes
[PATCH 2/6] avcodec/bsf: add a capabilities field to AVBitStreamFilter
[PATCH 4/6] ffmpeg: don't skip packets before a keyframe was seen if a bsf with delay is used
fftools/ffmpeg.c | 4 +++-
fftools/ffmpeg.h | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6aa0986f02..2a56b2f0e7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -889,6 +889,8 @@ static void output_packet(OutputFile *of, AVPacket *pkt,
/* apply the output bitstream filters */
if (ost->bsf_ctx) {
+ if (pkt && (pkt->flags & AV_PKT_FLAG_KEY))
+ ost->seen_kf = 1;
ret = av_bsf_send_packet(ost->bsf_ctx, eof ? NULL : pkt);
if (ret < 0)
goto finish;
@@ -2026,7 +2028,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
}
if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
- !ost->copy_initial_nonkeyframes)
+ !ost->copy_initial_nonkeyframes && !ost->seen_kf)
return;
if (!ost->frame_number && !ost->copy_prior_start) {
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 1b8bbace3f..cc8f767e5d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -535,6 +535,7 @@ typedef struct OutputStream {
int inputs_done;
const char *attachment_filename;
+ int seen_kf;
int copy_initial_nonkeyframes;
int copy_prior_start;
char *disposition;
--
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".
^ permalink raw reply [flat|nested] 14+ messages in thread