-
OverviewMy goal is to write out an array of data as an audio file with the given sampling rate, format, codec and number of channels (mono, stereo, 5.1, 7.1 etc). I am doing this in the following way (sampling rate, audio length, format and codec don't matter here): import av
import av.audio
import numpy as np
sampling_rate = 44800
length = 5
num_channels = 6
data = np.random.random((num_channels, length * sampling_rate))
# "dblp" matches with float64 data types, "5.1" matches with (6, n) data size
frame = av.audio.AudioFrame.from_ndarray(data, "dblp", "5.1")
frame.rate = sampling_rate
with av.open("output.flac", "w", "flac") as container:
stream = container.add_stream("flac", sampling_rate)
stream.channels = num_channels
container.mux(stream.encode(frame))
container.mux(stream.encode(None)) Actual behaviorUp until version 12.3.0 this worked just as expected, but starting from the version 13.0.0 Traceback:
I tried The other possibility would be to pass If I leave it as is without setting Is there another way to set Versions
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You set |
Beta Was this translation helpful? Give feedback.
-
Thank you for the answer. Just to be fully clear, you mean it like this, right? stream = container.add_stream("flac", sampling_rate, layout="5.1") This works for me. |
Beta Was this translation helpful? Give feedback.
You set
layout
to indirectly set the channels now. This is how it's done in the ffmpeg c library as well.