-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate max and mean volume sensors
- Loading branch information
1 parent
5431e86
commit 232b5c0
Showing
3 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import asyncio | ||
import logging | ||
|
||
import click | ||
|
||
from haffmpeg.sensor import MeanSensorVolume | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
@click.command() | ||
@click.option("--ffmpeg", "-f", default="ffmpeg", help="FFmpeg binary") | ||
@click.option("--source", "-s", help="Input file for ffmpeg") | ||
@click.option("--output", "-o", default=None, help="Output ffmpeg target") | ||
@click.option( | ||
"--duration", | ||
"-d", | ||
default=1, | ||
type=int, | ||
help="Time duration to detect volume", | ||
) | ||
@click.option("--extra", "-e", help="Extra ffmpeg command line arguments") | ||
def cli(ffmpeg, source, output, duration, extra): | ||
"""FFMPEG mean volume detection.""" | ||
|
||
def callback(state): | ||
print("Mean volume is: %s" % str(state)) | ||
|
||
async def run(): | ||
|
||
sensor = MeanSensorVolume(ffmpeg_bin=ffmpeg, callback=callback) | ||
sensor.set_options(time_duration=duration) | ||
await sensor.open_sensor( | ||
input_source=source, output_dest=output, extra_cmd=extra | ||
) | ||
try: | ||
while True: | ||
await asyncio.sleep(0.1) | ||
finally: | ||
await sensor.close() | ||
|
||
asyncio.run(run()) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |