Modifying scrcpy to Force H264 Baseline Profile for Real-Time Android Screen Casting
This article describes the limitations of existing Android screen‑casting tools, analyzes the H264 profile issue on devices like Xiaomi 9, and details how the scrcpy source code was altered to output baseline H264 streams, enabling reliable real‑time casting via the Broadway web plugin.
Background: The cloud device platform currently uses two real‑time casting tools—STF's minicap, which captures screenshots, and scrcpy, which streams video but only supports Android 5.0+. Both have drawbacks; minicap lags behind new Android releases, while scrcpy cannot handle devices (e.g., Vivo, Oppo, Xiaomi 9) that output H264 streams with a High profile, which the Broadway web player only supports for baseline profiles.
Solution: Using a Xiaomi 9 (Android 9.0) as an example, the H264 stream was inspected and found to have profile_idc = 100 (High). By examining scrcpy’s source, the private createFormat method in ScreenEncoder was identified as the place to set the video format. The method was modified to force the profile to baseline ( profile_idc = 66 ).
Implementation steps:
Recompile the modified scrcpy source into a JAR file and push it to the device.
Execute on the device: CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / --nice-name=scrcpy_server com.genymobile.scrcpy.Server 0 8000000 true weight:height:0:0 false Note: each run clears the previously pushed JAR, so the JAR must be pushed before every start.
Run adb forward to forward the device’s socket to the PC and capture the video stream.
Parse the received H264 stream into individual frames and send them to the web front‑end, where the Broadway plugin plays the baseline H264 video, achieving real‑time casting.
Result: After the modification, the scrcpy‑generated video stream shows profile_idc = 66 , confirming the baseline format and successful playback in the web client.
Effect demonstration: Screenshots and GIFs illustrate the real‑time casting working correctly with the modified scrcpy.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.