summaryrefslogtreecommitdiff
path: root/libavfilter/f_reverse.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-01-27 23:52:14 +0100
committerPaul B Mahol <onemda@gmail.com>2023-01-27 23:53:26 +0100
commitac37b2c2b12bd256c29f92a2feebfa20b08f5f5c (patch)
tree96d51c7d9f717664a20eae9d9658465b5d0071f1 /libavfilter/f_reverse.c
parentd9b07a98539b9d395df5d5e6a1d8ea91210991ee (diff)
downloadffmpeg-ac37b2c2b12bd256c29f92a2feebfa20b08f5f5c.tar.gz
avfilter/f_reverse: set output frame duration
Diffstat (limited to 'libavfilter/f_reverse.c')
-rw-r--r--libavfilter/f_reverse.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/libavfilter/f_reverse.c b/libavfilter/f_reverse.c
index 2c99557c75..0ab2a3ab29 100644
--- a/libavfilter/f_reverse.c
+++ b/libavfilter/f_reverse.c
@@ -33,7 +33,9 @@ typedef struct ReverseContext {
AVFrame **frames;
unsigned int frames_size;
unsigned int pts_size;
+ unsigned int duration_size;
int64_t *pts;
+ int64_t *duration;
int flush_idx;
int64_t nb_samples;
} ReverseContext;
@@ -47,12 +49,15 @@ static av_cold int init(AVFilterContext *ctx)
if (!s->pts)
return AVERROR(ENOMEM);
+ s->duration = av_fast_realloc(NULL, &s->duration_size,
+ DEFAULT_LENGTH * sizeof(*(s->duration)));
+ if (!s->duration)
+ return AVERROR(ENOMEM);
+
s->frames = av_fast_realloc(NULL, &s->frames_size,
DEFAULT_LENGTH * sizeof(*(s->frames)));
- if (!s->frames) {
- av_freep(&s->pts);
+ if (!s->frames)
return AVERROR(ENOMEM);
- }
return 0;
}
@@ -67,6 +72,7 @@ static av_cold void uninit(AVFilterContext *ctx)
}
av_freep(&s->pts);
+ av_freep(&s->duration);
av_freep(&s->frames);
}
@@ -83,6 +89,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
s->pts = ptr;
}
+ if (s->nb_frames + 1 > s->duration_size / sizeof(*(s->duration))) {
+ ptr = av_fast_realloc(s->duration, &s->duration_size, s->duration_size * 2);
+ if (!ptr)
+ return AVERROR(ENOMEM);
+ s->duration = ptr;
+ }
+
if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) {
ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);
if (!ptr)
@@ -92,6 +105,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
s->frames[s->nb_frames] = in;
s->pts[s->nb_frames] = in->pts;
+ s->duration[s->nb_frames] = in->duration;
s->nb_frames++;
return 0;
@@ -109,6 +123,7 @@ static int request_frame(AVFilterLink *outlink)
if (ret == AVERROR_EOF && s->nb_frames > 0) {
AVFrame *out = s->frames[s->nb_frames - 1];
+ out->duration= s->duration[s->flush_idx];
out->pts = s->pts[s->flush_idx++];
ret = ff_filter_frame(outlink, out);
s->frames[s->nb_frames - 1] = NULL;
@@ -252,6 +267,7 @@ static int areverse_request_frame(AVFilterLink *outlink)
if (ret == AVERROR_EOF && s->nb_frames > 0) {
AVFrame *out = s->frames[s->nb_frames - 1];
+ out->duration = s->duration[s->flush_idx];
out->pts = s->pts[s->flush_idx++] - s->nb_samples;
s->nb_samples += s->pts[s->flush_idx] - s->pts[s->flush_idx - 1] - out->nb_samples;