[Python] Bria API Slow Response Time (~40-60s per Image) When Processing 300+ Images...

Discussão em 'Python' iniciado por Stack, Abril 7, 2025.

  1. Stack

    Stack Membro Participativo

    I’m currently integrating the Bria API to remove backgrounds from video frames (images) in bulk using asynchronous Python code.

    The setup works fine for a small number of images, but when I send more than 300 images, I encounter severe slowness. Each API response takes 40 to 60 seconds per image, significantly slowing down the overall processing pipeline.

    Here is a part of my async function that handles the response and downloads the final image returned by Bria:

    import aiohttp
    import asyncio
    import re

    # Bria response post-process: downloads image using the final processed URL
    async def process_output_url(session, url):
    if url is not None:
    pattern = re.search("_(frame.*)", url)
    if pattern:
    imagename = pattern.group(1)

    pattern1 = re.search("(.*)_frame", url)
    if pattern1:
    url = pattern1.group(1)
    else:
    print("One None data found in URL")
    return None, None

    async with session.get(url) as response:
    data = await response.read()
    return data, imagename


    What I'm doing:
    I extract hundreds of frames from a video.

    Send each frame (as image) to Bria’s background removal endpoint.

    Once the background is removed, I get a response with a new image URL (hosted on Bria’s side).

    I then download the image using the function above.

    The problem:
    After ~200 images, the response time drastically increases.

    For 300+ images, it's taking 20+ minutes just to receive and download processed URLs.

    I suspect either rate-limiting or heavy payload/queueing on the Bria side.

    What I’ve tried:
    Limited concurrency with asyncio.Semaphore.

    Added retry logic for failed calls.

    Checked for any "429 Too Many Requests" responses — not seeing those.

    Split requests into chunks of 50-100 — minimal improvement.

    What I need help with:
    How can I optimize or batch Bria API usage to reduce response time?

    Is there a better way to handle downloading the processed images asynchronously?

    Any known rate limits or best practices when using the Bria API for high-volume usage?

    Should I add delay between requests or use exponential backoff?

    Any help, advice, or workaround would be greatly appreciated as I'm stuck on this bottleneck and unable to move forward with the rest of the video processing pipeline.

    Thank you!

    Continue reading...

Compartilhe esta Página