Skip to content

Commit a19f8f0

Browse files
committed
All metadata logger cls to inherit MetadataLogger
1 parent fe8cc30 commit a19f8f0

1 file changed

Lines changed: 11 additions & 87 deletions

File tree

src/ffmpegio/analyze.py

Lines changed: 11 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def run(
305305
return loggers
306306

307307

308-
class ScDet:
308+
class ScDet(MetadataLogger):
309309
media_type = "video" # the stream media type
310310
meta_names = ("scd",) # metadata primary names
311311
filter_name = "scdet"
@@ -317,14 +317,6 @@ def __init__(self, all_scores=False, **options) -> None:
317317
self.options = options
318318
self.data = {}
319319

320-
@property
321-
def filter(self):
322-
return Filter(self.filter_name, **self.options)
323-
324-
@property
325-
def ref_in(self):
326-
return None
327-
328320
def log(self, t, _, key, value):
329321
if key == "mafd": # always the first entry / frame
330322
self.data[t] = {"mafd": float(value)}
@@ -354,7 +346,7 @@ def output(self):
354346
)
355347

356348

357-
class BlackDetect:
349+
class BlackDetect(MetadataLogger):
358350
media_type = "video" # the stream media type
359351
meta_names = ("black_start", "black_end") # metadata primary names
360352
filter_name = "blackdetect"
@@ -364,14 +356,6 @@ def __init__(self, **options):
364356
self.options = options
365357
self.interval = []
366358

367-
@property
368-
def filter(self):
369-
return Filter(self.filter_name, **self.options)
370-
371-
@property
372-
def ref_in(self):
373-
return None
374-
375359
def log(self, t, key, *_):
376360
if key == "black_start":
377361
self.interval.append([t, None])
@@ -385,7 +369,7 @@ def output(self):
385369
return self.Output(self.interval)
386370

387371

388-
class BlackFrame:
372+
class BlackFrame(MetadataLogger):
389373
media_type = "video" # the stream media type
390374
meta_names = ("blackframe",) # metadata primary names
391375
filter_name = "blackframe"
@@ -395,14 +379,6 @@ def __init__(self, **options):
395379
self.options = options
396380
self.frames = []
397381

398-
@property
399-
def filter(self):
400-
return Filter(self.filter_name, **self.options)
401-
402-
@property
403-
def ref_in(self):
404-
return None
405-
406382
def log(self, t, _, key, value):
407383
if key != "pblack":
408384
raise ValueError(f"Unknown blackframe metadata found: {key}")
@@ -413,7 +389,7 @@ def output(self):
413389
return self.Output(*zip(*self.frames))
414390

415391

416-
class FreezeDetect:
392+
class FreezeDetect(MetadataLogger):
417393
media_type = "video" # the stream media type
418394
meta_names = ("freeze",) # metadata primary names
419395
filter_name = "freezedetect"
@@ -423,14 +399,6 @@ def __init__(self, **options):
423399
self.options = options
424400
self.interval = []
425401

426-
@property
427-
def filter(self):
428-
return Filter(self.filter_name, **self.options)
429-
430-
@property
431-
def ref_in(self):
432-
return None
433-
434402
def log(self, t, _, key, __):
435403
if key == "freeze_start":
436404
self.interval.append([t, None])
@@ -445,7 +413,7 @@ def output(self):
445413
return self.Output(self.interval)
446414

447415

448-
class BBox:
416+
class BBox(MetadataLogger):
449417
media_type = "video" # the stream media type
450418
meta_names = ("bbox",) # metadata primary names
451419
filter_name = "bbox"
@@ -457,14 +425,6 @@ def __init__(self, **options):
457425
self.time = []
458426
self.position = []
459427

460-
@property
461-
def filter(self):
462-
return Filter(self.filter_name, **self.options)
463-
464-
@property
465-
def ref_in(self):
466-
return None
467-
468428
def log(self, t, _, key, value):
469429
if key == "x1":
470430
self.time.append(t)
@@ -481,7 +441,7 @@ def output(self):
481441
return self.Output(self.time, self.position)
482442

483443

484-
class BlurDetect:
444+
class BlurDetect(MetadataLogger):
485445
media_type = "video" # the stream media type
486446
meta_names = ("blur",) # metadata primary names
487447
filter_name = "blurdetect"
@@ -491,14 +451,6 @@ def __init__(self, **options):
491451
self.options = options
492452
self.frames = []
493453

494-
@property
495-
def filter(self):
496-
return Filter(self.filter_name, **self.options)
497-
498-
@property
499-
def ref_in(self):
500-
return None
501-
502454
def log(self, t, key, _, value):
503455
if key != "blur":
504456
raise ValueError(f"Unknown blurdetect metadata found: {key}")
@@ -516,7 +468,7 @@ def output(self):
516468
# 'lavfi.entropy.normalized_entropy.normal.U=0.576130\n'
517469
# 'lavfi.entropy.entropy.normal.V=4.532040\n'
518470
# 'lavfi.entropy.normalized_entropy.normal.V=0.566505\n'
519-
class PSNR:
471+
class PSNR(MetadataLogger):
520472
media_type = "video" # the stream media type
521473
meta_names = ("psnr",) # metadata primary names
522474
filter_name = "psnr"
@@ -530,10 +482,6 @@ def __init__(self, ref_stream_spec, **options):
530482
self._first = None
531483
self._ref = ref_stream_spec
532484

533-
@property
534-
def filter(self):
535-
return Filter(self.filter_name, **self.options)
536-
537485
@property
538486
def ref_in(self):
539487
return self._ref
@@ -580,7 +528,7 @@ def output(self):
580528
return Output(self.time, *self.stats.values())
581529

582530

583-
class SilenceDetect:
531+
class SilenceDetect(MetadataLogger):
584532
media_type = "audio" # the stream media type
585533
meta_names = ("silence_start", "silence_end") # metadata primary names
586534
filter_name = "silencedetect"
@@ -591,14 +539,6 @@ def __init__(self, **options):
591539
self.interval = []
592540
self.mono_intervals = {} # mono intervals
593541

594-
@property
595-
def filter(self):
596-
return Filter(self.filter_name, **self.options)
597-
598-
@property
599-
def ref_in(self):
600-
return None
601-
602542
def log(self, t, key, ch, _):
603543

604544
if ch is None:
@@ -628,7 +568,7 @@ def output(self):
628568
return self.Output(self.interval)
629569

630570

631-
class APhaseMeter:
571+
class APhaseMeter(MetadataLogger):
632572
media_type = "audio" # the stream media type
633573
meta_names = ("aphasemeter",) # metadata primary names
634574
filter_name = "aphasemeter"
@@ -647,10 +587,6 @@ def __init__(self, **options):
647587
def filter(self):
648588
return Filter(self.filter_name, **self.options, video=False, phasing=True)
649589

650-
@property
651-
def ref_in(self):
652-
return None
653-
654590
def log(self, t, _, key, val):
655591

656592
if key == "phase":
@@ -673,7 +609,7 @@ def output(self):
673609
return self.Output(self.time, self.value, self.mono, self.out_phase)
674610

675611

676-
class AStats:
612+
class AStats(MetadataLogger):
677613
media_type = "audio" # the stream media type
678614
meta_names = ("astats",) # metadata primary names
679615
filter_name = "astats"
@@ -707,10 +643,6 @@ def __init__(self, **options):
707643
def filter(self):
708644
return Filter(self.filter_name, **self.options, metadata=True)
709645

710-
@property
711-
def ref_in(self):
712-
return None
713-
714646
def log(self, t, _, key, value):
715647

716648
if not self._first:
@@ -752,7 +684,7 @@ def output(self):
752684
)
753685

754686

755-
class ASpectralStats:
687+
class ASpectralStats(MetadataLogger):
756688
media_type = "audio" # the stream media type
757689
meta_names = ("aspectralstats",) # metadata primary names
758690
filter_name = "aspectralstats"
@@ -764,14 +696,6 @@ def __init__(self, **options):
764696
self.stats = {}
765697
self._first = None
766698

767-
@property
768-
def filter(self):
769-
return Filter(self.filter_name, **self.options, metadata=True)
770-
771-
@property
772-
def ref_in(self):
773-
return None
774-
775699
def log(self, t, _, key, value):
776700

777701
m = self.re_key.match(key)

0 commit comments

Comments
 (0)