(self,
output_path: str,
resolution: Iterable[int],
fps: float = 30.0,
num_frame: int = 1e9,
disable_log: bool = False)
| 21 | class video_writer: |
| 22 | |
| 23 | def __init__(self, |
| 24 | output_path: str, |
| 25 | resolution: Iterable[int], |
| 26 | fps: float = 30.0, |
| 27 | num_frame: int = 1e9, |
| 28 | disable_log: bool = False) -> None: |
| 29 | prepare_output_path( |
| 30 | output_path, |
| 31 | allowed_suffix=['.mp4'], |
| 32 | tag='output video', |
| 33 | path_type='file', |
| 34 | overwrite=True) |
| 35 | height, width = resolution |
| 36 | width += width % 2 |
| 37 | height += height % 2 |
| 38 | command = [ |
| 39 | 'ffmpeg', |
| 40 | '-y', # (optional) overwrite output file if it exists |
| 41 | '-f', |
| 42 | 'rawvideo', |
| 43 | '-pix_fmt', |
| 44 | 'bgr24', |
| 45 | '-s', |
| 46 | f'{int(width)}x{int(height)}', |
| 47 | '-r', |
| 48 | f'{fps}', # frames per second |
| 49 | '-loglevel', |
| 50 | 'error', |
| 51 | '-threads', |
| 52 | '1', |
| 53 | '-i', |
| 54 | '-', # The input comes from a pipe |
| 55 | '-vcodec', |
| 56 | 'libx264', |
| 57 | '-r', |
| 58 | f'{fps}', # frames per second |
| 59 | '-an', # Tells FFMPEG not to expect any audio |
| 60 | output_path, |
| 61 | ] |
| 62 | if not disable_log: |
| 63 | print(f'Running \"{" ".join(command)}\"') |
| 64 | process = subprocess.Popen( |
| 65 | command, |
| 66 | stdin=subprocess.PIPE, |
| 67 | stderr=subprocess.PIPE, |
| 68 | ) |
| 69 | if process.stdin is None or process.stderr is None: |
| 70 | raise BrokenPipeError('No buffer received.') |
| 71 | self.process = process |
| 72 | self.num_frame = num_frame |
| 73 | self.len = 0 |
| 74 | |
| 75 | def write(self, image_array: np.ndarray): |
| 76 | if self.len <= self.num_frame: |
nothing calls this directly
no test coverage detected