Skip to content

Commit

Permalink
fix: remove min/max bitrates from vp8/9 encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagruenstein committed Jun 2, 2024
1 parent 3aafa03 commit 4d65fb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions vpx_rtp/codecs/vpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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 *")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d65fb6

Please sign in to comment.