Spaces:
Sleeping
Sleeping
| import json | |
| import ffmpeg | |
| from transformers import Tool | |
| class VideoFrameSampleTool(Tool): | |
| name = "video_frame_sample_tool" | |
| description = """ | |
| This tool samples an image frame from an input video. | |
| Inputs are input_path, output_path, and frame_number. | |
| Output is the output_path. | |
| """ | |
| inputs = ["text", "text", "text"] | |
| outputs = ["text"] | |
| def __call__(self, input_path: str, output_path: str, frame_number: int): | |
| out, _ = ( | |
| ffmpeg.input(input_path) | |
| .filter("select", "gte(n,{})".format(str(frame_number))) | |
| .output("pipe:", vframes=1, format="image2", vcodec="mjpeg") | |
| .run(capture_stdout=True) | |
| ) | |
| img = Image.open(BytesIO(out)) | |
| img.save(output_path) | |
| return output_path | |