Skip to content

Commit f9ae462

Browse files
committed
docs updated quick start guide
1 parent 6126b53 commit f9ae462

5 files changed

Lines changed: 104 additions & 14 deletions

File tree

.github/workflows/pub_docs.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: Publish Docs
33
on:
44
push:
55
branches: [main] # only if commit message starts with "docs "
6-
workflow_run:
7-
workflows: ["Run Tests"]
8-
branches: [main]
9-
types: [completed]
106
workflow_dispatch:
117

128
jobs:
@@ -15,8 +11,9 @@ jobs:
1511
runs-on: ubuntu-20.04
1612
if: |
1713
${{ github.event_name=='workflow_dispatch'
18-
|| (startsWith(github.ref, 'refs/tags') && github.event.workflow_run.conclusion == 'success' )
19-
|| (github.event_name=='push' && startsWith(github.event.head_commit.message, 'docs '))}}
14+
|| (github.event_name=='push'
15+
&& (startsWith(github.ref, 'refs/tags')
16+
|| startsWith(github.event.head_commit.message, 'docs ')))}}
2017
steps:
2118
- name: Checkout
2219
uses: actions/checkout@master

docsrc/_static/css/custom.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
table.tight-table {
2+
width: 100%;
3+
table-layout: auto;
4+
}
5+
6+
.tight-table td {
7+
white-space: normal !important;
8+
}

docsrc/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@
6161
# Add any paths that contain custom static files (such as style sheets) here,
6262
# relative to this directory. They are copied after the builtin static files,
6363
# so a file named "default.css" will overwrite the builtin "default.css".
64-
html_static_path = []
64+
html_static_path = ["_static"]
6565

6666
# html_sidebars = {
6767
# "**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]
6868
# }
69+
70+
def setup(app):
71+
app.add_css_file('css/custom.css')
72+

docsrc/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Where to start
3030

3131
* :ref:`Quick-start guide <quick>`
3232

33+
* Install via ``pip``:
34+
35+
.. code-block:: bash
36+
37+
pip install ffmpegio
3338
3439
Other resources
3540
---------------

docsrc/quick.rst

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ on the system path. For Windows, it is a bit more complicated.
5252
Alternately, the FFmpeg may be placed elsewhere and use :py:func:`ffmpegio.set_path` to
5353
specify any arbitrary location.
5454

55-
Core offerings
56-
--------------
55+
Features
56+
--------
5757

5858
FFmpeg can read/write virtually any multimedia file out there, and :code:`ffmpegio` uses
5959
the FFmpeg's prowess to perform media I/O (and other) operations in Python. It offers two
@@ -64,12 +64,13 @@ Media Probe
6464
-----------
6565

6666
To process a media file, you first need to know what's in it. Within FFmpeg
67-
ecosystem, this task is handled by `ffprobe<https://ffmpeg.org/ffprobe.html>`__.
68-
:code:`ffmpegio` offers a wrapper module :ref:`ffmpegio:probe<probe>` with 4
67+
ecosystem, this task is handled by `ffprobe <https://ffmpeg.org/ffprobe.html>`__.
68+
:code:`ffmpegio`'s :ref:`ffmpegio:probe<probe>` module wraps ffprobe with 4
6969
basic functions::
7070

7171
>>> import ffmpegio
7272
>>> from pprint import pprint
73+
7374
>>> url = 'mytestvideo.mpg'
7475
>>> format_info = ffmpegio.probe.format_basic(url)
7576
>>> pprint(format_info)
@@ -78,11 +79,13 @@ basic functions::
7879
'format_name': 'mpegts',
7980
'nb_streams': 2,
8081
'start_time': 0.0}
82+
8183
>>> stream_info = ffmpegio.probe.streams_basic(url)
8284
>>> pprint(stream_info)
8385
[{'codec_name': 'mp2', 'codec_type': 'audio', 'index': 0},
8486
{'codec_name': 'h264', 'codec_type': 'video', 'index': 1}]
85-
>>> vst_info =ffmpegio.probe.video_streams_basic(url)
87+
88+
>>> vst_info = ffmpegio.probe.video_streams_basic(url)
8689
>>> pprint.pprint(vst_info)
8790
[{'codec_name': 'h264',
8891
'display_aspect_ratio': Fraction(22, 15),
@@ -94,6 +97,7 @@ basic functions::
9497
'sample_aspect_ratio': Fraction(1, 1),
9598
'start_time': 0.0,
9699
'width': 352}]
100+
97101
>>> ast_info = ffmpegio.probe.audio_streams_basic(url)
98102
>>> pprint.pprint(ast_info)
99103
[{'channel_layout': 'stereo',
@@ -106,8 +110,8 @@ basic functions::
106110
'sample_rate': 44100,
107111
'start_time': 0.0}]
108112

109-
To obtain the complete ffprobe output, use :py:func:`ffmpegio.probe.inquire`. For more information,
110-
see :ref:`probe`.
113+
To obtain the complete ffprobe output, use :py:func:`ffmpegio.probe.full_details`.
114+
For more information on :py:mod:`probe`, see :ref:`probe`.
111115

112116
Block Read/Write
113117
----------------
@@ -183,3 +187,75 @@ write object comes with :code:`write()` method. The reader, in addition, has
183187
:code:`readiter()` generator to iterate as long as there are data to read. For more,
184188
see :py:func:`ffmpegio.open`.
185189

190+
Specify Read Time Range
191+
-----------------------
192+
193+
For both block and stream read operations, you can specify the time range to read
194+
data from. There are four options available:
195+
196+
.. table:: Read Timing Options
197+
:class: tight-table
198+
199+
======== =======================================================================
200+
Name Description
201+
======== =======================================================================
202+
start Start time. Defaults to the beginning of the stream.
203+
end End time. Defaults to the end of the stream.
204+
duration Duration in seconds. Defaults to the duration from :code:`start` to the
205+
end of the input stream.
206+
units Time units. One of ``seconds``, ``frames``, or ``samples``. Defaults
207+
to ``seconds``.
208+
======== =======================================================================
209+
210+
One of :code:`start`, :code:`end`, :code:`duration` or a combination of two of them
211+
defines the read range::
212+
213+
>>>url = "myvideo.mp4"
214+
>>>info = ffmpegio.probe.video_streams_basic(url)[0]
215+
216+
>>>#read only the first 1 seconds
217+
>>>fs, F = ffmpegio.video.read(url, duration=1.0)
218+
219+
>>>#read the last 2.5 seconds
220+
>>>fs, F = ffmpegio.video.read(url, end=info["duration"], duration=2.5)
221+
222+
>>>#read from 1.2 second mark to 2.5 second mark
223+
>>>fs, F = ffmpegio.video.read(url, start=1.2, end=2.5)
224+
225+
.. note::
226+
If all 3 are given, the read functions honor :code:`start` and :code:`duration`
227+
and ignore :code:`end`.
228+
229+
Rather than specifying the times and durations in seconds, :code:`units` option
230+
allows to specify by the frame numbers for video and sample numbers for audio.
231+
For example::
232+
233+
>>>#read 30 frame from the 11th frame (remember Python uses 0-based index)
234+
>>>with ffmpegio.open("myvideo.mp4", start=10, duration=30, units='frames') as f:
235+
>>> frame = f.read()
236+
>>> # do your thing with the frame data
237+
238+
In this example, the video stream of :code:`"myvideo.mp4"` is first probed for its
239+
frame rate, then the :code:`start` and :code:`duration` arguments are converted to
240+
seconds per the discovered frame rate.
241+
242+
Likewise, the timing of the audio input stream can be set with its sample number::
243+
244+
>>>#read first 10000 audio samples
245+
>>>fs, x = ffmpegio.audio.read("myaudio.wav", duration=10000, units='samples')
246+
247+
Now, you may ask about the accuracy of the timing, and this is a very important point
248+
when using FFmpeg in general. FFmpeg is a media playback/recording/transcoding
249+
tool and not a precision data analysis software. As such, it does not and cannot
250+
guarantee the time accuracy. To quote from its documentation,
251+
252+
"Note that in most formats it is not possible to seek exactly, so ffmpeg will
253+
seek to the closest seek point before position. When transcoding and ``-accurate_seek``
254+
is enabled (the default), this extra segment between the seek point and position
255+
will be decoded and discarded."
256+
257+
This being said, video frames are generally seeked correctly with ``-accurate_seek``.
258+
However, the audio stream timing gets a bit dicier due to its frames containing multiple
259+
samples. To overcome this :py:mod:`ffmpegio` always reads the audio stream from the
260+
beginning and truncate unrequested samples. So, it is advised to use the stream read
261+
if multiple audio segments are needed to reduce this necessary overhead.

0 commit comments

Comments
 (0)