media-toolkit 0.0.8__tar.gz → 0.1.1.dev1__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.
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/PKG-INFO +9 -7
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/README.md +8 -6
- media_toolkit-0.1.1.dev1/media_toolkit/__init__.py +2 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/image_file.py +1 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/media_file.py +85 -11
- media_toolkit-0.1.1.dev1/media_toolkit/utils/__init__.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/utils/file_conversion.py +5 -5
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit.egg-info/PKG-INFO +9 -7
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit.egg-info/SOURCES.txt +1 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/pyproject.toml +1 -1
- media_toolkit-0.1.1.dev1/test/test_image_file.py +11 -0
- media_toolkit-0.1.1.dev1/test/test_video_file.py +39 -0
- media_toolkit-0.0.8/media_toolkit/__init__.py +0 -2
- media_toolkit-0.0.8/media_toolkit/utils/__init__.py +0 -1
- media_toolkit-0.0.8/test/test_video_file.py +0 -39
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/LICENSE +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/__init__.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/audio_file.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/video/__init__.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/video/video_file.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/core/video/video_utils.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/utils/dependency_requirements.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/utils/generator_wrapper.py +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit.egg-info/dependency_links.txt +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit.egg-info/requires.txt +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit.egg-info/top_level.txt +0 -0
- {media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: media-toolkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.1.dev1
|
|
4
4
|
Summary: Web-ready standardized file processing and serialization. Read, load and convert to standard file types with a common interface.
|
|
5
5
|
Author: SocAIty
|
|
6
6
|
License: GPLv3
|
|
@@ -46,10 +46,11 @@ Load and convert from and to common data types:
|
|
|
46
46
|
- bytes,
|
|
47
47
|
- base64
|
|
48
48
|
- json
|
|
49
|
+
- urls
|
|
49
50
|
- etc.
|
|
50
51
|
|
|
51
52
|
Transmit files between services with a common interface
|
|
52
|
-
- Native FastSDK and FastTaskAPI integration
|
|
53
|
+
- Native [FastSDK](https://github.com/SocAIty/fastSDK) and [FastTaskAPI](https://github.com/SocAIty/FastTaskAPI) integration
|
|
53
54
|
- Supports httpx, requests
|
|
54
55
|
|
|
55
56
|
Work with native python libs like BytesIO.
|
|
@@ -63,9 +64,9 @@ You can install the package with PIP, or clone the repository.
|
|
|
63
64
|
```bash
|
|
64
65
|
# install from pypi
|
|
65
66
|
pip install media-toolkit
|
|
66
|
-
# install without dependencies: this is useful if you only need the basic functionality
|
|
67
|
+
# install without dependencies: this is useful if you only need the basic functionality (working with files)
|
|
67
68
|
pip install media-toolkit --no-deps
|
|
68
|
-
# if you
|
|
69
|
+
# if you want to use certain file types, and convenience functions
|
|
69
70
|
pip install media-toolkit[VideoFile] # or [AudioFile, VideoFile, ...]
|
|
70
71
|
# install from github for newest release
|
|
71
72
|
pip install git+git://github.com/SocAIty/media-toolkit
|
|
@@ -84,7 +85,7 @@ The library automatically detects the data type and loads it correctly.
|
|
|
84
85
|
```python
|
|
85
86
|
from media_toolkit import MediaFile, ImageFile, AudioFile, VideoFile
|
|
86
87
|
|
|
87
|
-
# could be a path, base64, bytesio, file_handle, numpy array ...
|
|
88
|
+
# could be a path, url, base64, bytesio, file_handle, numpy array ...
|
|
88
89
|
arbitrary_data = "...."
|
|
89
90
|
# Instantiate an image file
|
|
90
91
|
new_file = ImageFile().from_any(arbitrary_data)
|
|
@@ -189,6 +190,7 @@ my_files = {
|
|
|
189
190
|
response = httpx.Client().post(url, files=my_files)
|
|
190
191
|
```
|
|
191
192
|
|
|
193
|
+
|
|
192
194
|
# How it works
|
|
193
195
|
|
|
194
196
|
If media-file is instantiated with ```from_*``` it converts it to an intermediate representation.
|
|
@@ -199,5 +201,5 @@ Currently the intermediate representation is supported in memory with (BytesIO).
|
|
|
199
201
|
|
|
200
202
|
# ToDo:
|
|
201
203
|
|
|
202
|
-
[x] additionally support tempfile backend instead of working bytesio memory mode only.
|
|
203
|
-
[x] decreasing redundancies for _file_info() method
|
|
204
|
+
- [x] additionally support tempfile backend instead of working bytesio memory mode only.
|
|
205
|
+
- [x] decreasing redundancies for _file_info() method
|
|
@@ -17,10 +17,11 @@ Load and convert from and to common data types:
|
|
|
17
17
|
- bytes,
|
|
18
18
|
- base64
|
|
19
19
|
- json
|
|
20
|
+
- urls
|
|
20
21
|
- etc.
|
|
21
22
|
|
|
22
23
|
Transmit files between services with a common interface
|
|
23
|
-
- Native FastSDK and FastTaskAPI integration
|
|
24
|
+
- Native [FastSDK](https://github.com/SocAIty/fastSDK) and [FastTaskAPI](https://github.com/SocAIty/FastTaskAPI) integration
|
|
24
25
|
- Supports httpx, requests
|
|
25
26
|
|
|
26
27
|
Work with native python libs like BytesIO.
|
|
@@ -34,9 +35,9 @@ You can install the package with PIP, or clone the repository.
|
|
|
34
35
|
```bash
|
|
35
36
|
# install from pypi
|
|
36
37
|
pip install media-toolkit
|
|
37
|
-
# install without dependencies: this is useful if you only need the basic functionality
|
|
38
|
+
# install without dependencies: this is useful if you only need the basic functionality (working with files)
|
|
38
39
|
pip install media-toolkit --no-deps
|
|
39
|
-
# if you
|
|
40
|
+
# if you want to use certain file types, and convenience functions
|
|
40
41
|
pip install media-toolkit[VideoFile] # or [AudioFile, VideoFile, ...]
|
|
41
42
|
# install from github for newest release
|
|
42
43
|
pip install git+git://github.com/SocAIty/media-toolkit
|
|
@@ -55,7 +56,7 @@ The library automatically detects the data type and loads it correctly.
|
|
|
55
56
|
```python
|
|
56
57
|
from media_toolkit import MediaFile, ImageFile, AudioFile, VideoFile
|
|
57
58
|
|
|
58
|
-
# could be a path, base64, bytesio, file_handle, numpy array ...
|
|
59
|
+
# could be a path, url, base64, bytesio, file_handle, numpy array ...
|
|
59
60
|
arbitrary_data = "...."
|
|
60
61
|
# Instantiate an image file
|
|
61
62
|
new_file = ImageFile().from_any(arbitrary_data)
|
|
@@ -160,6 +161,7 @@ my_files = {
|
|
|
160
161
|
response = httpx.Client().post(url, files=my_files)
|
|
161
162
|
```
|
|
162
163
|
|
|
164
|
+
|
|
163
165
|
# How it works
|
|
164
166
|
|
|
165
167
|
If media-file is instantiated with ```from_*``` it converts it to an intermediate representation.
|
|
@@ -170,5 +172,5 @@ Currently the intermediate representation is supported in memory with (BytesIO).
|
|
|
170
172
|
|
|
171
173
|
# ToDo:
|
|
172
174
|
|
|
173
|
-
[x] additionally support tempfile backend instead of working bytesio memory mode only.
|
|
174
|
-
[x] decreasing redundancies for _file_info() method
|
|
175
|
+
- [x] additionally support tempfile backend instead of working bytesio memory mode only.
|
|
176
|
+
- [x] decreasing redundancies for _file_info() method
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
import io
|
|
3
3
|
import mimetypes
|
|
4
|
+
|
|
4
5
|
from typing import Union, BinaryIO
|
|
5
6
|
import os
|
|
7
|
+
from urllib.parse import urlparse
|
|
8
|
+
|
|
6
9
|
from media_toolkit.utils.dependency_requirements import requires_numpy
|
|
7
10
|
|
|
11
|
+
import re
|
|
8
12
|
|
|
9
13
|
try:
|
|
10
14
|
import numpy as np
|
|
@@ -17,6 +21,7 @@ class MediaFile:
|
|
|
17
21
|
Has file conversions that make it easy to work standardized with files across the web and in the sdk.
|
|
18
22
|
Works natively with bytesio, base64 and binary data.
|
|
19
23
|
"""
|
|
24
|
+
|
|
20
25
|
def __init__(self, file_name: str = "file", content_type: str = "application/octet-stream"):
|
|
21
26
|
"""
|
|
22
27
|
:param file_name: The name of the file. Note it is overwritten if you use from_file/from_starlette.
|
|
@@ -24,7 +29,7 @@ class MediaFile:
|
|
|
24
29
|
"""
|
|
25
30
|
self.content_type = content_type
|
|
26
31
|
self.file_name = file_name # the name of the file also when specified in bytesio
|
|
27
|
-
self.path = None
|
|
32
|
+
self.path = None # the path of the file if it was provided. Is also indicator if file was loaded from file.
|
|
28
33
|
self._content_buffer = io.BytesIO()
|
|
29
34
|
|
|
30
35
|
def from_any(self, data):
|
|
@@ -41,8 +46,13 @@ class MediaFile:
|
|
|
41
46
|
elif isinstance(data, str):
|
|
42
47
|
if self._is_valid_file_path(data):
|
|
43
48
|
self.from_file(data)
|
|
49
|
+
elif self._is_url(data):
|
|
50
|
+
self.from_url(data)
|
|
44
51
|
else:
|
|
45
|
-
|
|
52
|
+
try:
|
|
53
|
+
self.from_base64(data)
|
|
54
|
+
except Exception as e:
|
|
55
|
+
print(f"Either wrong file path or not base64. Check your inputs: {data}. Error: {e}")
|
|
46
56
|
elif isinstance(data, bytes):
|
|
47
57
|
self.from_bytes(data)
|
|
48
58
|
elif type(data).__name__ == 'ndarray':
|
|
@@ -53,9 +63,9 @@ class MediaFile:
|
|
|
53
63
|
return self
|
|
54
64
|
|
|
55
65
|
def from_bytesio_or_handle(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
self,
|
|
67
|
+
buffer: Union[io.BytesIO, BinaryIO, io.BufferedReader],
|
|
68
|
+
copy: bool = True
|
|
59
69
|
):
|
|
60
70
|
"""
|
|
61
71
|
Set the content of the file from a BytesIO or a file handle.
|
|
@@ -85,11 +95,10 @@ class MediaFile:
|
|
|
85
95
|
def from_bytesio(self, buffer: Union[io.BytesIO, BinaryIO], copy: bool = True):
|
|
86
96
|
return self.from_bytesio_or_handle(buffer=buffer, copy=copy)
|
|
87
97
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
#def from_file(path_or_handle: Union[str, io.BytesIO, io.BufferedReader]):
|
|
98
|
+
# @staticmethod
|
|
99
|
+
# @overload
|
|
100
|
+
# def from_file(path_or_handle: Union[str, io.BytesIO, io.BufferedReader]):
|
|
91
101
|
# return MediaFile().from_file(path_or_handle)
|
|
92
|
-
|
|
93
102
|
def from_file(self, path_or_handle: Union[str, io.BytesIO, io.BufferedReader]):
|
|
94
103
|
"""
|
|
95
104
|
Load a file from a file path, file handle or base64 and convert it to BytesIO.
|
|
@@ -160,6 +169,52 @@ class MediaFile:
|
|
|
160
169
|
self.from_base64(file_result_json["content"])
|
|
161
170
|
return self
|
|
162
171
|
|
|
172
|
+
def from_url(self, url: str):
|
|
173
|
+
"""
|
|
174
|
+
Download a file from an url.
|
|
175
|
+
"""
|
|
176
|
+
# code inspired by: https://github.com/runpod/runpod-python/blob/main/runpod/serverless/utils/rp_download.py
|
|
177
|
+
import requests
|
|
178
|
+
HEADERS = {"User-Agent": "runpod-python/0.0.0 (https://runpod.io; support@runpod.io)"}
|
|
179
|
+
with requests.get(url, headers=HEADERS, stream=True, timeout=5) as response:
|
|
180
|
+
response.raise_for_status()
|
|
181
|
+
|
|
182
|
+
# get orig file name or create new
|
|
183
|
+
original_file_name = []
|
|
184
|
+
if "Content-Disposition" in response.headers.keys():
|
|
185
|
+
original_file_name = re.findall(
|
|
186
|
+
"filename=(.+)",
|
|
187
|
+
response.headers["Content-Disposition"]
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
if len(original_file_name) > 0:
|
|
191
|
+
original_file_name = original_file_name[0]
|
|
192
|
+
else:
|
|
193
|
+
download_path = urlparse(url).path
|
|
194
|
+
original_file_name = os.path.basename(download_path)
|
|
195
|
+
|
|
196
|
+
# DOWNLOAD FILE IN Chunks
|
|
197
|
+
file_size = int(response.headers.get('Content-Length', 0))
|
|
198
|
+
# calculate chunk_size
|
|
199
|
+
if file_size <= 1024 * 1024: # 1 MB
|
|
200
|
+
chunk_size = 1024 # 1 KB
|
|
201
|
+
elif file_size <= 1024 * 1024 * 1024: # 1 GB
|
|
202
|
+
chunk_size = 1024 * 1024 # 1 MB
|
|
203
|
+
else:
|
|
204
|
+
chunk_size = 1024 * 1024 * 10 # 10 MB
|
|
205
|
+
|
|
206
|
+
# write the content in chunks to the file
|
|
207
|
+
file = io.BytesIO()
|
|
208
|
+
for chunk in response.iter_content(chunk_size=chunk_size):
|
|
209
|
+
if chunk: # filter out keep-alive chunks
|
|
210
|
+
file.write(chunk)
|
|
211
|
+
file.name = original_file_name
|
|
212
|
+
self.file_name = original_file_name
|
|
213
|
+
|
|
214
|
+
# self.url = url
|
|
215
|
+
|
|
216
|
+
return self.from_bytesio_or_handle(file, copy=False)
|
|
217
|
+
|
|
163
218
|
@requires_numpy()
|
|
164
219
|
def to_np_array(self, shape=None, dtype=np.uint8):
|
|
165
220
|
"""
|
|
@@ -194,7 +249,7 @@ class MediaFile:
|
|
|
194
249
|
return self._content_buffer
|
|
195
250
|
|
|
196
251
|
def to_base64(self):
|
|
197
|
-
return base64.b64encode(self.to_bytes()).decode()
|
|
252
|
+
return base64.b64encode(self.to_bytes()).decode('ascii')
|
|
198
253
|
|
|
199
254
|
def to_httpx_send_able_tuple(self):
|
|
200
255
|
return self.file_name, self.read(), self.content_type
|
|
@@ -226,7 +281,7 @@ class MediaFile:
|
|
|
226
281
|
path = os.path.join(path, self.file_name)
|
|
227
282
|
|
|
228
283
|
# check if has extension
|
|
229
|
-
#if os.path.splitext(path)[1] == "":
|
|
284
|
+
# if os.path.splitext(path)[1] == "":
|
|
230
285
|
# path += ".mp4"
|
|
231
286
|
|
|
232
287
|
with open(path, 'wb') as file:
|
|
@@ -246,6 +301,7 @@ class MediaFile:
|
|
|
246
301
|
# from np_array -> tempfile
|
|
247
302
|
# from starlette_upload_file -> from_buffered_reader(spooled_temporary) -> info from the spooled_temporary
|
|
248
303
|
# from base64 -> from-bytes -> tempfile
|
|
304
|
+
# from url -> from bytesio
|
|
249
305
|
if self.path is not None:
|
|
250
306
|
self.file_name = os.path.basename(self.path)
|
|
251
307
|
self.content_type = mimetypes.guess_type(self.file_name)[0] or "application/octet-stream"
|
|
@@ -255,6 +311,21 @@ class MediaFile:
|
|
|
255
311
|
if self.content_type is None:
|
|
256
312
|
self.content_type = "application/octet-stream"
|
|
257
313
|
|
|
314
|
+
def file_size(self, unit="bytes") -> int:
|
|
315
|
+
"""
|
|
316
|
+
:param unit:
|
|
317
|
+
"""
|
|
318
|
+
size_in_ = self._content_buffer.getbuffer().nbytes
|
|
319
|
+
if unit == "bytes":
|
|
320
|
+
return size_in_
|
|
321
|
+
elif unit == "kb":
|
|
322
|
+
size_in_ = size_in_ / 1000
|
|
323
|
+
elif unit == "mb":
|
|
324
|
+
size_in_ = size_in_ / 1000000
|
|
325
|
+
elif unit == "gb":
|
|
326
|
+
size_in_ = size_in_ / 1000000000
|
|
327
|
+
return size_in_
|
|
328
|
+
|
|
258
329
|
def __bytes__(self):
|
|
259
330
|
return self.to_bytes()
|
|
260
331
|
|
|
@@ -301,3 +372,6 @@ class MediaFile:
|
|
|
301
372
|
except:
|
|
302
373
|
return False
|
|
303
374
|
|
|
375
|
+
@staticmethod
|
|
376
|
+
def _is_url(url: str):
|
|
377
|
+
return urlparse(url).scheme in ['http', 'https']
|
|
File without changes
|
|
@@ -37,11 +37,11 @@ def media_from_file(file_path: str) -> Union[MediaFile, ImageFile, AudioFile, Vi
|
|
|
37
37
|
return MediaFile().from_file(file_path)
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
def
|
|
40
|
+
def media_from_any(file, media_file_type=None):
|
|
41
41
|
"""
|
|
42
42
|
Converts a file to a send able format.
|
|
43
43
|
:param file: The file to convert.
|
|
44
|
-
:param
|
|
44
|
+
:param media_file_type: The target type to convert to. If not specified will be converted to MediaFile.
|
|
45
45
|
Use ImageFile, AudioFile, VideoFile to convert to those types.
|
|
46
46
|
:return: The send able file.
|
|
47
47
|
"""
|
|
@@ -51,8 +51,8 @@ def convert_to_upload_file_type(file, target_media_file=None):
|
|
|
51
51
|
|
|
52
52
|
# determine target class
|
|
53
53
|
target_class = MediaFile
|
|
54
|
-
if
|
|
55
|
-
target_class =
|
|
54
|
+
if media_file_type is not None and issubclass(media_file_type, MediaFile):
|
|
55
|
+
target_class = media_file_type
|
|
56
56
|
media_file_instance = target_class()
|
|
57
57
|
|
|
58
58
|
# load data
|
|
@@ -60,7 +60,7 @@ def convert_to_upload_file_type(file, target_media_file=None):
|
|
|
60
60
|
return media_file_instance
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def
|
|
63
|
+
def media_from_file_result(file_result: dict):
|
|
64
64
|
"""
|
|
65
65
|
Converts a file result to a MediaFile.
|
|
66
66
|
:param file_result: The file result to convert.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: media-toolkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.1.dev1
|
|
4
4
|
Summary: Web-ready standardized file processing and serialization. Read, load and convert to standard file types with a common interface.
|
|
5
5
|
Author: SocAIty
|
|
6
6
|
License: GPLv3
|
|
@@ -46,10 +46,11 @@ Load and convert from and to common data types:
|
|
|
46
46
|
- bytes,
|
|
47
47
|
- base64
|
|
48
48
|
- json
|
|
49
|
+
- urls
|
|
49
50
|
- etc.
|
|
50
51
|
|
|
51
52
|
Transmit files between services with a common interface
|
|
52
|
-
- Native FastSDK and FastTaskAPI integration
|
|
53
|
+
- Native [FastSDK](https://github.com/SocAIty/fastSDK) and [FastTaskAPI](https://github.com/SocAIty/FastTaskAPI) integration
|
|
53
54
|
- Supports httpx, requests
|
|
54
55
|
|
|
55
56
|
Work with native python libs like BytesIO.
|
|
@@ -63,9 +64,9 @@ You can install the package with PIP, or clone the repository.
|
|
|
63
64
|
```bash
|
|
64
65
|
# install from pypi
|
|
65
66
|
pip install media-toolkit
|
|
66
|
-
# install without dependencies: this is useful if you only need the basic functionality
|
|
67
|
+
# install without dependencies: this is useful if you only need the basic functionality (working with files)
|
|
67
68
|
pip install media-toolkit --no-deps
|
|
68
|
-
# if you
|
|
69
|
+
# if you want to use certain file types, and convenience functions
|
|
69
70
|
pip install media-toolkit[VideoFile] # or [AudioFile, VideoFile, ...]
|
|
70
71
|
# install from github for newest release
|
|
71
72
|
pip install git+git://github.com/SocAIty/media-toolkit
|
|
@@ -84,7 +85,7 @@ The library automatically detects the data type and loads it correctly.
|
|
|
84
85
|
```python
|
|
85
86
|
from media_toolkit import MediaFile, ImageFile, AudioFile, VideoFile
|
|
86
87
|
|
|
87
|
-
# could be a path, base64, bytesio, file_handle, numpy array ...
|
|
88
|
+
# could be a path, url, base64, bytesio, file_handle, numpy array ...
|
|
88
89
|
arbitrary_data = "...."
|
|
89
90
|
# Instantiate an image file
|
|
90
91
|
new_file = ImageFile().from_any(arbitrary_data)
|
|
@@ -189,6 +190,7 @@ my_files = {
|
|
|
189
190
|
response = httpx.Client().post(url, files=my_files)
|
|
190
191
|
```
|
|
191
192
|
|
|
193
|
+
|
|
192
194
|
# How it works
|
|
193
195
|
|
|
194
196
|
If media-file is instantiated with ```from_*``` it converts it to an intermediate representation.
|
|
@@ -199,5 +201,5 @@ Currently the intermediate representation is supported in memory with (BytesIO).
|
|
|
199
201
|
|
|
200
202
|
# ToDo:
|
|
201
203
|
|
|
202
|
-
[x] additionally support tempfile backend instead of working bytesio memory mode only.
|
|
203
|
-
[x] decreasing redundancies for _file_info() method
|
|
204
|
+
- [x] additionally support tempfile backend instead of working bytesio memory mode only.
|
|
205
|
+
- [x] decreasing redundancies for _file_info() method
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "media-toolkit"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.1.1.dev1"
|
|
8
8
|
description = "Web-ready standardized file processing and serialization. Read, load and convert to standard file types with a common interface."
|
|
9
9
|
requires-python = ">=3.8"
|
|
10
10
|
authors = [
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
from media_toolkit import ImageFile
|
|
3
|
+
|
|
4
|
+
outdir = "outdir/"
|
|
5
|
+
def test_img_from_url():
|
|
6
|
+
url = "https://github.com/SocAIty/face2face/blob/main/test/test_imgs/test_face_1.jpg?raw=true"
|
|
7
|
+
fromurl = ImageFile().from_any(url)
|
|
8
|
+
fromurl.save(f"{outdir}test_face_1_1.jpg")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
test_img_from_url()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests some core functionalities of the VideoFile class.
|
|
3
|
+
"""
|
|
4
|
+
from tqdm import tqdm
|
|
5
|
+
|
|
6
|
+
from media_toolkit import VideoFile, ImageFile
|
|
7
|
+
import cv2
|
|
8
|
+
|
|
9
|
+
outdir = "outdir/"
|
|
10
|
+
|
|
11
|
+
def test_video_file():
|
|
12
|
+
test_video = "test_files/test_video.mp4"
|
|
13
|
+
vf = VideoFile().from_file(test_video)
|
|
14
|
+
# extract audio_file
|
|
15
|
+
vf.extract_audio(f"{outdir}/extracted_audio.mp3")
|
|
16
|
+
audio_bytes = vf.extract_audio()
|
|
17
|
+
|
|
18
|
+
def test_video_from_files():
|
|
19
|
+
files = [f"{outdir}/test_out_video_stream_{i}.png" for i in range(10)]
|
|
20
|
+
vf = VideoFile().from_files(files)
|
|
21
|
+
vf.add_audio(f"{outdir}/extracted_audio.mp3")
|
|
22
|
+
vf.save(f"{outdir}/test_from_files_add_audio.mp4")
|
|
23
|
+
# from dir; and combine audio and video
|
|
24
|
+
fromdir = VideoFile().from_dir(outdir, audio=f"{outdir}/extracted_audio.mp3", frame_rate=30)
|
|
25
|
+
fromdir.save(f"{outdir}/test_from_dir.mp4")
|
|
26
|
+
|
|
27
|
+
def test_video_stream():
|
|
28
|
+
audio_array = []
|
|
29
|
+
image_paths = []
|
|
30
|
+
for i, (img, audio_part) in tqdm(enumerate(vf.to_video_stream(include_audio=True))):
|
|
31
|
+
p = f"{outdir}/test_out_video_stream_{i}.png"
|
|
32
|
+
image_paths.append(p)
|
|
33
|
+
cv2.imwrite(p, img)
|
|
34
|
+
audio_array.append(audio_part)
|
|
35
|
+
|
|
36
|
+
# test video clients with audio_file
|
|
37
|
+
fromstream = VideoFile().from_video_stream(fromdir.to_video_stream(include_audio=True))
|
|
38
|
+
fromstream.save(f"{outdir}/test_from_stream.mp4")
|
|
39
|
+
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .file_conversion import media_from_file
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Tests some core functionalities of the VideoFile class.
|
|
3
|
-
"""
|
|
4
|
-
from tqdm import tqdm
|
|
5
|
-
|
|
6
|
-
from media_toolkit import VideoFile
|
|
7
|
-
import cv2
|
|
8
|
-
|
|
9
|
-
outdir = "outdir/"
|
|
10
|
-
|
|
11
|
-
# test video files
|
|
12
|
-
#test_video = "test_files/test_video.mp4"
|
|
13
|
-
#vf = VideoFile().from_file(test_video)
|
|
14
|
-
#### extract audio_file
|
|
15
|
-
#vf.extract_audio(f"{outdir}/extracted_audio.mp3")
|
|
16
|
-
##audio_bytes = vf.extract_audio()
|
|
17
|
-
#
|
|
18
|
-
### test video clients
|
|
19
|
-
#audio_array = []
|
|
20
|
-
#image_paths = []
|
|
21
|
-
#for i, (img, audio_part) in tqdm(enumerate(vf.to_video_stream(include_audio=True))):
|
|
22
|
-
# p = f"{outdir}/test_out_video_stream_{i}.png"
|
|
23
|
-
# image_paths.append(p)
|
|
24
|
-
# cv2.imwrite(p, img)
|
|
25
|
-
# audio_array.append(audio_part)
|
|
26
|
-
|
|
27
|
-
# new video File
|
|
28
|
-
#vf = VideoFile().from_files(image_paths)
|
|
29
|
-
#vf.add_audio(audio_array)
|
|
30
|
-
#vf.save(f"{outdir}/test_from_files_add_audio.mp4")
|
|
31
|
-
# from dir; and combine audio and video
|
|
32
|
-
# files = [f"{outdir}/test_out_video_stream_{i}.png" for i in range(10)]
|
|
33
|
-
|
|
34
|
-
fromdir = VideoFile().from_dir(outdir, audio=f"{outdir}/extracted_audio.mp3", frame_rate=30)
|
|
35
|
-
fromdir.save(f"{outdir}/test_from_dir.mp4")
|
|
36
|
-
|
|
37
|
-
# test video clients with audio_file
|
|
38
|
-
fromstream = VideoFile().from_video_stream(fromdir.to_video_stream(include_audio=True))
|
|
39
|
-
fromstream.save(f"{outdir}/test_from_stream.mp4")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit/utils/dependency_requirements.py
RENAMED
|
File without changes
|
|
File without changes
|
{media_toolkit-0.0.8 → media_toolkit-0.1.1.dev1}/media_toolkit.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|