Unexpected warnings about bit_rate when converting audio
Overview
Thanks for the great work on pyav
! I'm using it to convert PCM audio to AAC in memory to convert a stream. It's working but I'm seeing unexpected warnings about bit_rate
Expected behavior
Default bit_rate
would work or setting the bit_rate
to an expected value would not give a warning
Actual behavior
The default gives this error:
Too many bits 16384.000000 > 6144 per frame requested, clamping to max
Then setting bit_rate
to 128 gives this error (and setting it to 128 * 1024 gives the same error as above):
Bitrate 128 is extremely low, maybe you mean 128k
Build report:
Using av==10.0.0
in a requirements.txt
file
Investigation
These warnings are printed in ffmpeg
code
Reproduction
Here's a piece of sample code that's reading the data from files instead of a stream but it shows the issue:
import audioop
import sys
from fractions import Fraction
import av
import numpy
from av.audio.frame import AudioFrame
AUDIO_SAMPLE_RATE = 8000
def _main():
print("Initializing")
fake_output = av.open("/tmp/_alaw_to_aac.mp4", "w")
audio_transcoder = fake_output.add_stream("aac", rate=AUDIO_SAMPLE_RATE, bit_rate=128, layout="mono")
audio_data = AudioFrame(format="s16", layout="mono", samples=160)
audio_data.rate = AUDIO_SAMPLE_RATE
audio_data.time_base = Fraction(1, AUDIO_SAMPLE_RATE)
for n in range(1000):
data = open("{}/sample-{:03d}.alaw".format(sys.argv[1], n), "rb").read()
linear = audioop.alaw2lin(data, 2)
array = numpy.frombuffer(linear, "i2")
audio_data.planes[0].update(array)
audio_data.pts = 20 * n
aac = b""
pts = 0
for p in audio_transcoder.encode(audio_data):
pts = p.pts
aac += bytes(p)
if aac:
print("Size:", pts, len(aac))
print("Done")
if __name__ == "__main__":
_main()
Versions
- OS: Debian Bullseye
- PyAV runtime: 3.9.16
- PyAV build: 10.0.0 from
pip
- FFmpeg: N/A (doesn't output anything so I believe I'm using what's included in the wheel
Research
I have done the following:
-
Checked the PyAV documentation -
Searched on Google -
Searched on Stack Overflow -
Looked through old GitHub issues -
Asked on PyAV Gitter -
... and waited 72 hours for a response.