import asyncio


async def run_command(*args):
    # Create subprocess
    process = await asyncio.create_subprocess_exec(
        *args,
        # stdout must a pipe to be accessible as process.stdout
        stdout=asyncio.subprocess.PIPE)
    # Wait for the subprocess to finish
    stdout, stderr = await process.communicate()
    # Return stdout
    return stdout.decode().strip()


async def render_frame(time_string, input_path, filename, filter=None):
    if filter is None:
        await run_command('ffmpeg', '-y', '-ss', time_string, '-i', input_path, '-vframes', str(1), filename)
    else:
        await run_command('ffmpeg', '-y', '-ss', time_string, '-i', input_path, '-vframes', str(1), "-vf", filter,
                          filename)
