@@ -37,6 +37,7 @@ def to_file(
3737 dest : Union [str , Path ],
3838 * ,
3939 pixel_format : Optional [str ] = None ,
40+ crf : Optional [Union [int , float ]] = None ,
4041 ) -> None :
4142 """Encode frames into a file.
4243
@@ -46,27 +47,35 @@ def to_file(
4647 container format.
4748 pixel_format (str, optional): The pixel format for encoding (e.g.,
4849 "yuv420p", "yuv444p"). If not specified, uses codec's default format.
50+ crf (int or float, optional): Constant Rate Factor for encoding quality. Lower values
51+ mean better quality. Valid range depends on the encoder (commonly 0-51).
52+ Defaults to None (which will use encoder's default).
4953 """
5054 _core .encode_video_to_file (
5155 frames = self ._frames ,
5256 frame_rate = self ._frame_rate ,
5357 filename = str (dest ),
5458 pixel_format = pixel_format ,
59+ crf = crf ,
5560 )
5661
5762 def to_tensor (
5863 self ,
5964 format : str ,
6065 * ,
6166 pixel_format : Optional [str ] = None ,
67+ crf : Optional [Union [int , float ]] = None ,
6268 ) -> Tensor :
6369 """Encode frames into raw bytes, as a 1D uint8 Tensor.
6470
6571 Args:
6672 format (str): The container format of the encoded frames, e.g. "mp4", "mov",
67- "mkv", "avi", "webm", "flv", or "gif"
73+ "mkv", "avi", "webm", "flv", etc.
6874 pixel_format (str, optional): The pixel format to encode frames into (e.g.,
6975 "yuv420p", "yuv444p"). If not specified, uses codec's default format.
76+ crf (int or float, optional): Constant Rate Factor for encoding quality. Lower values
77+ mean better quality. Valid range depends on the encoder (commonly 0-51).
78+ Defaults to None (which will use encoder's default).
7079
7180 Returns:
7281 Tensor: The raw encoded bytes as 4D uint8 Tensor.
@@ -76,6 +85,7 @@ def to_tensor(
7685 frame_rate = self ._frame_rate ,
7786 format = format ,
7887 pixel_format = pixel_format ,
88+ crf = crf ,
7989 )
8090
8191 def to_file_like (
@@ -84,6 +94,7 @@ def to_file_like(
8494 format : str ,
8595 * ,
8696 pixel_format : Optional [str ] = None ,
97+ crf : Optional [Union [int , float ]] = None ,
8798 ) -> None :
8899 """Encode frames into a file-like object.
89100
@@ -94,14 +105,18 @@ def to_file_like(
94105 ``write(data: bytes) -> int`` and ``seek(offset: int, whence:
95106 int = 0) -> int``.
96107 format (str): The container format of the encoded frames, e.g. "mp4", "mov",
97- "mkv", "avi", "webm", "flv", or "gif" .
108+ "mkv", "avi", "webm", "flv", etc .
98109 pixel_format (str, optional): The pixel format for encoding (e.g.,
99110 "yuv420p", "yuv444p"). If not specified, uses codec's default format.
111+ crf (int or float, optional): Constant Rate Factor for encoding quality. Lower values
112+ mean better quality. Valid range depends on the encoder (commonly 0-51).
113+ Defaults to None (which will use encoder's default).
100114 """
101115 _core .encode_video_to_file_like (
102116 frames = self ._frames ,
103117 frame_rate = self ._frame_rate ,
104118 format = format ,
105119 file_like = file_like ,
106120 pixel_format = pixel_format ,
121+ crf = crf ,
107122 )
0 commit comments