Skip to content

Commit

Permalink
Fix encoder_name param while initialising Client
Browse files Browse the repository at this point in the history
1. Make `encoder_name` work again
2. Add `codec_name` param to work with encoder_name
  • Loading branch information
xiaokang00010 authored and leng-yue committed Aug 31, 2024
1 parent b7fadda commit 1488792
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scrcpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
lock_screen_orientation: int = LOCK_SCREEN_ORIENTATION_UNLOCKED,
connection_timeout: int = 3000,
encoder_name: Optional[str] = None,
codec_name: Optional[str] = None,
):
"""
Create a scrcpy client, this client won't be started until you call the start function
Expand All @@ -48,6 +49,7 @@ def __init__(
lock_screen_orientation: lock screen orientation, LOCK_SCREEN_ORIENTATION_*
connection_timeout: timeout for connection, unit is ms
encoder_name: encoder name, enum: [OMX.google.h264.encoder, OMX.qcom.video.encoder.avc, c2.qti.avc.encoder, c2.android.avc.encoder], default is None (Auto)
codec_name: codec name, enum: [h264, h265, av1], default is None (Auto)
"""
# Check Params
assert max_width >= 0, "max_width must be greater than or equal to 0"
Expand All @@ -66,6 +68,12 @@ def __init__(
"c2.qti.avc.encoder",
"c2.android.avc.encoder",
]
assert codec_name in [
None,
"h264",
"h265",
"av1"
]

# Params
self.flip = flip
Expand All @@ -77,6 +85,7 @@ def __init__(
self.lock_screen_orientation = lock_screen_orientation
self.connection_timeout = connection_timeout
self.encoder_name = encoder_name
self.codec_name = codec_name

# Connect to device
if device is None:
Expand Down Expand Up @@ -154,15 +163,18 @@ def __deploy_server(self) -> None:
f"max_size={self.max_width}",
f"max_fps={self.max_fps}",
f"video_bit_rate={self.bitrate}",
f"video_encoder={self.encoder_name}" if self.encoder_name else "video_encoder=OMX.google.h264.encoder",
f"video_codec={self.codec_name}" if self.codec_name else "video_codec=h264",
"tunnel_forward=true",
"send_frame_meta=false",
"control=true",
"audio=false",
"show_touches=false",
"stay_awake=false",
"power_off_on_close=false",
"clipboard_autosync=false"
"clipboard_autosync=false",
]
print(commands)

self.__server_stream: AdbConnection = self.device.shell(
commands,
Expand Down

0 comments on commit 1488792

Please sign in to comment.