@@ -77,20 +77,30 @@ making distribution and installation *much* easier. And probably
77
77
the code itself too. In contrast, [ PyAV] ( https://github.com/mikeboers/PyAV )
78
78
wraps ffmpeg at the C level.
79
79
80
+ Note that because of how ` imageio-ffmpeg ` works, ` read_frames() ` and
81
+ ` write_frames() ` only accept file names, and not file (like) objects.
82
+
80
83
81
84
## API
82
85
83
86
``` py
84
- def read_frames (path , pix_fmt = " rgb24" , bpp = 3 , input_params = None , output_params = None ):
87
+ def read_frames (
88
+ path ,
89
+ pix_fmt = " rgb24" ,
90
+ bpp = None ,
91
+ input_params = None ,
92
+ output_params = None ,
93
+ bits_per_pixel = None ,
94
+ ):
85
95
"""
86
96
Create a generator to iterate over the frames in a video file.
87
97
88
98
It first yields a small metadata dictionary that contains:
89
99
90
- * ffmpeg_version: the ffmpeg version is use (as a string).
91
- * codec: a hint about the codec used to encode the video, e.g. "h264"
92
- * source_size: the width and height of the encoded video frames
93
- * size: the width and height of the frames that will be produced
100
+ * ffmpeg_version: the ffmpeg version in use (as a string).
101
+ * codec: a hint about the codec used to encode the video, e.g. "h264".
102
+ * source_size: the width and height of the encoded video frames.
103
+ * size: the width and height of the frames that will be produced.
94
104
* fps: the frames per second. Can be zero if it could not be detected.
95
105
* duration: duration in seconds. Can be zero if it could not be detected.
96
106
@@ -113,13 +123,16 @@ def read_frames(path, pix_fmt="rgb24", bpp=3, input_params=None, output_params=N
113
123
print(len(frame))
114
124
115
125
Parameters:
116
- path (str): the file to write to .
126
+ path (str): the filename of the file to read from .
117
127
pix_fmt (str): the pixel format of the frames to be read.
118
128
The default is "rgb24" (frames are uint8 RGB images).
119
- bpp (int): The number of bytes per pixel in the output frames.
120
- This depends on the given pix_fmt. Default is 3 (RGB).
121
129
input_params (list): Additional ffmpeg input command line parameters.
122
130
output_params (list): Additional ffmpeg output command line parameters.
131
+ bits_per_pixel (int): The number of bits per pixel in the output frames.
132
+ This depends on the given pix_fmt. Default is 24 (RGB)
133
+ bpp (int): DEPRECATED, USE bits_per_pixel INSTEAD. The number of bytes per pixel in the output frames.
134
+ This depends on the given pix_fmt. Some pixel formats like yuv420p have 12 bits per pixel
135
+ and cannot be set in bytes as integer. For this reason the bpp argument is deprecated.
123
136
"""
124
137
```
125
138
@@ -135,7 +148,7 @@ def write_frames(
135
148
codec = None ,
136
149
macro_block_size = 16 ,
137
150
ffmpeg_log_level = " warning" ,
138
- ffmpeg_timeout = 20. 0 ,
151
+ ffmpeg_timeout = 0 ,
139
152
input_params = None ,
140
153
output_params = None ,
141
154
):
@@ -155,7 +168,7 @@ def write_frames(
155
168
gen.close() # don't forget this
156
169
157
170
Parameters:
158
- path (str): the file to write to.
171
+ path (str): the filename to write to.
159
172
size (tuple): the width and height of the frames.
160
173
pix_fmt_in (str): the pixel format of incoming frames.
161
174
E.g. "gray", "gray8a", "rgb24", or "rgba". Default "rgb24".
@@ -170,8 +183,8 @@ def write_frames(
170
183
to 1 to avoid block alignment, though this is not recommended.
171
184
ffmpeg_log_level (str): The ffmpeg logging level. Default "warning".
172
185
ffmpeg_timeout (float): Timeout in seconds to wait for ffmpeg process
173
- to finish. Value of 0 will wait forever. The time that ffmpeg needs
174
- depends on CPU speed, compression, and frame size. Default 20.0 .
186
+ to finish. Value of 0 will wait forever (default) . The time that
187
+ ffmpeg needs depends on CPU speed, compression, and frame size.
175
188
input_params (list): Additional ffmpeg input command line parameters.
176
189
output_params (list): Additional ffmpeg output command line parameters.
177
190
"""
@@ -192,7 +205,7 @@ def count_frames_and_secs(path):
192
205
``` py
193
206
def get_ffmpeg_exe ():
194
207
"""
195
- Get the ffmpeg executable file. This can be the binary defined by
208
+ Get the ffmpeg executable file. This can be the binary defined by
196
209
the IMAGEIO_FFMPEG_EXE environment variable, the binary distributed
197
210
with imageio-ffmpeg, an ffmpeg binary installed with conda, or the
198
211
system ffmpeg (in that order). A RuntimeError is raised if no valid
0 commit comments