This is consistent across filters and also is less typing.
Unified · Split
| @@ -89,48 +89,47 @@ static int query_formats(AVFilterContext *ctx) · 88 unmodified lines | ||
| 89 | 89 | static int config_input(AVFilterLink *inlink) |
| 90 | 90 | { |
| 91 | 91 | AVFilterContext *ctx = inlink->dst; |
| 92 | − BlackDetectContext *blackdetect = ctx->priv; | |
| 92 | + BlackDetectContext *s = ctx->priv; | |
| 93 | 93 | |
| 94 | − blackdetect->black_min_duration = | |
| 95 | − blackdetect->black_min_duration_time / av_q2d(inlink->time_base); | |
| 94 | + s->black_min_duration = s->black_min_duration_time / av_q2d(inlink->time_base); | |
| 96 | 95 | |
| 97 | − blackdetect->pixel_black_th_i = ff_fmt_is_in(inlink->format, yuvj_formats) ? | |
| 96 | + s->pixel_black_th_i = ff_fmt_is_in(inlink->format, yuvj_formats) ? | |
| 98 | 97 | // luminance_minimum_value + pixel_black_th * luminance_range_size |
| 99 | − blackdetect->pixel_black_th * 255 : | |
| 100 | − 16 + blackdetect->pixel_black_th * (235 - 16); | |
| 98 | + s->pixel_black_th * 255 : | |
| 99 | + 16 + s->pixel_black_th * (235 - 16); | |
| 101 | 100 | |
| 102 | − av_log(blackdetect, AV_LOG_VERBOSE, | |
| 101 | + av_log(s, AV_LOG_VERBOSE, | |
| 103 | 102 | "black_min_duration:%s pixel_black_th:%f pixel_black_th_i:%d picture_black_ratio_th:%f\n", |
| 104 | − av_ts2timestr(blackdetect->black_min_duration, &inlink->time_base), | |
| 105 | − blackdetect->pixel_black_th, blackdetect->pixel_black_th_i, | |
| 106 | − blackdetect->picture_black_ratio_th); | |
| 103 | + av_ts2timestr(s->black_min_duration, &inlink->time_base), | |
| 104 | + s->pixel_black_th, s->pixel_black_th_i, | |
| 105 | + s->picture_black_ratio_th); | |
| 107 | 106 | return 0; |
| 108 | 107 | } |
| 109 | 108 | |
| 110 | 109 | static void check_black_end(AVFilterContext *ctx) |
| 111 | 110 | { |
| 112 | − BlackDetectContext *blackdetect = ctx->priv; | |
| 111 | + BlackDetectContext *s = ctx->priv; | |
| 113 | 112 | AVFilterLink *inlink = ctx->inputs[0]; |
| 114 | 113 | |
| 115 | − if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration) { | |
| 116 | − av_log(blackdetect, AV_LOG_INFO, | |
| 114 | + if ((s->black_end - s->black_start) >= s->black_min_duration) { | |
| 115 | + av_log(s, AV_LOG_INFO, | |
| 117 | 116 | "black_start:%s black_end:%s black_duration:%s\n", |
| 118 | − av_ts2timestr(blackdetect->black_start, &inlink->time_base), | |
| 119 | − av_ts2timestr(blackdetect->black_end, &inlink->time_base), | |
| 120 | − av_ts2timestr(blackdetect->black_end - blackdetect->black_start, &inlink->time_base)); | |
| 117 | + av_ts2timestr(s->black_start, &inlink->time_base), | |
| 118 | + av_ts2timestr(s->black_end, &inlink->time_base), | |
| 119 | + av_ts2timestr(s->black_end - s->black_start, &inlink->time_base)); | |
| 121 | 120 | } |
| 122 | 121 | } |
| 123 | 122 | |
| 124 | 123 | static int request_frame(AVFilterLink *outlink) |
| 125 | 124 | { |
| 126 | 125 | AVFilterContext *ctx = outlink->src; |
| 127 | − BlackDetectContext *blackdetect = ctx->priv; | |
| 126 | + BlackDetectContext *s = ctx->priv; | |
| 128 | 127 | AVFilterLink *inlink = ctx->inputs[0]; |
| 129 | 128 | int ret = ff_request_frame(inlink); |
| 130 | 129 | |
| 131 | − if (ret == AVERROR_EOF && blackdetect->black_started) { | |
| 130 | + if (ret == AVERROR_EOF && s->black_started) { | |
| 132 | 131 | // FIXME: black_end should be set to last_picref_pts + last_picref_duration |
| 133 | − blackdetect->black_end = blackdetect->last_picref_pts; | |
| 132 | + s->black_end = s->last_picref_pts; | |
| 134 | 133 | check_black_end(ctx); |
| 135 | 134 | } |
| 136 | 135 | return ret; |
| @@ -139,18 +138,18 @@ static int request_frame(AVFilterLink *outlink) · 2 unmodified lines | ||
| 139 | 138 | static int filter_frame(AVFilterLink *inlink, AVFrame *picref) |
| 140 | 139 | { |
| 141 | 140 | AVFilterContext *ctx = inlink->dst; |
| 142 | − BlackDetectContext *blackdetect = ctx->priv; | |
| 141 | + BlackDetectContext *s = ctx->priv; | |
| 143 | 142 | double picture_black_ratio = 0; |
| 144 | 143 | const uint8_t *p = picref->data[0]; |
| 145 | 144 | int x, i; |
| 146 | 145 | |
| 147 | 146 | for (i = 0; i < inlink->h; i++) { |
| 148 | 147 | for (x = 0; x < inlink->w; x++) |
| 149 | − blackdetect->nb_black_pixels += p[x] <= blackdetect->pixel_black_th_i; | |
| 148 | + s->nb_black_pixels += p[x] <= s->pixel_black_th_i; | |
| 150 | 149 | p += picref->linesize[0]; |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | − picture_black_ratio = (double)blackdetect->nb_black_pixels / (inlink->w * inlink->h); | |
| 152 | + picture_black_ratio = (double)s->nb_black_pixels / (inlink->w * inlink->h); | |
| 154 | 153 | |
| 155 | 154 | av_log(ctx, AV_LOG_DEBUG, |
| 156 | 155 | "frame:%"PRId64" picture_black_ratio:%f pts:%s t:%s type:%c\n", |
| @@ -158,25 +157,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) · 1 unmodified line | ||
| 158 | 157 | av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base), |
| 159 | 158 | av_get_picture_type_char(picref->pict_type)); |
| 160 | 159 | |
| 161 | − if (picture_black_ratio >= blackdetect->picture_black_ratio_th) { | |
| 162 | − if (!blackdetect->black_started) { | |
| 160 | + if (picture_black_ratio >= s->picture_black_ratio_th) { | |
| 161 | + if (!s->black_started) { | |
| 163 | 162 | /* black starts here */ |
| 164 | − blackdetect->black_started = 1; | |
| 165 | − blackdetect->black_start = picref->pts; | |
| 163 | + s->black_started = 1; | |
| 164 | + s->black_start = picref->pts; | |
| 166 | 165 | av_dict_set(&picref->metadata, "lavfi.black_start", |
| 167 | − av_ts2timestr(blackdetect->black_start, &inlink->time_base), 0); | |
| 166 | + av_ts2timestr(s->black_start, &inlink->time_base), 0); | |
| 168 | 167 | } |
| 169 | − } else if (blackdetect->black_started) { | |
| 168 | + } else if (s->black_started) { | |
| 170 | 169 | /* black ends here */ |
| 171 | − blackdetect->black_started = 0; | |
| 172 | − blackdetect->black_end = picref->pts; | |
| 170 | + s->black_started = 0; | |
| 171 | + s->black_end = picref->pts; | |
| 173 | 172 | check_black_end(ctx); |
| 174 | 173 | av_dict_set(&picref->metadata, "lavfi.black_end", |
| 175 | − av_ts2timestr(blackdetect->black_end, &inlink->time_base), 0); | |
| 174 | + av_ts2timestr(s->black_end, &inlink->time_base), 0); | |
| 176 | 175 | } |
| 177 | 176 | |
| 178 | − blackdetect->last_picref_pts = picref->pts; | |
| 179 | − blackdetect->nb_black_pixels = 0; | |
| 177 | + s->last_picref_pts = picref->pts; | |
| 178 | + s->nb_black_pixels = 0; | |
| 180 | 179 | return ff_filter_frame(inlink->dst->outputs[0], picref); |
| 181 | 180 | } |
| 182 | 181 | |