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