History

avfilter/vf_blackdetect_vulkan: fix black region reporting

The old logic failed to take into account files that ended on ablack region. The new logic matches the vf_blackdetect behavior.

Niklas Haas committed 1 year ago

Commit 6ad95be1 parent 167e3431 file · +22 −8Browse files

Unified · Split

libavfilter/vf_blackdetect_vulkan.c+22−8
@@ -42,7 +42,6 @@ typedef struct BlackDetectVulkanContext { · 41 unmodified lines
42 int alpha;42 int alpha;
43 43
44 int64_t black_start;44 int64_t black_start;
45 int64_t black_end;
46} BlackDetectVulkanContext;45} BlackDetectVulkanContext;
47 46
48typedef struct BlackDetectPushData {47typedef struct BlackDetectPushData {
@@ -145,6 +144,7 @@ static av_cold int init_filter(AVFilterContext *ctx) · 96 unmodified lines
145 144
146 RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));145 RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));
147 146
147 s->black_start = AV_NOPTS_VALUE;
148 s->initialized = 1;148 s->initialized = 1;
149 149
150fail:150fail:
@@ -156,6 +156,22 @@ fail: · 5 unmodified lines
156 return err;156 return err;
157}157}
158 158
159static 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
159static void evaluate(AVFilterLink *link, AVFrame *in,175static void evaluate(AVFilterLink *link, AVFrame *in,
160 const BlackDetectBuf *sum)176 const BlackDetectBuf *sum)
161{177{
@@ -183,15 +199,9 @@ static void evaluate(AVFilterLink *link, AVFrame *in, · 21 unmodified lines
183 av_ts2timestr(in->pts, &in->time_base), 0);199 av_ts2timestr(in->pts, &in->time_base), 0);
184 }200 }
185 } else if (s->black_start != AV_NOPTS_VALUE) {201 } else if (s->black_start != AV_NOPTS_VALUE) {
202 report_black_region(ctx, in->pts);
186 av_dict_set(&in->metadata, "lavfi.black_end",203 av_dict_set(&in->metadata, "lavfi.black_end",
187 av_ts2timestr(in->pts, &in->time_base), 0);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 s->black_start = AV_NOPTS_VALUE;205 s->black_start = AV_NOPTS_VALUE;
196 }206 }
197}207}
@@ -349,8 +359,12 @@ fail: · 151 unmodified lines
349static void blackdetect_vulkan_uninit(AVFilterContext *avctx)359static void blackdetect_vulkan_uninit(AVFilterContext *avctx)
350{360{
351 BlackDetectVulkanContext *s = avctx->priv;361 BlackDetectVulkanContext *s = avctx->priv;
362 AVFilterLink *inlink = avctx->inputs[0];
363 FilterLink *inl = ff_filter_link(inlink);
352 FFVulkanContext *vkctx = &s->vkctx;364 FFVulkanContext *vkctx = &s->vkctx;
353 365
366 report_black_region(avctx, inl->current_pts);
367
354 ff_vk_exec_pool_free(vkctx, &s->e);368 ff_vk_exec_pool_free(vkctx, &s->e);
355 ff_vk_shader_free(vkctx, &s->shd);369 ff_vk_shader_free(vkctx, &s->shd);
356 370

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t