Skip to content

Commit c28ee43

Browse files
committed
docs update
1 parent e4c2b8b commit c28ee43

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

docsrc/quick.rst

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,20 @@ read/write operation. It mimics the familiar Python's file I/O with
178178

179179
.. code-block:: python
180180
181-
>>> with ffmpegio.open('mytestvideo.mp4', 'v') as f: # opens the first video stream
182-
>>> print(f.frame_rate) # frame rate fraction in frames/second
183-
>>> F = f.read() # read the first frame
184-
>>> F = f.read(5) # read the next 5 frames at once
181+
>>> with ffmpegio.open('mytestvideo.mp4', 'v') as f: # opens the first video stream
182+
>>> print(f.frame_rate) # frame rate fraction in frames/second
183+
>>> F = f.read() # read the first frame
184+
>>> F = f.read(5) # read the next 5 frames at once
185185
186186
Another example, which uses read and write streams simultaneously:
187187

188188
.. code-block:: python
189189
190-
>>> with ffmpegio.open('mytestvideo.mp4', 'rv') as f:
191-
>>> with ffmpegio.open('myoutput.avi', 'wv', f.frame_rate) as g:
192-
>>> for frame in f.readiter(): # iterates over all frames, one at a time
193-
>>> output = my_processor(frame) # function to process data
194-
>>> g.write(output) # send the processed frame to 'myoutput.avi'
190+
>>> with ffmpegio.open('mytestvideo.mp4', 'rv') as f:
191+
>>> with ffmpegio.open('myoutput.avi', 'wv', f.frame_rate) as g:
192+
>>> for frame in f.readiter(): # iterates over all frames, one at a time
193+
>>> output = my_processor(frame) # function to process data
194+
>>> g.write(output) # send the processed frame to 'myoutput.avi'
195195
196196
By default, :code:`ffmpegio.open()` opens the first media stream availble to read.
197197
However, the operation mode can be specified via the :code:`mode` second argument.
@@ -245,7 +245,7 @@ defines the read range:
245245

246246
Rather than specifying the times and durations in seconds, :code:`units` option
247247
allows to specify by the frame numbers for video and sample numbers for audio.
248-
For example::
248+
For example:
249249

250250
.. code-block:: python
251251
@@ -258,7 +258,7 @@ In this example, the video stream of :code:`'myvideo.mp4'` is first probed for i
258258
frame rate, then the :code:`start` and :code:`duration` arguments are converted to
259259
seconds per the discovered frame rate.
260260

261-
Likewise, the timing of the audio input stream can be set with its sample number::
261+
Likewise, the timing of the audio input stream can be set with its sample number:
262262

263263
.. code-block:: python
264264
@@ -286,7 +286,8 @@ Specify Data Formats
286286

287287
FFmpeg can convert the formats of video pixels and sound samples on the fly.
288288
This feature is enabled in :py:mod:`ffmpegio` via options :code:`pix_fmt` for
289-
video and :code:`sample_fmt` for audio:
289+
video and :code:`sample_fmt` for audio. Also, the number of audio channels can
290+
be changed with :code:`channels` option.
290291

291292
.. table:: Video :code:`pix_fmt` Option Values
292293
:class: tight-table
@@ -327,13 +328,13 @@ For example,
327328
>>> GRAY.shape
328329
(29, 640, 480, 1)
329330
330-
# auto-convert PNG image to remove transparency with white background
331+
>>> # auto-convert PNG image to remove transparency with white background
331332
>>> RGBA = ffmpegio.image.read('myimage.png') # natively rgba with transparency
332-
>>> RGB = ffmpegio.image.read('myimage.png', pix_fmt='rgb', fill_color='white')
333+
>>> RGB = ffmpegio.image.read('myimage.png', pix_fmt='rgb24', fill_color='white')
333334
>>> RGB.shape
334335
(100, 396, 4)
335-
>>> GRAY.shape
336-
(29, 640, 480, 1)
336+
>>> RGB.shape
337+
(100, 396, 3)
337338
338339
>>> # auto-convert to audio samples to double precision
339340
>>> fs, x = ffmpegio.audio.read('myaudio.wav') # natively s16
@@ -342,8 +343,16 @@ For example,
342343
2324
343344
>>> y.max()
344345
0.0709228515625
345-
346+
347+
>>> # auto-convert to mono
348+
>>> fs, x = ffmpegio.audio.read('myaudio.wav') # natively stereo
349+
>>> _, y = ffmpegio.audio.read('myaudio.wav', channels=1)
350+
>>> x.shape
351+
(44100, 2)
352+
>>> y.shape
353+
(44100, 1)
354+
346355
Note when converting from an image with alpha channel (FFmpeg does not support
347356
alpha channel in video) the background color may be specified with :code:`fill_color`
348357
option (default: ``'white'``). See `the FFmpeg color specification <https://ffmpeg.org/ffmpeg-utils.html#Color>`__
349-
for the list of predefined color names.
358+
for the list of predefined color names.

0 commit comments

Comments
 (0)