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
33 AVFrame **frames;33 AVFrame **frames;
34 unsigned int frames_size;34 unsigned int frames_size;
35 unsigned int pts_size;35 unsigned int pts_size;
36 unsigned int duration_size;
36 int64_t *pts;37 int64_t *pts;
38 int64_t *duration;
37 int flush_idx;39 int flush_idx;
38 int64_t nb_samples;40 int64_t nb_samples;
39} ReverseContext;41} ReverseContext;
@@ -47,12 +49,15 @@ static av_cold int init(AVFilterContext *ctx) · 7 unmodified lines
47 if (!s->pts)49 if (!s->pts)
48 return AVERROR(ENOMEM);50 return AVERROR(ENOMEM);
49 51
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
50 s->frames = av_fast_realloc(NULL, &s->frames_size,57 s->frames = av_fast_realloc(NULL, &s->frames_size,
51 DEFAULT_LENGTH * sizeof(*(s->frames)));58 DEFAULT_LENGTH * sizeof(*(s->frames)));
52 if (!s->frames) {59 if (!s->frames)
53 av_freep(&s->pts);
54 return AVERROR(ENOMEM);60 return AVERROR(ENOMEM);
55 }
56 61
57 return 0;62 return 0;
58}63}
@@ -67,6 +72,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 8 unmodified lines
67 }72 }
68 73
69 av_freep(&s->pts);74 av_freep(&s->pts);
75 av_freep(&s->duration);
70 av_freep(&s->frames);76 av_freep(&s->frames);
71}77}
72 78
@@ -83,6 +89,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 10 unmodified lines
83 s->pts = ptr;89 s->pts = ptr;
84 }90 }
85 91
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
86 if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) {99 if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) {
87 ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);100 ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);
88 if (!ptr)101 if (!ptr)
@@ -92,6 +105,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 3 unmodified lines
92 105
93 s->frames[s->nb_frames] = in;106 s->frames[s->nb_frames] = in;
94 s->pts[s->nb_frames] = in->pts;107 s->pts[s->nb_frames] = in->pts;
108 s->duration[s->nb_frames] = in->duration;
95 s->nb_frames++;109 s->nb_frames++;
96 110
97 return 0;111 return 0;
@@ -109,6 +123,7 @@ static int request_frame(AVFilterLink *outlink) · 11 unmodified lines
109 123
110 if (ret == AVERROR_EOF && s->nb_frames > 0) {124 if (ret == AVERROR_EOF && s->nb_frames > 0) {
111 AVFrame *out = s->frames[s->nb_frames - 1];125 AVFrame *out = s->frames[s->nb_frames - 1];
126 out->duration= s->duration[s->flush_idx];
112 out->pts = s->pts[s->flush_idx++];127 out->pts = s->pts[s->flush_idx++];
113 ret = ff_filter_frame(outlink, out);128 ret = ff_filter_frame(outlink, out);
114 s->frames[s->nb_frames - 1] = NULL;129 s->frames[s->nb_frames - 1] = NULL;
@@ -252,6 +267,7 @@ static int areverse_request_frame(AVFilterLink *outlink) · 137 unmodified lines
252 267
253 if (ret == AVERROR_EOF && s->nb_frames > 0) {268 if (ret == AVERROR_EOF && s->nb_frames > 0) {
254 AVFrame *out = s->frames[s->nb_frames - 1];269 AVFrame *out = s->frames[s->nb_frames - 1];
270 out->duration = s->duration[s->flush_idx];
255 out->pts = s->pts[s->flush_idx++] - s->nb_samples;271 out->pts = s->pts[s->flush_idx++] - s->nb_samples;
256 s->nb_samples += s->pts[s->flush_idx] - s->pts[s->flush_idx - 1] - out->nb_samples;272 s->nb_samples += s->pts[s->flush_idx] - s->pts[s->flush_idx - 1] - out->nb_samples;
257 273

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