Debian Codegraph @

test/sensor_noise.py

raw symbols SCIP
1 import asyncio
2 import logging
3
4 import click
5
6 from haffmpeg.sensor import SensorNoise
7
8 logging.basicConfig(level=logging.DEBUG)
9
10
11 @click.command()
12 @click.option("--ffmpeg", "-f", default="ffmpeg", help="FFmpeg binary")
13 @click.option("--source", "-s", help="Input file for ffmpeg")
14 @click.option("--output", "-o", default=None, help="Output ffmpeg target")
15 @click.option(
16 "--duration",
17 "-d",
18 default=1,
19 type=int,
20 help="Time duration to detect as noise (peak filter)",
21 )
22 @click.option(
23 "--reset",
24 "-r",
25 default=2,
26 type=int,
27 help="Time of silent to set the end of detection",
28 )
29 @click.option(
30 "--peak", "-p", default=-30, type=int, help="dB for detect a peak. Default -30"
31 )
32 @click.option("--extra", "-e", help="Extra ffmpeg command line arguments")
33 def cli(ffmpeg, source, output, duration, reset, peak, extra):
34 """FFMPEG noise detection."""
35
36 def callback(state):
37 print("Noise detection is: %s" % str(state))
38
39 async def run():
40
41 sensor = SensorNoise(ffmpeg_bin=ffmpeg, callback=callback)
42 sensor.set_options(time_duration=duration, time_reset=reset, peak=peak)
43 await sensor.open_sensor(
44 input_source=source, output_dest=output, extra_cmd=extra
45 )
46 try:
47 while True:
48 await asyncio.sleep(0.1)
49 finally:
50 await sensor.close()
51
52 asyncio.run(run())
53
54
55 if __name__ == "__main__":
56 cli()