python-media 0.1.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.
- python_media-0.1.0/LICENSE +21 -0
- python_media-0.1.0/MANIFEST.in +6 -0
- python_media-0.1.0/PKG-INFO +334 -0
- python_media-0.1.0/README.md +309 -0
- python_media-0.1.0/pyproject.toml +28 -0
- python_media-0.1.0/setup.cfg +4 -0
- python_media-0.1.0/setup.py +93 -0
- python_media-0.1.0/src/pymedia/__init__.py +11 -0
- python_media-0.1.0/src/pymedia/_core.py +97 -0
- python_media-0.1.0/src/pymedia/_lib/__init__.py +0 -0
- python_media-0.1.0/src/pymedia/_lib/libpymedia.so +0 -0
- python_media-0.1.0/src/pymedia/_lib/pymedia.c +1203 -0
- python_media-0.1.0/src/pymedia/audio.py +23 -0
- python_media-0.1.0/src/pymedia/frames.py +26 -0
- python_media-0.1.0/src/pymedia/info.py +22 -0
- python_media-0.1.0/src/pymedia/video.py +116 -0
- python_media-0.1.0/src/python_media.egg-info/PKG-INFO +334 -0
- python_media-0.1.0/src/python_media.egg-info/SOURCES.txt +21 -0
- python_media-0.1.0/src/python_media.egg-info/dependency_links.txt +1 -0
- python_media-0.1.0/src/python_media.egg-info/top_level.txt +1 -0
- python_media-0.1.0/tests/conftest.py +26 -0
- python_media-0.1.0/tests/test_audio.py +36 -0
- python_media-0.1.0/tests/test_video.py +90 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pyvideo contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-media
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: In-memory video processing library powered by FFmpeg
|
|
5
|
+
Home-page: https://github.com/moinakmalkhan/pymedia
|
|
6
|
+
Author: moinakmalkhan
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/moinakmalkhan/pymedia
|
|
9
|
+
Project-URL: Repository, https://github.com/moinakmalkhan/pymedia
|
|
10
|
+
Project-URL: Issues, https://github.com/moinakmalkhan/pymedia/issues
|
|
11
|
+
Keywords: video,audio,ffmpeg,extract,convert,compress,gif,media
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: C
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Topic :: Multimedia :: Video :: Conversion
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Conversion
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
|
|
26
|
+
# pymedia
|
|
27
|
+
|
|
28
|
+
In-memory video processing library for Python, powered by FFmpeg. No temporary files, no subprocesses — everything runs in-process via ctypes.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install python-media
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from pymedia import extract_audio, get_video_info, trim_video
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Extract audio** — pull audio from video as mp3, wav, aac, or ogg
|
|
41
|
+
- **Video info** — get duration, resolution, codecs, fps, bitrate, etc.
|
|
42
|
+
- **Convert format** — remux to mp4, mkv, webm, avi, mov (fast, no re-encoding)
|
|
43
|
+
- **Trim video** — cut a time segment
|
|
44
|
+
- **Mute video** — strip all audio tracks
|
|
45
|
+
- **Compress video** — re-encode with H.264 at a target quality (CRF)
|
|
46
|
+
- **Resize video** — change resolution
|
|
47
|
+
- **Extract frame** — grab a single frame as JPEG or PNG
|
|
48
|
+
- **Video to GIF** — convert video (or a segment) to animated GIF
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### Quick install (recommended)
|
|
53
|
+
|
|
54
|
+
The install script auto-detects your OS, installs FFmpeg dev libraries, and installs pymedia — all in one command:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/moinakmalkhan/pymedia.git
|
|
58
|
+
cd pymedia
|
|
59
|
+
./install.sh
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Manual install
|
|
63
|
+
|
|
64
|
+
If you prefer to install step by step, first install the system dependencies for your platform, then install pymedia.
|
|
65
|
+
|
|
66
|
+
#### Step 1: Install system dependencies
|
|
67
|
+
|
|
68
|
+
<details>
|
|
69
|
+
<summary><b>Ubuntu / Debian / Linux Mint / Pop!_OS</b></summary>
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
sudo apt update
|
|
73
|
+
sudo apt install gcc pkg-config \
|
|
74
|
+
libavformat-dev libavcodec-dev libavutil-dev \
|
|
75
|
+
libswresample-dev libswscale-dev
|
|
76
|
+
```
|
|
77
|
+
</details>
|
|
78
|
+
|
|
79
|
+
<details>
|
|
80
|
+
<summary><b>Fedora</b></summary>
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
sudo dnf install gcc pkg-config \
|
|
84
|
+
ffmpeg-free-devel libavcodec-free-devel libavformat-free-devel \
|
|
85
|
+
libavutil-free-devel libswresample-free-devel libswscale-free-devel
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or with RPM Fusion enabled (for full codec support):
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
sudo dnf install gcc pkg-config ffmpeg-devel
|
|
92
|
+
```
|
|
93
|
+
</details>
|
|
94
|
+
|
|
95
|
+
<details>
|
|
96
|
+
<summary><b>CentOS / RHEL / Rocky / AlmaLinux</b></summary>
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
sudo dnf install gcc pkg-config ffmpeg-devel
|
|
100
|
+
```
|
|
101
|
+
</details>
|
|
102
|
+
|
|
103
|
+
<details>
|
|
104
|
+
<summary><b>Arch Linux / Manjaro / EndeavourOS</b></summary>
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
sudo pacman -S gcc pkg-config ffmpeg
|
|
108
|
+
```
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
<details>
|
|
112
|
+
<summary><b>openSUSE</b></summary>
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
sudo zypper install gcc pkg-config ffmpeg-devel
|
|
116
|
+
```
|
|
117
|
+
</details>
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary><b>macOS (Homebrew)</b></summary>
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
brew install gcc pkg-config ffmpeg
|
|
124
|
+
```
|
|
125
|
+
</details>
|
|
126
|
+
|
|
127
|
+
<details>
|
|
128
|
+
<summary><b>Windows (via WSL)</b></summary>
|
|
129
|
+
|
|
130
|
+
pymedia does not support Windows natively. Use [WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install):
|
|
131
|
+
|
|
132
|
+
```powershell
|
|
133
|
+
wsl --install
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Then inside WSL, follow the Ubuntu/Debian instructions above.
|
|
137
|
+
</details>
|
|
138
|
+
|
|
139
|
+
#### Step 2: Install pymedia
|
|
140
|
+
|
|
141
|
+
The C library is compiled automatically during `pip install` — no need to run `make` manually:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
git clone https://github.com/moinakmalkhan/pymedia.git
|
|
145
|
+
cd pymedia
|
|
146
|
+
pip install .
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
For development (editable install):
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
git clone https://github.com/moinakmalkhan/pymedia.git
|
|
153
|
+
cd pymedia
|
|
154
|
+
python3 -m venv .venv
|
|
155
|
+
source .venv/bin/activate
|
|
156
|
+
pip install -e .
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Verify installation
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python -c "from pymedia import get_video_info; print('pymedia installed successfully')"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Usage
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from pymedia import (
|
|
169
|
+
extract_audio, get_video_info, convert_format,
|
|
170
|
+
trim_video, mute_video, compress_video, resize_video,
|
|
171
|
+
extract_frame, video_to_gif,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
with open("video.mp4", "rb") as f:
|
|
175
|
+
data = f.read()
|
|
176
|
+
|
|
177
|
+
# Get video metadata
|
|
178
|
+
info = get_video_info(data)
|
|
179
|
+
print(info["duration"], info["width"], info["height"])
|
|
180
|
+
|
|
181
|
+
# Extract audio as mp3
|
|
182
|
+
mp3 = extract_audio(data, format="mp3")
|
|
183
|
+
|
|
184
|
+
# Convert to webm
|
|
185
|
+
webm = convert_format(data, format="webm")
|
|
186
|
+
|
|
187
|
+
# Trim first 10 seconds
|
|
188
|
+
clip = trim_video(data, start=0, end=10)
|
|
189
|
+
|
|
190
|
+
# Remove audio
|
|
191
|
+
silent = mute_video(data)
|
|
192
|
+
|
|
193
|
+
# Compress (lower CRF = better quality)
|
|
194
|
+
small = compress_video(data, crf=28, preset="fast")
|
|
195
|
+
|
|
196
|
+
# Resize to 720p width
|
|
197
|
+
resized = resize_video(data, width=1280)
|
|
198
|
+
|
|
199
|
+
# Extract a frame at 5 seconds as JPEG
|
|
200
|
+
frame = extract_frame(data, timestamp=5.0, format="jpeg")
|
|
201
|
+
|
|
202
|
+
# Convert to GIF (320px wide, 10fps, first 3 seconds)
|
|
203
|
+
gif = video_to_gif(data, width=320, fps=10, start=0, duration=3)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Supported formats
|
|
207
|
+
|
|
208
|
+
| Function | Formats |
|
|
209
|
+
|---|---|
|
|
210
|
+
| `extract_audio` | mp3, wav, aac, ogg |
|
|
211
|
+
| `convert_format` | mp4, mkv, webm, avi, mov, flv, ts |
|
|
212
|
+
| `extract_frame` | jpeg, png |
|
|
213
|
+
| `compress_video` / `resize_video` | H.264 mp4 output |
|
|
214
|
+
| `video_to_gif` | GIF |
|
|
215
|
+
|
|
216
|
+
## Platform support
|
|
217
|
+
|
|
218
|
+
| Platform | Status |
|
|
219
|
+
|---|---|
|
|
220
|
+
| Linux (x86_64) | Fully supported |
|
|
221
|
+
| Linux (ARM64) | Supported (build from source) |
|
|
222
|
+
| macOS (Homebrew) | Supported (build from source) |
|
|
223
|
+
| Windows (WSL) | Supported via WSL |
|
|
224
|
+
| Windows (native) | Not supported |
|
|
225
|
+
|
|
226
|
+
## Contributing
|
|
227
|
+
|
|
228
|
+
Contributions are welcome! pymedia is open source and we appreciate help from the community.
|
|
229
|
+
|
|
230
|
+
### Setting up the development environment
|
|
231
|
+
|
|
232
|
+
1. **Fork the repo** on GitHub and clone your fork:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
git clone https://github.com/<your-username>/pymedia.git
|
|
236
|
+
cd pymedia
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
2. **Install system dependencies** (see [Installation](#installation) for your platform).
|
|
240
|
+
|
|
241
|
+
3. **Create a virtual environment and install in dev mode:**
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
python3 -m venv .venv
|
|
245
|
+
source .venv/bin/activate
|
|
246
|
+
pip install -e .
|
|
247
|
+
pip install pytest
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
4. **Run the tests to make sure everything works:**
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
pytest tests/ -v
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Making changes
|
|
257
|
+
|
|
258
|
+
1. **Create a branch** for your change:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
git checkout -b my-feature
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
2. **Make your changes.** If you're adding a new feature:
|
|
265
|
+
- Add the C function in `src/pymedia/_lib/pymedia.c`
|
|
266
|
+
- Add ctypes bindings in `src/pymedia/_core.py`
|
|
267
|
+
- Add the Python wrapper in the appropriate module (`audio.py`, `video.py`, `frames.py`, or `info.py`)
|
|
268
|
+
- Export it from `src/pymedia/__init__.py`
|
|
269
|
+
- Add tests in `tests/`
|
|
270
|
+
|
|
271
|
+
3. **Rebuild after any C changes:**
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
pip install -e .
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
4. **Run the tests:**
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
pytest tests/ -v
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
5. **Commit and push:**
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
git add <files>
|
|
287
|
+
git commit -m "Short description of the change"
|
|
288
|
+
git push origin my-feature
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
6. **Open a Pull Request** on GitHub.
|
|
292
|
+
|
|
293
|
+
### Project structure
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
src/pymedia/
|
|
297
|
+
├── __init__.py # Public API exports
|
|
298
|
+
├── _core.py # ctypes bindings (loads libpymedia.so)
|
|
299
|
+
├── audio.py # extract_audio
|
|
300
|
+
├── video.py # convert_format, compress, resize, trim, mute, to_gif
|
|
301
|
+
├── info.py # get_video_info
|
|
302
|
+
├── frames.py # extract_frame
|
|
303
|
+
└── _lib/
|
|
304
|
+
├── pymedia.c # All C code (FFmpeg operations)
|
|
305
|
+
└── libpymedia.so # Built automatically by `pip install` (not committed to git)
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Guidelines
|
|
309
|
+
|
|
310
|
+
- Keep Python wrappers thin — heavy lifting goes in the C code
|
|
311
|
+
- Every new feature needs at least one test
|
|
312
|
+
- Tests must not require external files — generate test data in `tests/conftest.py`
|
|
313
|
+
- Run `pytest tests/ -v` before submitting a PR and make sure all tests pass
|
|
314
|
+
|
|
315
|
+
### Ideas for contributions
|
|
316
|
+
|
|
317
|
+
- Add new video operations (watermark, rotate, change speed, reverse, merge)
|
|
318
|
+
- Improve GIF quality (palette generation)
|
|
319
|
+
- Add Windows native support
|
|
320
|
+
- Migrate deprecated FFmpeg API calls to the new channel layout API
|
|
321
|
+
- Expand CI/CD pipeline (test matrix, pre-built wheels)
|
|
322
|
+
- Improve error messages from the C layer
|
|
323
|
+
|
|
324
|
+
### Reporting bugs
|
|
325
|
+
|
|
326
|
+
Open an issue at https://github.com/moinakmalkhan/pymedia/issues with:
|
|
327
|
+
- What you did
|
|
328
|
+
- What you expected
|
|
329
|
+
- What happened instead
|
|
330
|
+
- Your OS and FFmpeg version (`ffmpeg -version`)
|
|
331
|
+
|
|
332
|
+
## License
|
|
333
|
+
|
|
334
|
+
MIT
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# pymedia
|
|
2
|
+
|
|
3
|
+
In-memory video processing library for Python, powered by FFmpeg. No temporary files, no subprocesses — everything runs in-process via ctypes.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install python-media
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pymedia import extract_audio, get_video_info, trim_video
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Extract audio** — pull audio from video as mp3, wav, aac, or ogg
|
|
16
|
+
- **Video info** — get duration, resolution, codecs, fps, bitrate, etc.
|
|
17
|
+
- **Convert format** — remux to mp4, mkv, webm, avi, mov (fast, no re-encoding)
|
|
18
|
+
- **Trim video** — cut a time segment
|
|
19
|
+
- **Mute video** — strip all audio tracks
|
|
20
|
+
- **Compress video** — re-encode with H.264 at a target quality (CRF)
|
|
21
|
+
- **Resize video** — change resolution
|
|
22
|
+
- **Extract frame** — grab a single frame as JPEG or PNG
|
|
23
|
+
- **Video to GIF** — convert video (or a segment) to animated GIF
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### Quick install (recommended)
|
|
28
|
+
|
|
29
|
+
The install script auto-detects your OS, installs FFmpeg dev libraries, and installs pymedia — all in one command:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/moinakmalkhan/pymedia.git
|
|
33
|
+
cd pymedia
|
|
34
|
+
./install.sh
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Manual install
|
|
38
|
+
|
|
39
|
+
If you prefer to install step by step, first install the system dependencies for your platform, then install pymedia.
|
|
40
|
+
|
|
41
|
+
#### Step 1: Install system dependencies
|
|
42
|
+
|
|
43
|
+
<details>
|
|
44
|
+
<summary><b>Ubuntu / Debian / Linux Mint / Pop!_OS</b></summary>
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
sudo apt update
|
|
48
|
+
sudo apt install gcc pkg-config \
|
|
49
|
+
libavformat-dev libavcodec-dev libavutil-dev \
|
|
50
|
+
libswresample-dev libswscale-dev
|
|
51
|
+
```
|
|
52
|
+
</details>
|
|
53
|
+
|
|
54
|
+
<details>
|
|
55
|
+
<summary><b>Fedora</b></summary>
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
sudo dnf install gcc pkg-config \
|
|
59
|
+
ffmpeg-free-devel libavcodec-free-devel libavformat-free-devel \
|
|
60
|
+
libavutil-free-devel libswresample-free-devel libswscale-free-devel
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or with RPM Fusion enabled (for full codec support):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
sudo dnf install gcc pkg-config ffmpeg-devel
|
|
67
|
+
```
|
|
68
|
+
</details>
|
|
69
|
+
|
|
70
|
+
<details>
|
|
71
|
+
<summary><b>CentOS / RHEL / Rocky / AlmaLinux</b></summary>
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
sudo dnf install gcc pkg-config ffmpeg-devel
|
|
75
|
+
```
|
|
76
|
+
</details>
|
|
77
|
+
|
|
78
|
+
<details>
|
|
79
|
+
<summary><b>Arch Linux / Manjaro / EndeavourOS</b></summary>
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
sudo pacman -S gcc pkg-config ffmpeg
|
|
83
|
+
```
|
|
84
|
+
</details>
|
|
85
|
+
|
|
86
|
+
<details>
|
|
87
|
+
<summary><b>openSUSE</b></summary>
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
sudo zypper install gcc pkg-config ffmpeg-devel
|
|
91
|
+
```
|
|
92
|
+
</details>
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
<summary><b>macOS (Homebrew)</b></summary>
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
brew install gcc pkg-config ffmpeg
|
|
99
|
+
```
|
|
100
|
+
</details>
|
|
101
|
+
|
|
102
|
+
<details>
|
|
103
|
+
<summary><b>Windows (via WSL)</b></summary>
|
|
104
|
+
|
|
105
|
+
pymedia does not support Windows natively. Use [WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install):
|
|
106
|
+
|
|
107
|
+
```powershell
|
|
108
|
+
wsl --install
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Then inside WSL, follow the Ubuntu/Debian instructions above.
|
|
112
|
+
</details>
|
|
113
|
+
|
|
114
|
+
#### Step 2: Install pymedia
|
|
115
|
+
|
|
116
|
+
The C library is compiled automatically during `pip install` — no need to run `make` manually:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
git clone https://github.com/moinakmalkhan/pymedia.git
|
|
120
|
+
cd pymedia
|
|
121
|
+
pip install .
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
For development (editable install):
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
git clone https://github.com/moinakmalkhan/pymedia.git
|
|
128
|
+
cd pymedia
|
|
129
|
+
python3 -m venv .venv
|
|
130
|
+
source .venv/bin/activate
|
|
131
|
+
pip install -e .
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Verify installation
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
python -c "from pymedia import get_video_info; print('pymedia installed successfully')"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Usage
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from pymedia import (
|
|
144
|
+
extract_audio, get_video_info, convert_format,
|
|
145
|
+
trim_video, mute_video, compress_video, resize_video,
|
|
146
|
+
extract_frame, video_to_gif,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
with open("video.mp4", "rb") as f:
|
|
150
|
+
data = f.read()
|
|
151
|
+
|
|
152
|
+
# Get video metadata
|
|
153
|
+
info = get_video_info(data)
|
|
154
|
+
print(info["duration"], info["width"], info["height"])
|
|
155
|
+
|
|
156
|
+
# Extract audio as mp3
|
|
157
|
+
mp3 = extract_audio(data, format="mp3")
|
|
158
|
+
|
|
159
|
+
# Convert to webm
|
|
160
|
+
webm = convert_format(data, format="webm")
|
|
161
|
+
|
|
162
|
+
# Trim first 10 seconds
|
|
163
|
+
clip = trim_video(data, start=0, end=10)
|
|
164
|
+
|
|
165
|
+
# Remove audio
|
|
166
|
+
silent = mute_video(data)
|
|
167
|
+
|
|
168
|
+
# Compress (lower CRF = better quality)
|
|
169
|
+
small = compress_video(data, crf=28, preset="fast")
|
|
170
|
+
|
|
171
|
+
# Resize to 720p width
|
|
172
|
+
resized = resize_video(data, width=1280)
|
|
173
|
+
|
|
174
|
+
# Extract a frame at 5 seconds as JPEG
|
|
175
|
+
frame = extract_frame(data, timestamp=5.0, format="jpeg")
|
|
176
|
+
|
|
177
|
+
# Convert to GIF (320px wide, 10fps, first 3 seconds)
|
|
178
|
+
gif = video_to_gif(data, width=320, fps=10, start=0, duration=3)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Supported formats
|
|
182
|
+
|
|
183
|
+
| Function | Formats |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `extract_audio` | mp3, wav, aac, ogg |
|
|
186
|
+
| `convert_format` | mp4, mkv, webm, avi, mov, flv, ts |
|
|
187
|
+
| `extract_frame` | jpeg, png |
|
|
188
|
+
| `compress_video` / `resize_video` | H.264 mp4 output |
|
|
189
|
+
| `video_to_gif` | GIF |
|
|
190
|
+
|
|
191
|
+
## Platform support
|
|
192
|
+
|
|
193
|
+
| Platform | Status |
|
|
194
|
+
|---|---|
|
|
195
|
+
| Linux (x86_64) | Fully supported |
|
|
196
|
+
| Linux (ARM64) | Supported (build from source) |
|
|
197
|
+
| macOS (Homebrew) | Supported (build from source) |
|
|
198
|
+
| Windows (WSL) | Supported via WSL |
|
|
199
|
+
| Windows (native) | Not supported |
|
|
200
|
+
|
|
201
|
+
## Contributing
|
|
202
|
+
|
|
203
|
+
Contributions are welcome! pymedia is open source and we appreciate help from the community.
|
|
204
|
+
|
|
205
|
+
### Setting up the development environment
|
|
206
|
+
|
|
207
|
+
1. **Fork the repo** on GitHub and clone your fork:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
git clone https://github.com/<your-username>/pymedia.git
|
|
211
|
+
cd pymedia
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
2. **Install system dependencies** (see [Installation](#installation) for your platform).
|
|
215
|
+
|
|
216
|
+
3. **Create a virtual environment and install in dev mode:**
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
python3 -m venv .venv
|
|
220
|
+
source .venv/bin/activate
|
|
221
|
+
pip install -e .
|
|
222
|
+
pip install pytest
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
4. **Run the tests to make sure everything works:**
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
pytest tests/ -v
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Making changes
|
|
232
|
+
|
|
233
|
+
1. **Create a branch** for your change:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
git checkout -b my-feature
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
2. **Make your changes.** If you're adding a new feature:
|
|
240
|
+
- Add the C function in `src/pymedia/_lib/pymedia.c`
|
|
241
|
+
- Add ctypes bindings in `src/pymedia/_core.py`
|
|
242
|
+
- Add the Python wrapper in the appropriate module (`audio.py`, `video.py`, `frames.py`, or `info.py`)
|
|
243
|
+
- Export it from `src/pymedia/__init__.py`
|
|
244
|
+
- Add tests in `tests/`
|
|
245
|
+
|
|
246
|
+
3. **Rebuild after any C changes:**
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
pip install -e .
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
4. **Run the tests:**
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
pytest tests/ -v
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
5. **Commit and push:**
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
git add <files>
|
|
262
|
+
git commit -m "Short description of the change"
|
|
263
|
+
git push origin my-feature
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
6. **Open a Pull Request** on GitHub.
|
|
267
|
+
|
|
268
|
+
### Project structure
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
src/pymedia/
|
|
272
|
+
├── __init__.py # Public API exports
|
|
273
|
+
├── _core.py # ctypes bindings (loads libpymedia.so)
|
|
274
|
+
├── audio.py # extract_audio
|
|
275
|
+
├── video.py # convert_format, compress, resize, trim, mute, to_gif
|
|
276
|
+
├── info.py # get_video_info
|
|
277
|
+
├── frames.py # extract_frame
|
|
278
|
+
└── _lib/
|
|
279
|
+
├── pymedia.c # All C code (FFmpeg operations)
|
|
280
|
+
└── libpymedia.so # Built automatically by `pip install` (not committed to git)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Guidelines
|
|
284
|
+
|
|
285
|
+
- Keep Python wrappers thin — heavy lifting goes in the C code
|
|
286
|
+
- Every new feature needs at least one test
|
|
287
|
+
- Tests must not require external files — generate test data in `tests/conftest.py`
|
|
288
|
+
- Run `pytest tests/ -v` before submitting a PR and make sure all tests pass
|
|
289
|
+
|
|
290
|
+
### Ideas for contributions
|
|
291
|
+
|
|
292
|
+
- Add new video operations (watermark, rotate, change speed, reverse, merge)
|
|
293
|
+
- Improve GIF quality (palette generation)
|
|
294
|
+
- Add Windows native support
|
|
295
|
+
- Migrate deprecated FFmpeg API calls to the new channel layout API
|
|
296
|
+
- Expand CI/CD pipeline (test matrix, pre-built wheels)
|
|
297
|
+
- Improve error messages from the C layer
|
|
298
|
+
|
|
299
|
+
### Reporting bugs
|
|
300
|
+
|
|
301
|
+
Open an issue at https://github.com/moinakmalkhan/pymedia/issues with:
|
|
302
|
+
- What you did
|
|
303
|
+
- What you expected
|
|
304
|
+
- What happened instead
|
|
305
|
+
- Your OS and FFmpeg version (`ffmpeg -version`)
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
MIT
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "python-media"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "In-memory video processing library powered by FFmpeg"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
keywords = ["video", "audio", "ffmpeg", "extract", "convert", "compress", "gif", "media"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: C",
|
|
16
|
+
"Operating System :: POSIX :: Linux",
|
|
17
|
+
"Operating System :: MacOS",
|
|
18
|
+
"Topic :: Multimedia :: Video :: Conversion",
|
|
19
|
+
"Topic :: Multimedia :: Sound/Audio :: Conversion",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/moinakmalkhan/pymedia"
|
|
24
|
+
Repository = "https://github.com/moinakmalkhan/pymedia"
|
|
25
|
+
Issues = "https://github.com/moinakmalkhan/pymedia/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["src"]
|