Skip to content

Commit 4b391f9

Browse files
committed
black format
1 parent 7c7e9ff commit 4b391f9

File tree

9 files changed

+64
-67
lines changed

9 files changed

+64
-67
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
2-
max-line-length = 132
2+
max-line-length = 110
33
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/

README.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# asyncio FFmpeg
1+
# Python asyncio FFmpeg
22

33
[![Actions Status](https://github.com/scivision/asyncio-subprocess-ffmpeg/workflows/ci/badge.svg)](https://github.com/scivision/asyncio-subprocess-ffmpeg/actions)
44

@@ -50,19 +50,3 @@ Even though coroutines are more efficient in many applications, the syntax of `c
5050
### Coroutine
5151

5252
* play_coroutine.py: `asyncio` coroutine event loop to spawn processes.
53-
54-
### Fortran
55-
56-
* `play_coarray.f90`: example of using Fortran with processes and coarrays.
57-
58-
Build by
59-
60-
```sh
61-
meson build
62-
meson compile -C build
63-
```
64-
65-
run like
66-
```sh
67-
cafrun -np 3 playvid ~/Videos/*
68-
```

examples/demo.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
1313
We didn't break out worker setup time from computation time.
1414
In real-world situations, coroutines can be faster and less resource-consuming than threads.
15-
There is no one best choice for all task types, we fit the asynchronous architecture to the task.
16-
There are numerous other popular implementations of threading and coroutines beyond the built-in modules used here.
17-
18-
In computation-bound programs like this example, coroutines and threads would generally not be as good a choice
19-
as multiprocessing. However, the heavier resource usage of multiprocessing is not necessarily best for IO-bound tasks
15+
There is no one best choice for all task types,
16+
we fit the asynchronous architecture to the task.
17+
There are numerous other popular implementations of threading and coroutines
18+
beyond the built-in modules used here.
19+
20+
In computation-bound programs like this example, coroutines and threads would
21+
generally not be as good a choice as multiprocessing.
22+
However, the heavier resource usage of multiprocessing is not necessarily best for IO-bound tasks
2023
such as waiting for network connections, where coroutines and/or threads are often a better choice.
2124
"""
2225

@@ -62,7 +65,7 @@ def run(self):
6265

6366

6467
def mp_worker(i: int, Niter: int, tic: float):
65-
""" multiprocessing worker"""
68+
"""multiprocessing worker"""
6669
for _ in range(Niter):
6770
math.sin(3)
6871

@@ -78,7 +81,10 @@ def mp_worker(i: int, Niter: int, tic: float):
7881
)
7982
P.add_argument("-Nworker", help="number of workers", type=int, default=4)
8083
P.add_argument(
81-
"-Niter", help="number of loop iterations (arbitrary)", type=int, default=5000000,
84+
"-Niter",
85+
help="number of loop iterations (arbitrary)",
86+
type=int,
87+
default=5000000,
8288
)
8389
A = P.parse_args()
8490

examples/play_coroutine.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
from asyncioffmpeg import get_videos
77

88

9-
if __name__ == "__main__":
10-
p = ArgumentParser(description="Plays media files asynchronously with FFplay")
11-
p.add_argument("path", help="directory where media files are kept")
12-
p.add_argument(
13-
"-suffix", help="file suffixes of desired media file types", nargs="+",
14-
)
15-
P = p.parse_args()
9+
p = ArgumentParser(description="Plays media files asynchronously with FFplay")
10+
p.add_argument("path", help="directory where media files are kept")
11+
p.add_argument(
12+
"-suffix",
13+
help="file suffixes of desired media file types",
14+
nargs="+",
15+
)
16+
P = p.parse_args()
1617

17-
flist = get_videos(P.path, P.suffix)
18-
print("found", len(flist), "files in", P.path)
18+
flist = get_videos(P.path, P.suffix)
19+
print("found", len(flist), "files in", P.path)
1920

20-
asyncio.run(play.main(flist))
21+
asyncio.run(play.main(flist))

examples/play_thread.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def ffplay(filein: Path):
2525
p = ArgumentParser(description="Asynchronous playback with ThreadPool and FFplay")
2626
p.add_argument("path", help="directory where media files are kept")
2727
p.add_argument(
28-
"-suffix", help="file suffixes of desired media file types", nargs="+",
28+
"-suffix",
29+
help="file suffixes of desired media file types",
30+
nargs="+",
2931
)
3032
P = p.parse_args()
3133

examples/play_thread_queue.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def main(qin: queue.Queue):
2828
p = ArgumentParser(description="Asynchronous playback with ThreadPool and FFplay")
2929
p.add_argument("path", help="directory where media files are kept")
3030
p.add_argument(
31-
"-suffix", help="file suffixes of desired media file types", nargs="+",
31+
"-suffix",
32+
help="file suffixes of desired media file types",
33+
nargs="+",
3234
)
3335
P = p.parse_args()
3436

examples/probe_coroutine.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
import asyncioffmpeg.ffprobe as probe
1111

1212

13-
if __name__ == "__main__":
14-
p = ArgumentParser(description="Get media metadata asynchronously with FFprobe")
15-
p.add_argument("path", help="directory where media files are kept")
16-
p.add_argument(
17-
"-suffix", help="file suffixes of desired media file types", nargs="+",
18-
)
19-
P = p.parse_args()
13+
p = ArgumentParser(description="Get media metadata asynchronously with FFprobe")
14+
p.add_argument("path", help="directory where media files are kept")
15+
p.add_argument(
16+
"-suffix",
17+
help="file suffixes of desired media file types",
18+
nargs="+",
19+
)
20+
P = p.parse_args()
2021

21-
tic = time.monotonic()
22-
# %% emits results as each future is completed
23-
asyncio.run(probe.get_meta(P.path, P.suffix))
24-
print(f"ffprobe asyncio.as_completed: {time.monotonic() - tic:.3f} seconds")
22+
tic = time.monotonic()
23+
# %% emits results as each future is completed
24+
asyncio.run(probe.get_meta(P.path, P.suffix))
25+
print(f"ffprobe asyncio.as_completed: {time.monotonic() - tic:.3f} seconds")
2526

26-
# %% approximately same wallclock time, but only gives results when all futures complete
27-
tic = time.monotonic()
28-
asyncio.run(probe.get_meta_gather(P.path, P.suffix))
29-
print(f"ffprobe asyncio.gather: {time.monotonic() - tic:.3f} seconds")
27+
# %% approximately same wallclock time, but only gives results when all futures complete
28+
tic = time.monotonic()
29+
asyncio.run(probe.get_meta_gather(P.path, P.suffix))
30+
print(f"ffprobe asyncio.gather: {time.monotonic() - tic:.3f} seconds")

examples/probe_sync.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
from asyncioffmpeg import get_videos
77

88

9-
if __name__ == "__main__":
10-
p = ArgumentParser(description="Get media metadata synchronously with FFprobe")
11-
p.add_argument("path", help="directory where media files are kept")
12-
p.add_argument(
13-
"-suffix", help="file suffixes of desired media file types", nargs="+",
14-
)
15-
P = p.parse_args()
9+
p = ArgumentParser(description="Get media metadata synchronously with FFprobe")
10+
p.add_argument("path", help="directory where media files are kept")
11+
p.add_argument(
12+
"-suffix",
13+
help="file suffixes of desired media file types",
14+
nargs="+",
15+
)
16+
P = p.parse_args()
1617

17-
tic = time.monotonic()
18-
for f in get_videos(P.path, P.suffix):
19-
meta = probe.ffprobe_sync(f)
20-
probe.print_meta(meta)
18+
tic = time.monotonic()
19+
for f in get_videos(P.path, P.suffix):
20+
meta = probe.ffprobe_sync(f)
21+
probe.print_meta(meta)
2122

22-
print(f"ffprobe sync: {time.monotonic() - tic:.3f} seconds")
23+
print(f"ffprobe sync: {time.monotonic() - tic:.3f} seconds")

src/asyncioffmpeg/ffprobe.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def print_meta(meta: typing.Dict[str, typing.Any]):
2424

2525

2626
async def get_meta_gather(path: Path, suffix: str) -> typing.List[typing.Dict[str, typing.Any]]:
27-
""" for comparison with asyncio.as_completed"""
27+
"""for comparison with asyncio.as_completed"""
2828
futures = [ffprobe(f) for f in get_videos(path, suffix)]
2929
metas = await asyncio.gather(*futures)
3030
for meta in metas:
@@ -45,7 +45,7 @@ async def get_meta(path: Path, suffix: str) -> typing.List[typing.Dict[str, typi
4545

4646

4747
async def ffprobe(file: Path) -> typing.Dict[str, typing.Any]:
48-
""" get media metadata """
48+
"""get media metadata"""
4949
proc = await asyncio.create_subprocess_exec(
5050
*[
5151
FFPROBE,
@@ -66,7 +66,7 @@ async def ffprobe(file: Path) -> typing.Dict[str, typing.Any]:
6666

6767

6868
def ffprobe_sync(file: Path) -> typing.Dict[str, typing.Any]:
69-
""" get media metadata """
69+
"""get media metadata"""
7070
meta = subprocess.check_output(
7171
[
7272
FFPROBE,

0 commit comments

Comments
 (0)