mirror of https://git.ffmpeg.org/ffmpeg.git
avfilter/vf_random: set output frame duration
This commit is contained in:
parent
a749e43c86
commit
7b78684f96
|
@ -37,6 +37,7 @@ typedef struct RandomContext {
|
||||||
int nb_frames_filled;
|
int nb_frames_filled;
|
||||||
AVFrame *frames[MAX_FRAMES];
|
AVFrame *frames[MAX_FRAMES];
|
||||||
int64_t pts[MAX_FRAMES];
|
int64_t pts[MAX_FRAMES];
|
||||||
|
int64_t duration[MAX_FRAMES];
|
||||||
int flush_idx;
|
int flush_idx;
|
||||||
} RandomContext;
|
} RandomContext;
|
||||||
|
|
||||||
|
@ -74,6 +75,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||||
|
|
||||||
if (s->nb_frames_filled < s->nb_frames) {
|
if (s->nb_frames_filled < s->nb_frames) {
|
||||||
s->frames[s->nb_frames_filled] = in;
|
s->frames[s->nb_frames_filled] = in;
|
||||||
|
s->duration[s->nb_frames_filled] = in->duration;
|
||||||
s->pts[s->nb_frames_filled++] = in->pts;
|
s->pts[s->nb_frames_filled++] = in->pts;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -82,9 +84,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||||
|
|
||||||
out = s->frames[idx];
|
out = s->frames[idx];
|
||||||
out->pts = s->pts[0];
|
out->pts = s->pts[0];
|
||||||
|
out->duration = s->duration[0];
|
||||||
memmove(&s->pts[0], &s->pts[1], (s->nb_frames - 1) * sizeof(s->pts[0]));
|
memmove(&s->pts[0], &s->pts[1], (s->nb_frames - 1) * sizeof(s->pts[0]));
|
||||||
|
memmove(&s->duration[0], &s->duration[1], (s->nb_frames - 1) * sizeof(s->duration[0]));
|
||||||
s->frames[idx] = in;
|
s->frames[idx] = in;
|
||||||
s->pts[s->nb_frames - 1] = in->pts;
|
s->pts[s->nb_frames - 1] = in->pts;
|
||||||
|
s->duration[s->nb_frames - 1] = in->duration;
|
||||||
|
|
||||||
return ff_filter_frame(outlink, out);
|
return ff_filter_frame(outlink, out);
|
||||||
}
|
}
|
||||||
|
@ -104,6 +109,7 @@ next:
|
||||||
s->nb_frames--;
|
s->nb_frames--;
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
out->duration = s->duration[s->flush_idx];
|
||||||
out->pts = s->pts[s->flush_idx++];
|
out->pts = s->pts[s->flush_idx++];
|
||||||
ret = ff_filter_frame(outlink, out);
|
ret = ff_filter_frame(outlink, out);
|
||||||
s->frames[s->nb_frames - 1] = NULL;
|
s->frames[s->nb_frames - 1] = NULL;
|
||||||
|
|
Loading…
Reference in New Issue