History

avfilter/f_reverse: set output frame duration

Paul B Mahol committed 3 years ago

Commit ac37b2c1 parent d9b07a91 file · +19 −3Browse files

Unified · Split

libavfilter/f_reverse.c+19−3
@@ -33,7 +33,9 @@ typedef struct ReverseContext { · 32 unmodified lines
3333 AVFrame **frames;
3434 unsigned int frames_size;
3535 unsigned int pts_size;
36+ unsigned int duration_size;
3637 int64_t *pts;
38+ int64_t *duration;
3739 int flush_idx;
3840 int64_t nb_samples;
3941 } ReverseContext;
@@ -47,12 +49,15 @@ static av_cold int init(AVFilterContext *ctx) · 7 unmodified lines
4749 if (!s->pts)
4850 return AVERROR(ENOMEM);
4951
52+ s->duration = av_fast_realloc(NULL, &s->duration_size,
53+ DEFAULT_LENGTH * sizeof(*(s->duration)));
54+ if (!s->duration)
55+ return AVERROR(ENOMEM);
56+
5057 s->frames = av_fast_realloc(NULL, &s->frames_size,
5158 DEFAULT_LENGTH * sizeof(*(s->frames)));
52− if (!s->frames) {
53− av_freep(&s->pts);
59+ if (!s->frames)
5460 return AVERROR(ENOMEM);
55− }
5661
5762 return 0;
5863 }
@@ -67,6 +72,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 8 unmodified lines
6772 }
6873
6974 av_freep(&s->pts);
75+ av_freep(&s->duration);
7076 av_freep(&s->frames);
7177 }
7278
@@ -83,6 +89,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 10 unmodified lines
8389 s->pts = ptr;
8490 }
8591
92+ if (s->nb_frames + 1 > s->duration_size / sizeof(*(s->duration))) {
93+ ptr = av_fast_realloc(s->duration, &s->duration_size, s->duration_size * 2);
94+ if (!ptr)
95+ return AVERROR(ENOMEM);
96+ s->duration = ptr;
97+ }
98+
8699 if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) {
87100 ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);
88101 if (!ptr)
@@ -92,6 +105,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 3 unmodified lines
92105
93106 s->frames[s->nb_frames] = in;
94107 s->pts[s->nb_frames] = in->pts;
108+ s->duration[s->nb_frames] = in->duration;
95109 s->nb_frames++;
96110
97111 return 0;
@@ -109,6 +123,7 @@ static int request_frame(AVFilterLink *outlink) · 11 unmodified lines
109123
110124 if (ret == AVERROR_EOF && s->nb_frames > 0) {
111125 AVFrame *out = s->frames[s->nb_frames - 1];
126+ out->duration= s->duration[s->flush_idx];
112127 out->pts = s->pts[s->flush_idx++];
113128 ret = ff_filter_frame(outlink, out);
114129 s->frames[s->nb_frames - 1] = NULL;
@@ -252,6 +267,7 @@ static int areverse_request_frame(AVFilterLink *outlink) · 137 unmodified lines
252267
253268 if (ret == AVERROR_EOF && s->nb_frames > 0) {
254269 AVFrame *out = s->frames[s->nb_frames - 1];
270+ out->duration = s->duration[s->flush_idx];
255271 out->pts = s->pts[s->flush_idx++] - s->nb_samples;
256272 s->nb_samples += s->pts[s->flush_idx] - s->pts[s->flush_idx - 1] - out->nb_samples;
257273

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t