simple-ffmpeg-batch-io 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ [distutils]
2
+ index-servers =
3
+ pypi
4
+ testpypi
5
+
6
+ [testpypi]
7
+ repository = https://test.pypi.org/legacy/
8
+ username = __token__
9
+ password = pypi-AgENdGVzdC5weXBpLm9yZwIkYjA4YWUyZWEtNzg5OS00OTk1LTgzYzItY2YzMTliNWQ3OGRkAAIqWzMsIjc5ZDcwOWMyLWUwZGQtNDI3Yi1hZjg4LTlhNDE1ZDQ1NzkzNSJdAAAGIAZ51pWaodZZSpYFcnl1s9eaIbmr2hirVhwOB9akTEWy
@@ -0,0 +1,24 @@
1
+ # The Docker image that will be used to build your app
2
+ image: python:3.12
3
+ create-pages:
4
+ timeout: 5m
5
+ pages:
6
+ # The folder that contains the files to be exposed at the Page URL
7
+ publish: public
8
+ rules:
9
+ # This ensures that only pushes to the default branch will trigger
10
+ # a pages deploy
11
+ - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
12
+ # Functions that should be executed before the build script is run
13
+ before_script:
14
+ - echo "python version"
15
+ - python --version
16
+ - echo "pip update"
17
+ - pip install -U pip
18
+ - echo "install local module"
19
+ - pip install -e .
20
+ - echo "install pdoc"
21
+ - pip install pdoc
22
+ script:
23
+ - echo "run pdoc"
24
+ - python -m pdoc simple_ffmpeg_batch_io -o public
@@ -0,0 +1,198 @@
1
+ ---
2
+ title: GNU Lesser General Public License v3.0
3
+ spdx-id: LGPL-3.0
4
+ nickname: GNU LGPLv3
5
+ redirect_from: /licenses/lgpl-v3/
6
+
7
+ description: Permissions of this copyleft license are conditioned on making available complete source code of licensed works and modifications under the same license or the GNU GPLv3. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work through interfaces provided by the licensed work may be distributed under different terms and without source code for the larger work.
8
+
9
+ how: This license is an additional set of permissions to the <a href="/licenses/gpl-3.0">GNU GPLv3</a> license. Follow the instructions to apply the GNU GPLv3, in the root of your source code. Then add another file named COPYING.LESSER and copy the text.
10
+
11
+ note: The Free Software Foundation recommends taking the additional step of adding a boilerplate notice to the top of each file. The boilerplate can be found at the end of the <a href="/licenses/gpl-3.0">GNU GPLv3 license</a>. Insert the word “Lesser” before “General” in all three places in the boilerplate notice to make sure that you refer to the GNU LGPLv3 and not the GNU GPLv3.
12
+
13
+ using:
14
+
15
+ permissions:
16
+ - commercial-use
17
+ - modifications
18
+ - distribution
19
+ - patent-use
20
+ - private-use
21
+
22
+ conditions:
23
+ - include-copyright
24
+ - disclose-source
25
+ - document-changes
26
+ - same-license--library
27
+
28
+ limitations:
29
+ - liability
30
+ - warranty
31
+
32
+ ---
33
+
34
+ GNU LESSER GENERAL PUBLIC LICENSE
35
+ Version 3, 29 June 2007
36
+
37
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
38
+ Everyone is permitted to copy and distribute verbatim copies
39
+ of this license document, but changing it is not allowed.
40
+
41
+
42
+ This version of the GNU Lesser General Public License incorporates
43
+ the terms and conditions of version 3 of the GNU General Public
44
+ License, supplemented by the additional permissions listed below.
45
+
46
+ 0. Additional Definitions.
47
+
48
+ As used herein, "this License" refers to version 3 of the GNU Lesser
49
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
50
+ General Public License.
51
+
52
+ "The Library" refers to a covered work governed by this License,
53
+ other than an Application or a Combined Work as defined below.
54
+
55
+ An "Application" is any work that makes use of an interface provided
56
+ by the Library, but which is not otherwise based on the Library.
57
+ Defining a subclass of a class defined by the Library is deemed a mode
58
+ of using an interface provided by the Library.
59
+
60
+ A "Combined Work" is a work produced by combining or linking an
61
+ Application with the Library. The particular version of the Library
62
+ with which the Combined Work was made is also called the "Linked
63
+ Version".
64
+
65
+ The "Minimal Corresponding Source" for a Combined Work means the
66
+ Corresponding Source for the Combined Work, excluding any source code
67
+ for portions of the Combined Work that, considered in isolation, are
68
+ based on the Application, and not on the Linked Version.
69
+
70
+ The "Corresponding Application Code" for a Combined Work means the
71
+ object code and/or source code for the Application, including any data
72
+ and utility programs needed for reproducing the Combined Work from the
73
+ Application, but excluding the System Libraries of the Combined Work.
74
+
75
+ 1. Exception to Section 3 of the GNU GPL.
76
+
77
+ You may convey a covered work under sections 3 and 4 of this License
78
+ without being bound by section 3 of the GNU GPL.
79
+
80
+ 2. Conveying Modified Versions.
81
+
82
+ If you modify a copy of the Library, and, in your modifications, a
83
+ facility refers to a function or data to be supplied by an Application
84
+ that uses the facility (other than as an argument passed when the
85
+ facility is invoked), then you may convey a copy of the modified
86
+ version:
87
+
88
+ a) under this License, provided that you make a good faith effort to
89
+ ensure that, in the event an Application does not supply the
90
+ function or data, the facility still operates, and performs
91
+ whatever part of its purpose remains meaningful, or
92
+
93
+ b) under the GNU GPL, with none of the additional permissions of
94
+ this License applicable to that copy.
95
+
96
+ 3. Object Code Incorporating Material from Library Header Files.
97
+
98
+ The object code form of an Application may incorporate material from
99
+ a header file that is part of the Library. You may convey such object
100
+ code under terms of your choice, provided that, if the incorporated
101
+ material is not limited to numerical parameters, data structure
102
+ layouts and accessors, or small macros, inline functions and templates
103
+ (ten or fewer lines in length), you do both of the following:
104
+
105
+ a) Give prominent notice with each copy of the object code that the
106
+ Library is used in it and that the Library and its use are
107
+ covered by this License.
108
+
109
+ b) Accompany the object code with a copy of the GNU GPL and this license
110
+ document.
111
+
112
+ 4. Combined Works.
113
+
114
+ You may convey a Combined Work under terms of your choice that,
115
+ taken together, effectively do not restrict modification of the
116
+ portions of the Library contained in the Combined Work and reverse
117
+ engineering for debugging such modifications, if you also do each of
118
+ the following:
119
+
120
+ a) Give prominent notice with each copy of the Combined Work that
121
+ the Library is used in it and that the Library and its use are
122
+ covered by this License.
123
+
124
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
125
+ document.
126
+
127
+ c) For a Combined Work that displays copyright notices during
128
+ execution, include the copyright notice for the Library among
129
+ these notices, as well as a reference directing the user to the
130
+ copies of the GNU GPL and this license document.
131
+
132
+ d) Do one of the following:
133
+
134
+ 0) Convey the Minimal Corresponding Source under the terms of this
135
+ License, and the Corresponding Application Code in a form
136
+ suitable for, and under terms that permit, the user to
137
+ recombine or relink the Application with a modified version of
138
+ the Linked Version to produce a modified Combined Work, in the
139
+ manner specified by section 6 of the GNU GPL for conveying
140
+ Corresponding Source.
141
+
142
+ 1) Use a suitable shared library mechanism for linking with the
143
+ Library. A suitable mechanism is one that (a) uses at run time
144
+ a copy of the Library already present on the user's computer
145
+ system, and (b) will operate properly with a modified version
146
+ of the Library that is interface-compatible with the Linked
147
+ Version.
148
+
149
+ e) Provide Installation Information, but only if you would otherwise
150
+ be required to provide such information under section 6 of the
151
+ GNU GPL, and only to the extent that such information is
152
+ necessary to install and execute a modified version of the
153
+ Combined Work produced by recombining or relinking the
154
+ Application with a modified version of the Linked Version. (If
155
+ you use option 4d0, the Installation Information must accompany
156
+ the Minimal Corresponding Source and Corresponding Application
157
+ Code. If you use option 4d1, you must provide the Installation
158
+ Information in the manner specified by section 6 of the GNU GPL
159
+ for conveying Corresponding Source.)
160
+
161
+ 5. Combined Libraries.
162
+
163
+ You may place library facilities that are a work based on the
164
+ Library side by side in a single library together with other library
165
+ facilities that are not Applications and are not covered by this
166
+ License, and convey such a combined library under terms of your
167
+ choice, if you do both of the following:
168
+
169
+ a) Accompany the combined library with a copy of the same work based
170
+ on the Library, uncombined with any other library facilities,
171
+ conveyed under the terms of this License.
172
+
173
+ b) Give prominent notice with the combined library that part of it
174
+ is a work based on the Library, and explaining where to find the
175
+ accompanying uncombined form of the same work.
176
+
177
+ 6. Revised Versions of the GNU Lesser General Public License.
178
+
179
+ The Free Software Foundation may publish revised and/or new versions
180
+ of the GNU Lesser General Public License from time to time. Such new
181
+ versions will be similar in spirit to the present version, but may
182
+ differ in detail to address new problems or concerns.
183
+
184
+ Each version is given a distinguishing version number. If the
185
+ Library as you received it specifies that a certain numbered version
186
+ of the GNU Lesser General Public License "or any later version"
187
+ applies to it, you have the option of following the terms and
188
+ conditions either of that published version or of any later version
189
+ published by the Free Software Foundation. If the Library as you
190
+ received it does not specify a version number of the GNU Lesser
191
+ General Public License, you may choose any version of the GNU Lesser
192
+ General Public License ever published by the Free Software Foundation.
193
+
194
+ If the Library as you received it specifies that a proxy can decide
195
+ whether future versions of the GNU Lesser General Public License shall
196
+ apply, that proxy's public statement of acceptance of any version is
197
+ permanent authorization for you to choose that version for the
198
+ Library.
@@ -0,0 +1,382 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple-ffmpeg-batch-io
3
+ Version: 1.0.0
4
+ Summary: Reading and writing batchs from/to audio and video file using ffmpeg backend
5
+ Project-URL: Homepage, https://gricad-gitlab.univ-grenoble-alpes.fr/m_psi_public_software/simple-ffmpeg-batch-io
6
+ Project-URL: Documentation, https://simple-ffmpeg-batch-io-f159cc.gricad-pages.univ-grenoble-alpes.fr/simple_ffmpeg_batch_io.html
7
+ Project-URL: Source, https://gricad-gitlab.univ-grenoble-alpes.fr/m_psi_public_software/simple-ffmpeg-batch-io
8
+ Project-URL: Issues, https://gricad-gitlab.univ-grenoble-alpes.fr/m_psi_public_software/simple-ffmpeg-batch-io/-/issues
9
+ Author-email: m-psi <pypi@m-psi.fr>
10
+ License: ---
11
+ title: GNU Lesser General Public License v3.0
12
+ spdx-id: LGPL-3.0
13
+ nickname: GNU LGPLv3
14
+ redirect_from: /licenses/lgpl-v3/
15
+
16
+ description: Permissions of this copyleft license are conditioned on making available complete source code of licensed works and modifications under the same license or the GNU GPLv3. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work through interfaces provided by the licensed work may be distributed under different terms and without source code for the larger work.
17
+
18
+ how: This license is an additional set of permissions to the <a href="/licenses/gpl-3.0">GNU GPLv3</a> license. Follow the instructions to apply the GNU GPLv3, in the root of your source code. Then add another file named COPYING.LESSER and copy the text.
19
+
20
+ note: The Free Software Foundation recommends taking the additional step of adding a boilerplate notice to the top of each file. The boilerplate can be found at the end of the <a href="/licenses/gpl-3.0">GNU GPLv3 license</a>. Insert the word “Lesser” before “General” in all three places in the boilerplate notice to make sure that you refer to the GNU LGPLv3 and not the GNU GPLv3.
21
+
22
+ using:
23
+
24
+ permissions:
25
+ - commercial-use
26
+ - modifications
27
+ - distribution
28
+ - patent-use
29
+ - private-use
30
+
31
+ conditions:
32
+ - include-copyright
33
+ - disclose-source
34
+ - document-changes
35
+ - same-license--library
36
+
37
+ limitations:
38
+ - liability
39
+ - warranty
40
+
41
+ ---
42
+
43
+ GNU LESSER GENERAL PUBLIC LICENSE
44
+ Version 3, 29 June 2007
45
+
46
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
47
+ Everyone is permitted to copy and distribute verbatim copies
48
+ of this license document, but changing it is not allowed.
49
+
50
+
51
+ This version of the GNU Lesser General Public License incorporates
52
+ the terms and conditions of version 3 of the GNU General Public
53
+ License, supplemented by the additional permissions listed below.
54
+
55
+ 0. Additional Definitions.
56
+
57
+ As used herein, "this License" refers to version 3 of the GNU Lesser
58
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
59
+ General Public License.
60
+
61
+ "The Library" refers to a covered work governed by this License,
62
+ other than an Application or a Combined Work as defined below.
63
+
64
+ An "Application" is any work that makes use of an interface provided
65
+ by the Library, but which is not otherwise based on the Library.
66
+ Defining a subclass of a class defined by the Library is deemed a mode
67
+ of using an interface provided by the Library.
68
+
69
+ A "Combined Work" is a work produced by combining or linking an
70
+ Application with the Library. The particular version of the Library
71
+ with which the Combined Work was made is also called the "Linked
72
+ Version".
73
+
74
+ The "Minimal Corresponding Source" for a Combined Work means the
75
+ Corresponding Source for the Combined Work, excluding any source code
76
+ for portions of the Combined Work that, considered in isolation, are
77
+ based on the Application, and not on the Linked Version.
78
+
79
+ The "Corresponding Application Code" for a Combined Work means the
80
+ object code and/or source code for the Application, including any data
81
+ and utility programs needed for reproducing the Combined Work from the
82
+ Application, but excluding the System Libraries of the Combined Work.
83
+
84
+ 1. Exception to Section 3 of the GNU GPL.
85
+
86
+ You may convey a covered work under sections 3 and 4 of this License
87
+ without being bound by section 3 of the GNU GPL.
88
+
89
+ 2. Conveying Modified Versions.
90
+
91
+ If you modify a copy of the Library, and, in your modifications, a
92
+ facility refers to a function or data to be supplied by an Application
93
+ that uses the facility (other than as an argument passed when the
94
+ facility is invoked), then you may convey a copy of the modified
95
+ version:
96
+
97
+ a) under this License, provided that you make a good faith effort to
98
+ ensure that, in the event an Application does not supply the
99
+ function or data, the facility still operates, and performs
100
+ whatever part of its purpose remains meaningful, or
101
+
102
+ b) under the GNU GPL, with none of the additional permissions of
103
+ this License applicable to that copy.
104
+
105
+ 3. Object Code Incorporating Material from Library Header Files.
106
+
107
+ The object code form of an Application may incorporate material from
108
+ a header file that is part of the Library. You may convey such object
109
+ code under terms of your choice, provided that, if the incorporated
110
+ material is not limited to numerical parameters, data structure
111
+ layouts and accessors, or small macros, inline functions and templates
112
+ (ten or fewer lines in length), you do both of the following:
113
+
114
+ a) Give prominent notice with each copy of the object code that the
115
+ Library is used in it and that the Library and its use are
116
+ covered by this License.
117
+
118
+ b) Accompany the object code with a copy of the GNU GPL and this license
119
+ document.
120
+
121
+ 4. Combined Works.
122
+
123
+ You may convey a Combined Work under terms of your choice that,
124
+ taken together, effectively do not restrict modification of the
125
+ portions of the Library contained in the Combined Work and reverse
126
+ engineering for debugging such modifications, if you also do each of
127
+ the following:
128
+
129
+ a) Give prominent notice with each copy of the Combined Work that
130
+ the Library is used in it and that the Library and its use are
131
+ covered by this License.
132
+
133
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
134
+ document.
135
+
136
+ c) For a Combined Work that displays copyright notices during
137
+ execution, include the copyright notice for the Library among
138
+ these notices, as well as a reference directing the user to the
139
+ copies of the GNU GPL and this license document.
140
+
141
+ d) Do one of the following:
142
+
143
+ 0) Convey the Minimal Corresponding Source under the terms of this
144
+ License, and the Corresponding Application Code in a form
145
+ suitable for, and under terms that permit, the user to
146
+ recombine or relink the Application with a modified version of
147
+ the Linked Version to produce a modified Combined Work, in the
148
+ manner specified by section 6 of the GNU GPL for conveying
149
+ Corresponding Source.
150
+
151
+ 1) Use a suitable shared library mechanism for linking with the
152
+ Library. A suitable mechanism is one that (a) uses at run time
153
+ a copy of the Library already present on the user's computer
154
+ system, and (b) will operate properly with a modified version
155
+ of the Library that is interface-compatible with the Linked
156
+ Version.
157
+
158
+ e) Provide Installation Information, but only if you would otherwise
159
+ be required to provide such information under section 6 of the
160
+ GNU GPL, and only to the extent that such information is
161
+ necessary to install and execute a modified version of the
162
+ Combined Work produced by recombining or relinking the
163
+ Application with a modified version of the Linked Version. (If
164
+ you use option 4d0, the Installation Information must accompany
165
+ the Minimal Corresponding Source and Corresponding Application
166
+ Code. If you use option 4d1, you must provide the Installation
167
+ Information in the manner specified by section 6 of the GNU GPL
168
+ for conveying Corresponding Source.)
169
+
170
+ 5. Combined Libraries.
171
+
172
+ You may place library facilities that are a work based on the
173
+ Library side by side in a single library together with other library
174
+ facilities that are not Applications and are not covered by this
175
+ License, and convey such a combined library under terms of your
176
+ choice, if you do both of the following:
177
+
178
+ a) Accompany the combined library with a copy of the same work based
179
+ on the Library, uncombined with any other library facilities,
180
+ conveyed under the terms of this License.
181
+
182
+ b) Give prominent notice with the combined library that part of it
183
+ is a work based on the Library, and explaining where to find the
184
+ accompanying uncombined form of the same work.
185
+
186
+ 6. Revised Versions of the GNU Lesser General Public License.
187
+
188
+ The Free Software Foundation may publish revised and/or new versions
189
+ of the GNU Lesser General Public License from time to time. Such new
190
+ versions will be similar in spirit to the present version, but may
191
+ differ in detail to address new problems or concerns.
192
+
193
+ Each version is given a distinguishing version number. If the
194
+ Library as you received it specifies that a certain numbered version
195
+ of the GNU Lesser General Public License "or any later version"
196
+ applies to it, you have the option of following the terms and
197
+ conditions either of that published version or of any later version
198
+ published by the Free Software Foundation. If the Library as you
199
+ received it does not specify a version number of the GNU Lesser
200
+ General Public License, you may choose any version of the GNU Lesser
201
+ General Public License ever published by the Free Software Foundation.
202
+
203
+ If the Library as you received it specifies that a proxy can decide
204
+ whether future versions of the GNU Lesser General Public License shall
205
+ apply, that proxy's public statement of acceptance of any version is
206
+ permanent authorization for you to choose that version for the
207
+ Library.
208
+ License-File: LICENSE
209
+ Keywords: audio/video generation,audio/video reading,batch,ffmpeg,machine learning
210
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
211
+ Classifier: Operating System :: OS Independent
212
+ Classifier: Programming Language :: Python :: 3
213
+ Classifier: Programming Language :: Python :: 3 :: Only
214
+ Requires-Python: >=3.9
215
+ Requires-Dist: numpy>=1.22
216
+ Requires-Dist: static-ffmpeg>=3.0
217
+ Description-Content-Type: text/markdown
218
+
219
+ # simple-ffmpeg-batch-io
220
+
221
+ Reading and writing image and audio batches from/to video and audio files using an FFmpeg backend, with a simple Python API built on top of `numpy`.
222
+
223
+ # Features
224
+
225
+ - Read batches of audio and video frames from video and audio files into `numpy` arrays.
226
+ - Write batches of frames from `numpy` arrays to video or audio files, even compressed
227
+ - Uses `static_ffmpeg` to provide FFmpeg binaries in a portable way. *Simple-ffmpeg-batch-io* provide *ffmpeg* and *ffprobe* as commands within the virtual environment
228
+ - Designed for machine learning and audio/video generation pipelines.
229
+
230
+ # Installation of last version
231
+
232
+ ```bash
233
+ pip install simple-ffmpeg-batch-io
234
+ ```
235
+
236
+ # Documentation
237
+
238
+ Automatically generated [documentation is available online](https://simple-ffmpeg-batch-io-f159cc.gricad-pages.univ-grenoble-alpes.fr/simple_ffmpeg_batch_io.html).
239
+
240
+ # Examples
241
+
242
+ ## Handling video files (i.e. images from video files)
243
+
244
+ ### Read video file at its own frame rate and frame shape
245
+
246
+ ```python
247
+ # Open it with VideoIO old way (C++ style)
248
+ inputVideo = VideoIO()
249
+ inputVideo.open(video_filename) # video file is a str or a path
250
+
251
+ # or open it a more pythonish way
252
+ inputVideo = VideoIO.reader(video_filename) # video file is a str or a path
253
+
254
+ # Here, one can read inputVideo.width, inputVideo.height, inputVideo.fps
255
+ print(inputVideo.width, inputVideo.height, inputVideo.fps)
256
+
257
+ # read one frame
258
+ frame = inputVideo.read_frame() # Here frame is a numpy arrays of shape (Width,height,channels). Channel is 3 as we support only 3 channels for the moment.
259
+
260
+ # Process video frame by frame
261
+ for frame in inputVideo.iter_frames():
262
+ # Process frame. Here frame is a numpy arrays of shape (Width,height,channels). Channel is 3 as we support only 3 channels for the moment.
263
+ process( frame )
264
+
265
+ # or process video using batches
266
+ n = 10
267
+ for batch in inputVideo.iter_batches(n):
268
+ # Process batch. Here batch is a numpy arrays of shape (n,Width,height,channels). Channel is 3 as we support only 3 channels for the moment.
269
+ process( batch )
270
+
271
+ inputVideo.close()
272
+
273
+ # Read video frame by frame with associated timestamps using with context, no need to close after end of context, close is aotomùatically called.
274
+ with VideoIO.reader(video_filename) as inputVideo:
275
+ for frame in inputVideo.iter_frames(with_timestamps = True):
276
+ # Here frame is encapsulated within simple-ffmpeg-batch-io.FrameContainer object
277
+ process( frame.data ) # numpy array of shape (Width,height,channels)
278
+ print( frame.timestamps ) # python list of the timestamp associated to the frame (video here, but same for audio), here only one element as one frame is used
279
+
280
+ # OR
281
+ # Read video batch by batch with associated timestamps using with context, no need to close after end of context, close is aotomùatically called.
282
+ n = 10
283
+ with VideoIO.reader(video_filename) as inputVideo:
284
+ for batch in inputVideo.iter_batches(n, with_timestamps = True):
285
+ # Here batch is encapsulated within simple-ffmpeg-batch-io.FrameContainer object
286
+ process( batch.data ) # numpy array of shape (n,Width,height,channels)
287
+ print( batch.timestamps ) # python list of timestamps associated to each frame (video here, but same for audio), here only one element as one frame is used
288
+
289
+ ```
290
+
291
+ ### Read video file with more parameters
292
+
293
+ ```python
294
+ from simple_ffmpeg_batch_io import VideoIO
295
+
296
+ # Read video changing width, height, and fps
297
+ inputVideo = VideoIO.reader(video_file, width=100, height=100, fps=1.0)
298
+
299
+ # Read modifying only some of them
300
+ inputVideo = VideoIO.reader(video_file, width=100, fps=2.0)
301
+ ```
302
+
303
+ ### Read video and write video file with dedicated ffmpeg parameters
304
+
305
+ ```python
306
+ from simple_ffmpeg_batch_io import VideoIO
307
+
308
+ # open file using filter:
309
+ # resizing to width=320, adapting height to keep aspect ratio while keep height pair (for some codec like H264)
310
+ # pixelising it to 5x5 pixels
311
+ # important note: one must not use decodingParams for scalling. Indeed, VideoIO class use filter to scale video, use width/height parameters
312
+ with VideoIO.reader("camera_4_short.mp4", width=320, height=320, decodingParams="-vf pixelize=w=5:h=5") as inputVideo,
313
+ VideoIO.writer("camera_4_short_pix.avi", width=inputVideo.width, height=inputVideo.height, fps=inputVideo.fps ) as outputVideo: # possible to add encodingParams to add filters, ...
314
+ # iter over batch of 10s and write it to the output file
315
+ batch_size = int( 10*inputVideo.fps )
316
+ for batch in inputVideo.iter_batches(batch_size):
317
+ outputVideo.write_batch(batch)
318
+ ```
319
+
320
+ ## Handling audio from video or audio files
321
+
322
+ ### Read audio from audio file
323
+
324
+ ```python
325
+ from simple_ffmpeg_batch_io import AudioIO
326
+
327
+ # Read audio converting it to one channel, 16000 Hz, frame size of 1s as parameter is a float, start reading file at 2.0s
328
+ # default mode is plannar, i.e. samples are not interleaved, they are separated by channel after reading
329
+ # frame_size for subsequent call to read_frame, iter_frames, read_batch or iter_batches is 1.0s (16000 samples) as the value is a float, thus times in seconds.
330
+ inputAudio = AudioIO.reader(audio_filename, 16000, 1, frame_size = 1.0, start_time = 2.0 )
331
+
332
+ # If the frame_size value is an int, frame_size is considered as a number of samples, for instance to have 0.5 seconds at 16 Khz (8000 samples for each frame)
333
+ with AudioIO.reader(audio_filename, 16000, 1, frame_size = 8000, start_time = 2.0 ) as inputAudio:
334
+ # Read batches of 10 audio frames, each frame has 8000 sanples
335
+ for audio_batch in inputAudio.iter_batches(10, with_timestamps = True):
336
+ .... # audio_batch is encapsulated within a FrameContainer object as with_timestamps = True
337
+
338
+ ```
339
+
340
+ ### Copy audio stream(s) from an audio file or a video file with an audio stream to a wav file
341
+
342
+ ```python
343
+ from simple_ffmpeg_batch_io import AudioIO
344
+
345
+ # Read audio data in interleaved mode (plannard = False) to avoid useless conversion to plannar using default frame_size (1 second). Sample rate remains the same.
346
+ with AudioIO.reader(audio_or_video_filename, plannar = False) as inputAudio:
347
+ # Copy sample_rate and channels to the created file, overwrite existing output filename if any.
348
+ with AudioIO.writer(audio_filename, sample_rate=inputAudio.sample_rate, channels=inputAudio.channels, plannar = False, writeOverExistingFile = True) as outputAudio:
349
+ # Read batches of 10 audio frames (10 seconds as frame_size was by default 1 second when opening video)
350
+ for audio_batch in inputAudio.iter_batches(10):
351
+ outputAudio.write_batch(audio_batch)
352
+
353
+ # no need to close AudioIO objects as 'with' context do it automatically.
354
+
355
+ ```
356
+
357
+ ## Static utility functions
358
+
359
+ ### VideoIO
360
+
361
+ ```python
362
+ from simple_ffmpeg_batch_io import VideoIO
363
+
364
+ # get (width, height, fps) of a video using a static function
365
+ print( VideoIO.get_params(video_filename) )
366
+
367
+ # get length of an audio stream as float (seconds.milliseconds)
368
+ print( VideoIO.get_time_in_sec(video_filename) )
369
+
370
+ ```
371
+
372
+ ### AudioIO
373
+
374
+ ```python
375
+ from simple_ffmpeg_batch_io import AudioIO
376
+
377
+ # get (channels,sample_rate) of a stream using astatic function
378
+ print( AudioIO.get_params(audio_or_video_filename) )
379
+
380
+ # get length of video stream as float (seconds.milliseconds)
381
+ print( AudioIO.get_time_in_sec(audio_or_video_filename) )
382
+ ```