Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to concat multiple streamed audio inputs #869

Open
jaredculp opened this issue Mar 7, 2025 · 0 comments
Open

How to concat multiple streamed audio inputs #869

jaredculp opened this issue Mar 7, 2025 · 0 comments

Comments

@jaredculp
Copy link

jaredculp commented Mar 7, 2025

Thank you for this wonderful library! I am wondering how I can translate the code below to be able to concatenate multiple opus audio files using the BytesIO API.

In this contrived example I am reading files off disk, but in reality I am reading files from S3. I am trying to avoid any intermediate writes to disk and instead just stream directly to ffmpeg. Is this possible?

from pathlib import Path

import ffmpeg

input = Path.cwd().joinpath("input.txt")
with input.open("w") as f:
    # in reality, this is more like:
    # for i, obj in enumerate([
    #     s3.get_object(Bucket=bucket_name, Key=obj["Key"])["Body"].read()
    #     for obj in s3_bucket_list_objects_v2(bucket_name=bucket_name, key=key)["Contents"]
    # ]):
    for i, obj in enumerate(Path.cwd().glob("recording*.webm")):
        f.write(f"file '{content}'\n")

output = Path.cwd().joinpath("combined.webm")
ffmpeg.input(str(input), format="concat", safe=0).output(str(output), c="copy").run()
@jaredculp jaredculp changed the title How to concat multiple audio inputs without using files How to concat multiple streamed audio inputs Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant