Skip to content

Commit 381aa46

Browse files
authored
Create run.py_
1 parent 4cb7d26 commit 381aa46

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

run.py_

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@output_operator()
2+
async def run_asyncio(
3+
stream_spec, cmd='ffmpeg', pipe_stdin=False, pipe_stdout=False, pipe_stderr=False,
4+
quiet=False, overwrite_output=False):
5+
"""Asynchronously invoke ffmpeg in asyncio sync/await style and return coroutine.
6+
Have the same possibilities as `run_async` call.
7+
Args:
8+
pipe_stdin: if True, connect pipe to subprocess stdin (to be
9+
used with ``pipe:`` ffmpeg inputs).
10+
pipe_stdout: if True, connect pipe to subprocess stdout (to be
11+
used with ``pipe:`` ffmpeg outputs).
12+
pipe_stderr: if True, connect pipe to subprocess stderr.
13+
quiet: shorthand for setting ``capture_stdout`` and
14+
``capture_stderr``.
15+
Returns:
16+
A Process instance as a coroutine
17+
"""
18+
19+
args = compile(stream_spec, cmd, overwrite_output=overwrite_output)
20+
stdin_stream = asyncio.subprocess.PIPE if pipe_stdin else None
21+
stdout_stream = asyncio.subprocess.PIPE if pipe_stdout or quiet else None
22+
stderr_stream = asyncio.subprocess.PIPE if pipe_stderr or quiet else None
23+
24+
return await asyncio.create_subprocess_exec(
25+
*args,
26+
stdin=stdin_stream,
27+
stdout=stdout_stream,
28+
stderr=stderr_stream
29+
)

0 commit comments

Comments
 (0)