Browse code

Add autozoom usage example

Robert Cranston authored on 04/06/2020 17:59:48
Showing 1 changed files
... ...
@@ -81,6 +81,14 @@ A number of hepler functions are also supplied:
81 81
 [`PIL.Image.resize`]: https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize
82 82
 [`cv2.putText`]: https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576
83 83
 
84
+### Examples
85
+
86
+Projects using `pyffstream`:
87
+
88
+-   [`autozoom`][]: Automatically zoom in on video content of interest.
89
+
90
+[`autozoom`]: https://git.rcrnstn.net/rcrnstn/autozoom
91
+
84 92
 ## Installation
85 93
 
86 94
 ### With `pip`
Browse code

Add implementation

Robert Cranston authored on 04/06/2020 17:59:34
Showing 1 changed files
... ...
@@ -2,6 +2,107 @@
2 2
 
3 3
 A Python library to ease processing of video frames.
4 4
 
5
+`pyffstream` is mostly a wrapper around external [FFmpeg][] processes (via
6
+[`ffmpeg-python`][]) intended to be used with [OpenCV][].
7
+
8
+[FFmpeg]: https://ffmpeg.org
9
+[`ffmpeg-python`]: https://github.com/kkroening/ffmpeg-python
10
+[OpenCV]: https://opencv.org
11
+
12
+## Usage
13
+
14
+`pyffstream` provides your application with a command line interface (CLI) and
15
+handles reading and writing video files (with the original audio intact),
16
+filtering the frames through a callback that you define. The API consists
17
+mainly of the single function
18
+
19
+```python
20
+run(description, process, init=None, args_pre=None, args_post=None)
21
+```
22
+
23
+that takes the application description to present in the CLI and some
24
+callbacks, all but one being optional:
25
+
26
+-   `process(args, state, frame, frame_num)`:
27
+
28
+    Takes:
29
+
30
+    -   `args`: [`argparse.Namespace`][] containing parsed command line
31
+        arguments.
32
+    -   `state`: arbitrary object returned by `init` (see below).
33
+    -   `frame`: [`numpy.array`][] with shape
34
+        `(args.working_width, args.working_height, 3)` containing RGB data to
35
+        be processed.
36
+    -   `frame_num`: integer in the range [`args.frame_start`,
37
+        `args.frame_end`) representing the number of the current frame.
38
+
39
+    Returns:
40
+
41
+    -   `output_frame`: [`numpy.array`][] with shape
42
+        `(args.output_width, args.output_height, 3)` containing RGB output.
43
+    -   `debug_frame`: [`numpy.array`][] with shape
44
+        `(args.working_width, args.working_height, 3)` containing RGB debug
45
+        output.
46
+
47
+-   `init(args)`:
48
+
49
+    Takes:
50
+
51
+    -   `args`: [`argparse.Namespace`][] containing parsed command line
52
+        arguments.
53
+
54
+    Returns:
55
+
56
+    -   `state`: arbitrary object passed to `process` (see above).
57
+
58
+-   `args_pre(parser)`, `args_post(parser)`:
59
+
60
+    Takes:
61
+
62
+    -   `args`: [`argparse.ArgumentParser`][] before (for `args_pre`) or after
63
+        (for `args_post`) being filled with `pyffstream` arguments.
64
+
65
+    Returns nothing.
66
+
67
+A number of hepler functions are also supplied:
68
+
69
+-   `resize(image, width, height, resample)`: wrapper around
70
+    [`PIL.Image.resize`][].
71
+-   `text(image, text, x, y, thickness, font=cv2.FONT_HERSHEY_SIMPLEX)`:
72
+    wrapper around [`cv2.putText`][] that automatically adjusts text placement
73
+    and scaling.
74
+-   `fix_rect(args, x, y, w, h)`: forces a rectangle to aspect ratio
75
+    `args.output_aspect` and to be inside `(0, 0, args.working_width,
76
+    args.working_height)`.
77
+
78
+[`argparse.Namespace`]: https://docs.python.org/3/library/argparse.html#argparse.Namespace
79
+[`argparse.ArgumentParser`]: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser
80
+[`numpy.array`]: https://numpy.org/doc/stable/reference/generated/numpy.array.html
81
+[`PIL.Image.resize`]: https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize
82
+[`cv2.putText`]: https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576
83
+
84
+## Installation
85
+
86
+### With `pip`
87
+
88
+```sh
89
+python3 -m pip install git+https://git.rcrnstn.net/rcrnstn/pyffstream
90
+```
91
+
92
+### In `setuptools` `setup.py`
93
+
94
+```python
95
+from setuptools import setup
96
+
97
+setup(
98
+    # ...
99
+    install_requires=[
100
+        'pyffstream @ git+https://git.rcrnstn.net/rcrnstn/pyffstream',
101
+    ],
102
+    # ...
103
+)
104
+```
105
+
5 106
 ## License
6 107
 
7 108
 Licensed under the [ISC license][], see the [`LICENSE`](LICENSE) file.
Browse code

Add license

Robert Cranston authored on 04/06/2020 17:57:55
Showing 1 changed files
... ...
@@ -1,3 +1,9 @@
1 1
 # `pyffstream`
2 2
 
3 3
 A Python library to ease processing of video frames.
4
+
5
+## License
6
+
7
+Licensed under the [ISC license][], see the [`LICENSE`](LICENSE) file.
8
+
9
+[ISC license]: https://en.wikipedia.org/wiki/ISC_license
Browse code

Add readme

Robert Cranston authored on 04/06/2020 17:57:36
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+# `pyffstream`
2
+
3
+A Python library to ease processing of video frames.