The old logic failed to take into account files that ended on ablack region. The new logic matches the vf_blackdetect behavior.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -42,7 +42,6 @@ typedef struct BlackDetectVulkanContext { · 41 unmodified lines | ||
| 42 | 42 | int alpha; |
| 43 | 43 | |
| 44 | 44 | int64_t black_start; |
| 45 | − int64_t black_end; | |
| 46 | 45 | } BlackDetectVulkanContext; |
| 47 | 46 | |
| 48 | 47 | typedef struct BlackDetectPushData { |
| @@ -145,6 +144,7 @@ static av_cold int init_filter(AVFilterContext *ctx) · 96 unmodified lines | ||
| 145 | 144 | |
| 146 | 145 | RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd)); |
| 147 | 146 | |
| 147 | + s->black_start = AV_NOPTS_VALUE; | |
| 148 | 148 | s->initialized = 1; |
| 149 | 149 | |
| 150 | 150 | fail: |
| @@ -156,6 +156,22 @@ fail: · 5 unmodified lines | ||
| 156 | 156 | return err; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | +static void report_black_region(AVFilterContext *ctx, int64_t black_end) | |
| 160 | +{ | |
| 161 | + BlackDetectVulkanContext *s = ctx->priv; | |
| 162 | + const AVFilterLink *inlink = ctx->inputs[0]; | |
| 163 | + if (s->black_start == AV_NOPTS_VALUE) | |
| 164 | + return; | |
| 165 | + | |
| 166 | + if ((black_end - s->black_start) >= s->black_min_duration_time / av_q2d(inlink->time_base)) { | |
| 167 | + av_log(s, AV_LOG_INFO, | |
| 168 | + "black_start:%s black_end:%s black_duration:%s\n", | |
| 169 | + av_ts2timestr(s->black_start, &inlink->time_base), | |
| 170 | + av_ts2timestr(black_end, &inlink->time_base), | |
| 171 | + av_ts2timestr(black_end - s->black_start, &inlink->time_base)); | |
| 172 | + } | |
| 173 | +} | |
| 174 | + | |
| 159 | 175 | static void evaluate(AVFilterLink *link, AVFrame *in, |
| 160 | 176 | const BlackDetectBuf *sum) |
| 161 | 177 | { |
| @@ -183,15 +199,9 @@ static void evaluate(AVFilterLink *link, AVFrame *in, · 21 unmodified lines | ||
| 183 | 199 | av_ts2timestr(in->pts, &in->time_base), 0); |
| 184 | 200 | } |
| 185 | 201 | } else if (s->black_start != AV_NOPTS_VALUE) { |
| 202 | + report_black_region(ctx, in->pts); | |
| 186 | 203 | av_dict_set(&in->metadata, "lavfi.black_end", |
| 187 | 204 | av_ts2timestr(in->pts, &in->time_base), 0); |
| 188 | − if ((in->pts - s->black_start) >= s->black_min_duration_time / av_q2d(in->time_base)) { | |
| 189 | − av_log(s, AV_LOG_INFO, | |
| 190 | − "black_start:%s black_end:%s black_duration:%s\n", | |
| 191 | − av_ts2timestr(s->black_start, &in->time_base), | |
| 192 | − av_ts2timestr(in->pts, &in->time_base), | |
| 193 | − av_ts2timestr(in->pts - s->black_start, &in->time_base)); | |
| 194 | − } | |
| 195 | 205 | s->black_start = AV_NOPTS_VALUE; |
| 196 | 206 | } |
| 197 | 207 | } |
| @@ -349,8 +359,12 @@ fail: · 151 unmodified lines | ||
| 349 | 359 | static void blackdetect_vulkan_uninit(AVFilterContext *avctx) |
| 350 | 360 | { |
| 351 | 361 | BlackDetectVulkanContext *s = avctx->priv; |
| 362 | + AVFilterLink *inlink = avctx->inputs[0]; | |
| 363 | + FilterLink *inl = ff_filter_link(inlink); | |
| 352 | 364 | FFVulkanContext *vkctx = &s->vkctx; |
| 353 | 365 | |
| 366 | + report_black_region(avctx, inl->current_pts); | |
| 367 | + | |
| 354 | 368 | ff_vk_exec_pool_free(vkctx, &s->e); |
| 355 | 369 | ff_vk_shader_free(vkctx, &s->shd); |
| 356 | 370 | |