I work with multistream audio files in ffmpeg:
ffmpeg -i stream1.m4a -i stream2.m4a -map 0:1 -map 0:2 out.m4a
As I understand this has been discussed here this is supported. Is this correct?
Now is there a way to use pipes as input and doing this in ffmpeg-python so that I can create multistream outputs from e.g. numpy arrays?
Here is an example what I use for single stream outputs:
# audio: numpy array
process = ffmpeg.input('pipe:', format='f32le').output(path).run_async()
process.stdin.write(audio.astype('<f4').tobytes())
@loretoparisi maybe you have an idea?
Workaround could be: stack to multi__channel__ and convert to multistream?
@faroit good question. I did any multi-stream input so far, typically we process more or less as in your case file/pipe in buffer out, like to output a waveform to a np array buffer:
process = (
ffmpeg
.input(path)
.output('pipe:', **kwargs)
.run_async(pipe_stdout=True, pipe_stderr=True))
buf, _ = process.communicate()
wv = np.frombuffer(buf, dtype='<f4').reshape(-1, 2)
Which is your use case?
Which is your use case?
I want to update stempeg to write stem files (m4a with 5 stereo multistreams) directly using ffmpeg-python
@loretoparisi I managed to do this now with -complex_filter and multiple maps. Is there an example how to use -complex_filter in ffmpeg-python?
As a workaround for muxing multiple stereo streams into one multistream file (e.g. two stereo audio file into a single 2-stream audio file), I came up with the idea of stacking the stereo streams into multiple channels and use a complex filter to map the channels to streams such as:
ffmpeg -y -i in.wav -filter_complex "\
[a:0]pan=stereo| c0=c0 | c1=c1[a0]; \
[a:0]pan=stereo| c0=c2 | c1=c3[a1]; \
" -map "[a0]" -map "[a1]" -c:a pcm_s16le out.mka
Would this be implementable in ffmpeg-python?
@loretoparisi @kkroening
@faroit good question, @shoegazerstella any idea?
@faroit That looks similar to what I was trying to accomplish with ffmpeg-python, but I don't know how to translate this crazy vertical-stacking command:
ffmpeg -y -i "v1.mkv" -i "v2.mkv" \
-filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3[a]" \
-map "[v]" \
-map "[a]" test.mkv
@mikebridge @kkroening wouldn't it make sense for these difficult operations to allow passing the complex filter string to ffmpeg-python? I guess this has been discussed before but many of the issues here are coming from users that know already how to solver their issue in the cli with ffmpeg and want to re-implement this in ffmpeg-python...