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

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_blackdetect_vulkan.c+22−8
@@ -42,7 +42,6 @@ typedef struct BlackDetectVulkanContext { · 41 unmodified lines
4242 int alpha;
4343
4444 int64_t black_start;
45− int64_t black_end;
4645 } BlackDetectVulkanContext;
4746
4847 typedef struct BlackDetectPushData {
@@ -145,6 +144,7 @@ static av_cold int init_filter(AVFilterContext *ctx) · 96 unmodified lines
145144
146145 RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));
147146
147+ s->black_start = AV_NOPTS_VALUE;
148148 s->initialized = 1;
149149
150150 fail:
@@ -156,6 +156,22 @@ fail: · 5 unmodified lines
156156 return err;
157157 }
158158
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+
159175 static void evaluate(AVFilterLink *link, AVFrame *in,
160176 const BlackDetectBuf *sum)
161177 {
@@ -183,15 +199,9 @@ static void evaluate(AVFilterLink *link, AVFrame *in, · 21 unmodified lines
183199 av_ts2timestr(in->pts, &in->time_base), 0);
184200 }
185201 } else if (s->black_start != AV_NOPTS_VALUE) {
202+ report_black_region(ctx, in->pts);
186203 av_dict_set(&in->metadata, "lavfi.black_end",
187204 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− }
195205 s->black_start = AV_NOPTS_VALUE;
196206 }
197207 }
@@ -349,8 +359,12 @@ fail: · 151 unmodified lines
349359 static void blackdetect_vulkan_uninit(AVFilterContext *avctx)
350360 {
351361 BlackDetectVulkanContext *s = avctx->priv;
362+ AVFilterLink *inlink = avctx->inputs[0];
363+ FilterLink *inl = ff_filter_link(inlink);
352364 FFVulkanContext *vkctx = &s->vkctx;
353365
366+ report_black_region(avctx, inl->current_pts);
367+
354368 ff_vk_exec_pool_free(vkctx, &s->e);
355369 ff_vk_shader_free(vkctx, &s->shd);
356370

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