|
7 | 7 | import copy
|
8 | 8 | import operator
|
9 | 9 | import subprocess
|
| 10 | +import asyncio |
10 | 11 |
|
11 | 12 | from ._ffmpeg import input, output
|
12 | 13 | from .nodes import (
|
@@ -326,4 +327,37 @@ def run(
|
326 | 327 | return out, err
|
327 | 328 |
|
328 | 329 |
|
329 |
| -__all__ = ['compile', 'Error', 'get_args', 'run', 'run_async'] |
| 330 | +@output_operator() |
| 331 | +async def run_asyncio( |
| 332 | + stream_spec, cmd='ffmpeg', pipe_stdin=False, pipe_stdout=False, pipe_stderr=False, |
| 333 | + quiet=False, overwrite_output=False): |
| 334 | + """Asynchronously invoke ffmpeg in asyncio sync/await style and return coroutine. |
| 335 | + Have the same possibilities as `run_async` call. |
| 336 | +
|
| 337 | + Args: |
| 338 | + pipe_stdin: if True, connect pipe to subprocess stdin (to be |
| 339 | + used with ``pipe:`` ffmpeg inputs). |
| 340 | + pipe_stdout: if True, connect pipe to subprocess stdout (to be |
| 341 | + used with ``pipe:`` ffmpeg outputs). |
| 342 | + pipe_stderr: if True, connect pipe to subprocess stderr. |
| 343 | + quiet: shorthand for setting ``capture_stdout`` and |
| 344 | + ``capture_stderr``. |
| 345 | +
|
| 346 | + Returns: |
| 347 | + A Process instance as a coroutine |
| 348 | + """ |
| 349 | + |
| 350 | + args = compile(stream_spec, cmd, overwrite_output=overwrite_output) |
| 351 | + stdin_stream = asyncio.subprocess.PIPE if pipe_stdin else None |
| 352 | + stdout_stream = asyncio.subprocess.PIPE if pipe_stdout or quiet else None |
| 353 | + stderr_stream = asyncio.subprocess.PIPE if pipe_stderr or quiet else None |
| 354 | + |
| 355 | + return await asyncio.create_subprocess_exec( |
| 356 | + *args, |
| 357 | + stdin=stdin_stream, |
| 358 | + stdout=stdout_stream, |
| 359 | + stderr=stderr_stream |
| 360 | + ) |
| 361 | + |
| 362 | + |
| 363 | +__all__ = ['compile', 'Error', 'get_args', 'run', 'run_async', 'run_asyncio'] |
0 commit comments