ffmpeg-python icon indicating copy to clipboard operation
ffmpeg-python copied to clipboard

Can we stream multiple inputs and use complex filter?

Open ne-api opened this issue 1 year ago • 1 comments

I have a code that is written in Typescript that takes in two streams of audio and combines them into one. Below is the TypeScript Code. Can anyone help how this can be done in python using this package?

   `const leftStream = await getKvsStream(`gprc-${callId}-AGENT`);
    const rightStream = await getKvsStream(`gprc-${callId}-CUSTOMER`);

    logger.info(`############ Begin piping KVS streams for callId ${callId}`);

    const ffmpegProcess = spawn('ffmpeg', [
        '-y', // Overwrite output files without asking
        '-re', // Read input at native frame rate
        '-f', 'matroska', '-i', 'pipe:3', // Input stream from pipe 3 (left stream)
        '-re', // Read input at native frame rate
        '-f', 'matroska', '-i', 'pipe:4', // Input stream from pipe 4 (right stream)
        '-filter_complex', '[0:a][1:a]join=inputs=2:channel_layout=stereo[a]', // Combine streams into separate tracks
        '-map', '[a]', // Map the combined audio to the output
        '-c:a', 'pcm_s16le', // Audio codec
        '-ar', '8000',
        '-f', 's16le', // Output format as PCM RAW
        'pipe:1' // Output stream to pipe
    ], {
        stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'] // Create extra pipes
    });

    leftStream.pipe(ffmpegProcess.stdio[3] as Writable);
    rightStream.pipe(ffmpegProcess.stdio[4] as Writable);

    const transcribeStream = new PassThrough();
    const combinedStream = new PassThrough();
            
    ffmpegProcess.stdout.pipe(combinedStream);

    combinedStream.pipe(transcribeStream);

    transcribe.transcribeCombinedAudioStream(transcribeStream, callId, 8000)`

ne-api avatar Oct 26 '24 20:10 ne-api

@ne-api I recommend using VideoAlchemy

hsngerami avatar Dec 25 '24 20:12 hsngerami