From 4d65fb6898860ef7b3da3250a6292b428437d048 Mon Sep 17 00:00:00 2001 From: Josh Gruenstein Date: Sun, 2 Jun 2024 14:18:44 -0400 Subject: [PATCH] fix: remove min/max bitrates from vp8/9 encoder --- examples/flag.py | 2 +- vpx_rtp/codecs/vpx.py | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/flag.py b/examples/flag.py index 740ea8d..9782744 100644 --- a/examples/flag.py +++ b/examples/flag.py @@ -60,7 +60,7 @@ def generate_flag_frames() -> list[VideoFrame]: codec = VpxCodec.VP9 -video_encoder = Vp8Encoder(codec) +video_encoder = Vp8Encoder(codec, target_bitrate=200000) video_decoder = Vp8Decoder(codec) pts_timestamp = 0 diff --git a/vpx_rtp/codecs/vpx.py b/vpx_rtp/codecs/vpx.py index 1485bf3..206bc6e 100644 --- a/vpx_rtp/codecs/vpx.py +++ b/vpx_rtp/codecs/vpx.py @@ -16,8 +16,6 @@ VIDEO_TIME_BASE = fractions.Fraction(1, VIDEO_CLOCK_RATE) DEFAULT_BITRATE = 500000 # 500 kbps -MIN_BITRATE = 250000 # 250 kbps -MAX_BITRATE = 1500000 # 1.5 Mbps MAX_FRAME_RATE = 30 PACKET_MAX = 1300 @@ -35,6 +33,11 @@ ) +class VpxCodec(Enum): + VP8 = VP8_CODEC + VP9 = VP9_CODEC + + def convert_timebase( pts: int, from_base: fractions.Fraction, to_base: fractions.Fraction ) -> int: @@ -189,11 +192,6 @@ def _vpx_assert(err: int) -> None: raise Exception("libvpx error: " + reason.decode("utf8")) -class VpxCodec(Enum): - VP8 = VP8_CODEC - VP9 = VP9_CODEC - - class Vp8Decoder: def __init__(self, codec: VpxCodec = VpxCodec.VP9) -> None: self.codec = ffi.new("vpx_codec_ctx_t *") @@ -261,9 +259,6 @@ class Vp8Encoder: def __init__( self, codec: VpxCodec = VpxCodec.VP9, target_bitrate: int = DEFAULT_BITRATE ) -> None: - if target_bitrate < MIN_BITRATE or target_bitrate > MAX_BITRATE: - raise ValueError("Invalid target bitrate") - match codec: case VpxCodec.VP8: self.cx = lib.vpx_codec_vp8_cx() @@ -410,7 +405,6 @@ def target_bitrate(self) -> int: @target_bitrate.setter def target_bitrate(self, bitrate: int) -> None: - bitrate = max(MIN_BITRATE, min(bitrate, MAX_BITRATE)) if bitrate != self.__target_bitrate: self.__target_bitrate = bitrate self.__update_config_needed = True