Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PyAV
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 37
    • Issues 37
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 26
    • Merge requests 26
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyAV
  • PyAV
  • Issues
  • #1088
Closed
Open
Issue created Feb 15, 2023 by Dave Johansen@daveisfera6 of 6 checklist items completed6/6 checklist items

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.
Assignee
Assign to
Time tracking