Fixes timestamp of last output frame.
Unified · Split
| @@ -20,6 +20,7 @@ · 19 unmodified lines | |||
| 20 | 20 | ||
| 21 | #include "libavutil/pixdesc.h" | 21 | #include "libavutil/pixdesc.h" |
| 22 | #include "avfilter.h" | 22 | #include "avfilter.h" |
| 23 | #include "filters.h" | ||
| 23 | #include "internal.h" | 24 | #include "internal.h" |
| 24 | 25 | ||
| 25 | typedef struct SeparateFieldsContext { | 26 | typedef struct SeparateFieldsContext { |
| @@ -101,23 +102,53 @@ clone: · 75 unmodified lines | |||
| 101 | return ff_filter_frame(outlink, inpicref); | 102 | return ff_filter_frame(outlink, inpicref); |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | static int request_frame(AVFilterLink *outlink) | 105 | static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts) |
| 105 | { | 106 | { |
| 106 | AVFilterContext *ctx = outlink->src; | 107 | AVFilterContext *ctx = outlink->src; |
| 107 | SeparateFieldsContext *s = ctx->priv; | 108 | SeparateFieldsContext *s = ctx->priv; |
| 108 | int ret; | 109 | int ret = 0; |
| 109 | 110 | ||
| 110 | ret = ff_request_frame(ctx->inputs[0]); | 111 | if (s->second) { |
| 111 | if (ret == AVERROR_EOF && s->second) { | 112 | *out_pts = s->second->pts += pts; |
| 112 | s->second->pts *= 2; | ||
| 113 | extract_field(s->second, s->nb_planes, s->second->top_field_first); | 113 | extract_field(s->second, s->nb_planes, s->second->top_field_first); |
| 114 | ret = ff_filter_frame(outlink, s->second); | 114 | ret = ff_filter_frame(outlink, s->second); |
| 115 | s->second = 0; | 115 | s->second = NULL; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | return ret; | 118 | return ret; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | static int activate(AVFilterContext *ctx) | ||
| 122 | { | ||
| 123 | AVFilterLink *inlink = ctx->inputs[0]; | ||
| 124 | AVFilterLink *outlink = ctx->outputs[0]; | ||
| 125 | AVFrame *in; | ||
| 126 | int64_t pts; | ||
| 127 | int ret, status; | ||
| 128 | |||
| 129 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); | ||
| 130 | |||
| 131 | ret = ff_inlink_consume_frame(inlink, &in); | ||
| 132 | if (ret < 0) | ||
| 133 | return ret; | ||
| 134 | if (ret > 0) | ||
| 135 | return filter_frame(inlink, in); | ||
| 136 | |||
| 137 | if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { | ||
| 138 | if (status == AVERROR_EOF) { | ||
| 139 | int64_t out_pts = pts; | ||
| 140 | |||
| 141 | ret = flush_frame(outlink, pts, &out_pts); | ||
| 142 | ff_outlink_set_status(outlink, status, out_pts); | ||
| 143 | return ret; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | FF_FILTER_FORWARD_WANTED(outlink, inlink); | ||
| 148 | |||
| 149 | return FFERROR_NOT_READY; | ||
| 150 | } | ||
| 151 | |||
| 121 | static av_cold void uninit(AVFilterContext *ctx) | 152 | static av_cold void uninit(AVFilterContext *ctx) |
| 122 | { | 153 | { |
| 123 | SeparateFieldsContext *s = ctx->priv; | 154 | SeparateFieldsContext *s = ctx->priv; |
| @@ -129,7 +160,6 @@ static const AVFilterPad separatefields_inputs[] = { · 5 unmodified lines | |||
| 129 | { | 160 | { |
| 130 | .name = "default", | 161 | .name = "default", |
| 131 | .type = AVMEDIA_TYPE_VIDEO, | 162 | .type = AVMEDIA_TYPE_VIDEO, |
| 132 | .filter_frame = filter_frame, | ||
| 133 | }, | 163 | }, |
| 134 | { NULL } | 164 | { NULL } |
| 135 | }; | 165 | }; |
| @@ -139,7 +169,6 @@ static const AVFilterPad separatefields_outputs[] = { · 3 unmodified lines | |||
| 139 | .name = "default", | 169 | .name = "default", |
| 140 | .type = AVMEDIA_TYPE_VIDEO, | 170 | .type = AVMEDIA_TYPE_VIDEO, |
| 141 | .config_props = config_props_output, | 171 | .config_props = config_props_output, |
| 142 | .request_frame = request_frame, | ||
| 143 | }, | 172 | }, |
| 144 | { NULL } | 173 | { NULL } |
| 145 | }; | 174 | }; |
| @@ -148,6 +177,7 @@ AVFilter ff_vf_separatefields = { · 2 unmodified lines | |||
| 148 | .name = "separatefields", | 177 | .name = "separatefields", |
| 149 | .description = NULL_IF_CONFIG_SMALL("Split input video frames into fields."), | 178 | .description = NULL_IF_CONFIG_SMALL("Split input video frames into fields."), |
| 150 | .priv_size = sizeof(SeparateFieldsContext), | 179 | .priv_size = sizeof(SeparateFieldsContext), |
| 180 | .activate = activate, | ||
| 151 | .uninit = uninit, | 181 | .uninit = uninit, |
| 152 | .inputs = separatefields_inputs, | 182 | .inputs = separatefields_inputs, |
| 153 | .outputs = separatefields_outputs, | 183 | .outputs = separatefields_outputs, |