1
1
__all__ = ("run" , "quit" , "run_and_record" , )
2
2
3
+ from collections .abc import Iterator
3
4
import pygame
4
5
import asyncpygame as ap
5
6
@@ -45,11 +46,22 @@ def run(main_func, *, fps=30, auto_quit=True):
45
46
main_task .cancel ()
46
47
47
48
48
- def run_and_record (main_func , * , fps = 30 , auto_quit = True , output_file = "./output.mkv" , overwrite = False , codec = 'libx265' ,
49
- quality = 0 ):
49
+ def run_and_record (main_func , * , fps = 30 , auto_quit = True , outfile = "./output.mkv" , overwrite = False ,
50
+ outfile_options : Iterator [ str ] = r"-codec:v libx265 -qscale:v 0" . split () ):
50
51
'''
51
52
Runs the program while recording the screen to a video file using ffmpeg.
52
53
Requires numpy.
54
+
55
+ .. code-block::
56
+
57
+ # H.265/HEVC, maximum quality (default)
58
+ run_and_record(..., outfile_options=r"-codec:v libx265 -qscale:v 0".split())
59
+
60
+ # H.265/HEVC, lossless compression
61
+ run_and_record(..., outfile_options=r"-codec:v libx265 -x265-params lossless=1".split())
62
+
63
+ # WebP, lossless compression, infinite loop
64
+ run_and_record(..., outfile_options=r"-codec:v libwebp -lossless 1 -loop 0".split(), outfile="./output.webp")
53
65
'''
54
66
import subprocess
55
67
from numpy import copyto as numpy_copyto
@@ -75,9 +87,8 @@ def run_and_record(main_func, *, fps=30, auto_quit=True, output_file="./output.m
75
87
'-framerate' , str (fps ),
76
88
'-i' , '-' , # stdin as the input source
77
89
'-an' , # no audio
78
- '-codec:v' , codec ,
79
- '-qscale:v' , str (quality ),
80
- output_file ,
90
+ * outfile_options ,
91
+ outfile ,
81
92
)
82
93
process = subprocess .Popen (ffmpeg_cmd , stdin = subprocess .PIPE , bufsize = 0 )
83
94
output_buffer = _create_output_buffer_for_surface (screen )
0 commit comments