Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AudioLayout's "copy" constructor (fixes: #1434) #1435

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion av/audio/layout.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ cdef class AudioLayout:
elif isinstance(layout, str):
c_layout = lib.av_get_channel_layout(layout)
elif isinstance(layout, AudioLayout):
c_layout = layout.layout
c_layout = (<AudioLayout>layout).layout
else:
raise TypeError("layout must be str or int")

Expand Down
9 changes: 7 additions & 2 deletions tests/test_audiolayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@


class TestAudioLayout(TestCase):
def test_stereo_properties(self):
def test_stereo_from_str(self):
layout = AudioLayout("stereo")
self._test_stereo(layout)

def test_2channel_properties(self) -> None:
def test_stereo_from_int(self):
layout = AudioLayout(2)
self._test_stereo(layout)

def test_stereo_from_layout(self):
layout = AudioLayout("stereo")
layout2 = AudioLayout(layout)
self._test_stereo(layout2)

def test_channel_counts(self):
self.assertRaises(ValueError, AudioLayout, -1)
self.assertRaises(ValueError, AudioLayout, 9)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest import SkipTest

import av
from av import AudioResampler, Codec, Packet
from av import AudioLayout, AudioResampler, Codec, Packet
from av.codec.codec import UnknownCodecError
from av.video.frame import PictureType

Expand Down Expand Up @@ -393,6 +393,12 @@ def test_encoding_mp2(self):
maxDiff = None

def audio_encoding(self, codec_name):
self._audio_encoding(codec_name=codec_name, channel_layout="stereo")
self._audio_encoding(
codec_name=codec_name, channel_layout=AudioLayout("stereo")
)

def _audio_encoding(self, *, codec_name, channel_layout):
try:
codec = Codec(codec_name, "w")
except UnknownCodecError:
Expand All @@ -404,14 +410,12 @@ def audio_encoding(self, codec_name):

sample_fmt = ctx.codec.audio_formats[-1].name
sample_rate = 48000
channel_layout = "stereo"
channels = 2

ctx.time_base = Fraction(1) / sample_rate
ctx.sample_rate = sample_rate
ctx.format = sample_fmt
ctx.layout = channel_layout
ctx.channels = channels

ctx.open()

Expand Down Expand Up @@ -549,7 +553,6 @@ def audio_encoding(self, codec_name):
ctx.sample_rate = sample_rate
ctx.format = sample_fmt
ctx.layout = channel_layout
ctx.channels = channels
ctx.open()

result_samples = 0
Expand Down
Loading