Skip to content

How to concat multiple streamed audio inputs #869

Description

@jaredculp

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions