Debian Codegraph @

test/tools_imageframe.py

raw symbols SCIP
1 import asyncio
2 import logging
3
4 import click
5
6 from haffmpeg.tools import ImageFrame, IMAGE_JPEG
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", required=True, help="Input file for ffmpeg")
14 @click.option("--format_img", "-f", default=IMAGE_JPEG, help="Image output format")
15 @click.option("--output", "-o", required=True, help="Output image file")
16 @click.option("--extra", "-e", help="Extra ffmpeg command line arguments")
17 def cli(ffmpeg, source, format_img, output, extra):
18 """FFMPEG capture frame as image."""
19
20 async def capture_image():
21 stream = ImageFrame(ffmpeg_bin=ffmpeg)
22 return await stream.get_image(
23 input_source=source, output_format=format_img, extra_cmd=extra
24 )
25
26 image = asyncio.run(capture_image())
27
28 if image:
29 with open(output, "wb") as fh_img:
30 fh_img.write(image)
31 else:
32 print("No image returned. Skipping writing output")
33
34
35 if __name__ == "__main__":
36 cli()