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

Bits per coded sample #1330

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 24 additions & 0 deletions av/video/codeccontext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ cdef class VideoCodecContext(CodecContext):
self.ptr.height = value
self._build_format()

@property
def bits_per_coded_sample(self):
"""
bits per sample/pixel from the demuxer (needed for huffyuv).

encoding: Set by libavcodec.
decoding: Set by user.

Wraps :ffmpeg:`AVCodecContext::bits_per_coded_sample`

:type: int
"""
return self.ptr.bits_per_coded_sample

@bits_per_coded_sample.setter
def bits_per_coded_sample(self, int value):
if self.is_encoder:
warnings.warn(
"Setting VideoCodecContext.bits_per_coded_sample for encoders is deprecated.",
AVDeprecationWarning
)
self.ptr.bits_per_coded_sample = value
self._build_format()

@property
def pix_fmt(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ cdef extern from "libavcodec/avcodec.h" nogil:
int bit_rate_tolerance
int mb_decision

int bits_per_coded_sample

int global_quality
int compression_level

Expand Down
32 changes: 32 additions & 0 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,38 @@ def _assert_parse(self, codec_name, path):
self.assertEqual(len(parsed_source), len(full_source))
self.assertEqual(full_source, parsed_source)

def test_bits_per_coded_sample(self):
with av.open(fate_suite("qtrle/aletrek-rle.mov")) as container:
stream = container.streams.video[0]
stream.codec_context.bits_per_coded_sample = 32

for packet in container.demux(stream):
for frame in packet.decode():
pass
self.assertEqual(packet.stream.codec_context.bits_per_coded_sample, 32)

with av.open(fate_suite("qtrle/aletrek-rle.mov")) as container:
stream = container.streams.video[0]
stream.codec_context.bits_per_coded_sample = 31

with self.assertRaises(av.error.InvalidDataError):
for packet in container.demux(stream):
for frame in packet.decode():
pass
self.assertEqual(
packet.stream.codec_context.bits_per_coded_sample, 31
)

with av.open(self.sandboxed("output.mov"), "w") as output:
stream = output.add_stream("qtrle")

with warnings.catch_warnings(record=True) as captured:
stream.codec_context.bits_per_coded_sample = 32
self.assertEqual(
captured[0].message.args[0],
"Setting VideoCodecContext.bits_per_coded_sample for encoders is deprecated.",
)


class TestEncoding(TestCase):
def test_encoding_png(self):
Expand Down
Loading