Android device screen projection method and system based on USB and network connection

By using USB to network connection method in Android device screen projection technology, combining ADB tools and SCRCPY software, video streaming is achieved using Go language and network protocol, and the problems of single connection method and high resource occupation in the existing technology are solved, and the problem of single connection method and high resource occupation is realized. Efficient, flexible and easy to use real-time screen mirroring effect.

CN119484496APending Publication Date: 2025-02-18ZKTECO CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411417849.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The existing Android device screen projection technology has problems such as single connection mode, high resource occupation, large latency, insufficient performance optimization, poor firewall penetration capability and lack of fine control. It cannot be compatible with USB and Ethernet connections at the same time, especially in enterprise firewall environments. Poor performance.

Method used

Using the screen projection method and system of Android device based on USB and network connection, establish a connection with Android device through ADB tools, use SCRCPY for screen acquisition and H.264/AVC encoding, and use Go language and HTTP, TCP, WebSocket and other network protocols to implement it. Video stream transmission supports USB and Ethernet connection, real-time screen mirroring without intrusiveness and cross-platform.

Benefits of technology

It realizes efficient real-time screen mirroring, flexible connection mode, easy to deploy and use, has cross-platform support, high compatibility and scalability, stable performance and low resource consumption, improves security and privacy protection, suitable for Various application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119484496A_ABST
    Figure CN119484496A_ABST
Patent Text Reader

Abstract

The invention provides an Android device screen projection method and system based on USB and network connection, and relates to the technical field of video streaming media transmission, and the method comprises the steps: building a communication connection between a PC and an Android device through an ADB tool, and transmitting an SCRCPY tool to a designated directory of the Android device through a push command of the ADB; using an ADB shell command to start SCRCPY on the Android device to capture and encode screen content; port forwarding is carried out by using an ADB forward command, and a local Socket of the Android device is mapped to a TCP port of a PC; a program written by using a Go language is connected with an Android device through a TCP port, and an H.264 / AVC video stream acquired by the SCRCPY is received; the Go program segments the received video stream into NAL units; the Go program starts a WebSocket server at a PC (Personal Computer) end; the NAL unit data is pushed through the WebSocket; and decoding the received NAL unit by using a jmuyer library, and playing a video in a browser, thereby realizing non-intrusive and cross-platform real-time screen mirroring.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of video streaming media transmission, and in particular to a method and system for projecting a screen of a PC onto an Android device supporting a USB connection to a network in a WEB browser. Background Art

[0002] With the popularity of mobile devices and personal computers, users have an increasing demand for cross-device content sharing and interaction. Especially in scenarios such as business presentations, teaching and training, and game live broadcasts, users need to display and share the screen content of Android devices through the PC. However, the existing Android device screen projection technology on the market has many limitations and shortcomings, as shown below:

[0003] The traditional screenshot-based screen projection solution is based on screenshot technology, which captures multiple frames of pictures per second and transmits them to the PC for display. Although this method is simple to implement, it has obvious defects. First, the frequency of picture capture and transmission is limited by device performance, resulting in high picture delay and low frame rate. Secondly, frequent screenshot operations will occupy a lot of system resources, affecting the normal operation of the device, and the key frame optimization of video encoding technology cannot be used, further increasing performance loss.

[0004] The traditional video recording and screen projection solution is to encode the screen content into a video stream (such as H.264 / AVC or H.265 / HEVC) through video recording, and then transmit it to the PC for decoding and playback. This method alleviates the delay and frame rate problems to a certain extent, but due to the complexity of the recording and transmission process, there are many technical barriers to implementation, especially in terms of compatibility with USB and Ethernet connections. In addition, this method is easily affected by network bandwidth and stability during transmission, resulting in a poor experience.

[0005] In addition, existing Android device screen projection solutions mainly use Ethernet IP mode to capture and transmit the device screen image to the PC through screenshots or video encoding, but these solutions often have problems such as large performance loss, high resource usage, and high latency. It is not compatible with both USB and Ethernet connection methods, especially for devices with limited hardware resources. In addition, existing solutions have poor applicability in enterprise firewall environments and lack fine control over transmission efficiency.

[0006] To sum up, the existing Android device screen projection technology has many shortcomings in terms of connection methods, resource usage, performance optimization, firewall penetration capabilities and fine control. There is an urgent need for a video transmission solution that can support both USB and Ethernet connections, with efficient resource utilization and low latency, to meet users' screen projection needs in different scenarios. Summary of the invention

[0007] In order to solve the above problems, the present invention proposes a screen projection method and system for an Android device based on USB and network connection, which is compatible with USB and Ethernet connection modes, and adopts more efficient H.264 / AVC encoding for picture acquisition and transmission. The present invention is implemented by combining GO language with network protocols such as HTTP, TCP and WebSocket, uses ADB to establish a connection with the Android device, uses scrcpy to perform screen acquisition and encoding processing, and then transmits the encoded video data to the browser client through the WebSocket protocol, thereby realizing non-intrusive, cross-platform real-time screen mirroring.

[0008] The present invention is implemented by the following technical solutions:

[0009] In a first aspect, the present invention provides a method for projecting a screen of an Android device based on a USB connection to a network, the method comprising the following steps:

[0010] Step 1: Device connection and initialization:

[0011] Establish a communication connection between PC and Android device through ADB tool;

[0012] Step 2: Data collection and video encoding:

[0013] Use the ADB push command to transfer the SCRCPY tool to the specified directory of the Android device;

[0014] Use the ADB shell command to start SCRCPY on the Android device to capture and encode screen content;

[0015] Use the ADB forward command to forward the port and map the local socket of the Android device to the TCP port of the PC;

[0016] Step 3: Receiving and forwarding video streams:

[0017] A program written in Go language connects to the Android device through the TCP port and receives the H.264 / AVC video stream captured by SCRCPY;

[0018] The Go program splits the received video stream into NAL units;

[0019] Step 4: Real-time display on the browser:

[0020] The Go program starts a WebSocket server on the PC.

[0021] The Go program sends the segmented video data in NAL unit format to the browser via WebSocket.

[0022] The browser establishes a WebSocket connection through JavaScript and pushes NAL unit data;

[0023] The jmuxer library is used to decode the received NAL units and display them in real time through the HTML5 video tag.

[0024] As a further solution of the present invention, the PC and the Android device are also connected via USB or Ethernet. When connected via USB, the Android device turns on USB debugging mode. When connected via the network, the IP address of the Android device is configured in the same local area network.

[0025] As a further solution of the present invention, the PC transmits the SCRCPY acquisition software to the Android device via the TCP protocol.

[0026] As a further solution of the present invention, an ADB shell command is used to start the SCRCPY tool to perform screen content capture and H.264 / AVC video encoding.

[0027] As a further solution of the present invention, before data collection and video encoding, the ADB tool and the scrcpy.jar file are prepared on the PC where the Go program is located, and the Android device has USB debugging enabled and is connected to the PC via USB or Ethernet IP.

[0028] As a further solution of the present invention, when the SCRCPY tool is transferred to the designated directory of the Android device by the push command of ADB, the push command of ADB is used to transfer the scrcpy.jar file from the PC to the designated directory of the Android device.

[0029] As a further solution of the present invention, when SCRCPY is started on an Android device using an ADB shell command to capture and encode screen content, scrcpy.jar is run on the Android device using app_process through the ADB shell command.

[0030] As a further solution of the present invention, when the jmuxer library is used to decode the received NAL unit, jmuxer is responsible for decoding the H.264 encoded data into playable video frames and playing them through the HTML5 video element. The Go program continuously receives data from the ADB connection, processes the NAL unit, and sends it through WebSocket. The browser side continuously receives the data and decodes and plays it, thereby realizing real-time screen mirroring.

[0031] As a further solution of the present invention, the JavaScript code on the browser side receives NAL unit data from the PC side through the WebSocket protocol, and uses the jmuxer library to perform H.264 video decoding.

[0032] In a second aspect, the present invention also includes an Android device screen projection system based on USB and network connection, the system comprising:

[0033] Android device, used to establish communication connection with PC through ADB tool, and capture and encode screen content;

[0034] PC, used to establish a communication connection with the Android device through the ADB tool, transfer the SCRCPY tool to the Android device, start the SCRCPY tool to capture and encode the screen content, forward the port to the TCP port, receive and process the video stream through the Go program;

[0035] Go program, used to connect to the Android device through the TCP port, receive the H.264 / AVC video stream collected by SCRCPY, split it into NAL units, start the WebSocket server, and send the segmented video data in the form of NAL units to the browser through WebSocket;

[0036] The browser side is used to establish a WebSocket connection through JavaScript, push NAL unit data, use the jmuxer library to decode the received NAL units, and display them in real time through the HTML5 video tag.

[0037] The present invention also includes a computer device, comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the Android device screen projection method based on USB and network connection.

[0038] The present invention also includes a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the Android device screen projection method based on USB and network connection.

[0039] Compared with the prior art, the Android device screen projection method and system based on USB and network connection provided by the present invention has the following beneficial effects:

[0040] 1. Realize efficient real-time screen mirroring: The present invention ensures high-quality video transmission by capturing and encoding the screen content of the Android device into a video stream in H.264 / AVC format. At the same time, through ADB port forwarding and TCP connection, the transmission delay is effectively reduced, and the real-time screen mirroring effect is achieved.

[0041] 2. Flexible connection mode: The present invention supports connecting Android devices and PCs via USB and Ethernet. Users can choose the most appropriate connection mode according to actual conditions, providing higher flexibility and convenience.

[0042] 3. Easy to deploy and use, with cross-platform support: ADB tools and SCRCPY software are used to capture and encode screen content, without the need for additional hardware or complex software configuration, and ordinary users can easily operate it. The present invention also transmits the video stream to the browser through the WebSocket protocol, and uses the jmuxer library for video decoding and playback, so that the method can be run on any browser that supports HTML5 and JavaScript, achieving cross-platform support.

[0043] 4. High compatibility and scalability: The present invention combines the ADB tool and the SCRCPY software to make the method applicable to most Android devices, and the middle-layer program written in Go language has good scalability and maintainability, which is convenient for later function expansion and performance optimization.

[0044] 5. Stable performance and low resource consumption, improved security and privacy protection: SCRCPY in the present invention is a lightweight open source tool. Its efficient encoding and transmission mechanism ensures stable performance, while consuming less device resources, and is suitable for Android devices with various hardware configurations. When the present invention is connected via USB, data transmission is performed locally, which is more secure; when connected via Ethernet, with the IP address configuration in the local area network, the security and privacy protection of data transmission can also be ensured.

[0045] 6. Open source and community support: The SCRCPY and ADB tools in the present invention are both open source software with extensive community support. Users can customize and redevelop them according to their own needs to obtain functions and performance that better meet their needs.

[0046] To sum up, the present invention realizes an efficient, flexible, easy-to-use, cross-platform, highly compatible and secure Android device screen projection method and system through reasonable technical solution design, which has significant practical value and promotion prospects.

[0047] These and other aspects of the present invention will be more clearly understood in the following description of the embodiments. It should be understood that the above general description and the following detailed description are only exemplary and explanatory and cannot limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the following briefly introduces the drawings required for use in the exemplary embodiments or related technical descriptions. The drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation to the present invention. In the drawings:

[0049] Figure 1 This is a flowchart of a method for projecting screen on an Android device based on USB and network connection according to an embodiment of the present invention. DETAILED DESCRIPTION

[0050] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0051] In some of the processes described in the specification and claims of the present invention and the above-mentioned figures, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel. The serial numbers of the operations, such as 101, 102, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.

[0052] The following will be combined with the drawings in the exemplary embodiments of the present invention to clearly and completely describe the technical solutions in the exemplary embodiments of the present invention. Obviously, the exemplary embodiments described are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0053] Since most Android devices on the market use Ethernet IP mode for screen projection, for example, the screen is captured as pictures captured every second and transmitted via Ethernet, the delay and frame rate of the picture are limited by the number of times the picture is captured per second, the Android device resources are high, the performance loss is large, and it is impossible to use key frame and other technologies for optimization. There are also ways to capture the picture by recording videos, such as using H.264 / AVC, H.265 / HEVC and other video encodings for transmission, but due to restrictions and transmission methods, the same solution cannot be compatible with USB connection or Ethernet. The present invention provides a screen projection method and system for an Android device based on USB and network connection. The method adopts H.264 / AVC video encoding which is well compatible with current hardware devices, and performs screen capture in a low-resource occupation manner. The method can efficiently capture device display screens, record silently in the background with low resource occupation and consumption, connect to the Android device non-invasively, and there is no need to actively install any software on the device. The software will be applied to the Android device using an active transmission method. The present invention adopts GO language in conjunction with HTTP, TCP, Websocket and other network protocols for implementation, uses SCRCPY to perform screen capture and encoding and other operations on the Android device, and uses ADB as the connection between the Android device and devices such as PC.

[0054] The technical solution of the present invention is further described below in conjunction with specific embodiments:

[0055] See also Figure 1 As shown, Figure 1 A flowchart of a method for projecting screen of an Android device based on a USB connection to a network provided by the present invention. A method for projecting screen of an Android device based on a USB connection to a network provided in one embodiment of the present invention comprises the following steps:

[0056] Step S10: Device connection and initialization:

[0057] Establish a communication connection between PC and Android device through ADB tool;

[0058] Step S20: Data collection and video encoding:

[0059] Use the ADB push command to transfer the SCRCPY tool to the specified directory of the Android device;

[0060] Use the ADB shell command to start SCRCPY on the Android device to capture and encode screen content;

[0061] Use the ADB forward command to forward the port and map the local socket of the Android device to the TCP port of the PC;

[0062] Step S30: Receiving and forwarding video stream:

[0063] A program written in Go language connects to the Android device through the TCP port and receives the H.264 / AVC video stream captured by SCRCPY;

[0064] The Go program splits the received video stream into NAL units;

[0065] Step S40: Real-time display on the browser side:

[0066] The Go program starts a WebSocket server on the PC.

[0067] The Go program sends the segmented video data in NAL unit format to the browser via WebSocket.

[0068] The browser establishes a WebSocket connection through JavaScript and pushes NAL unit data;

[0069] The jmuxer library is used to decode the received NAL units and display them in real time through the HTML5 video tag.

[0070] In this embodiment, the PC and the Android device are also connected via USB or Ethernet. When connected via USB, the Android device turns on USB debugging mode. When connected via the network, the IP address of the Android device is configured in the same local area network. The PC transmits the SCRCPY acquisition software to the Android device via the TCP protocol.

[0071] In this embodiment, the SCRCPY tool is started using the ADB shell command to capture screen content and encode H.264 / AVC video. Before data collection and video encoding, the ADB tool and the scrcpy.jar file are prepared on the PC where the Go program is located. The Android device has USB debugging enabled and is connected to the PC via USB or Ethernet IP.

[0072] In this embodiment, when the SCRCPY tool is transferred to the specified directory of the Android device through the ADB push command, the scrcpy.jar file is transferred from the PC to the specified directory of the Android device using the ADB push command. When the SCRCPY is started on the Android device for screen content capture and encoding using the ADB shell command, the scrcpy.jar is run on the Android device using app_process through the ADB shell command.

[0073] In this embodiment, when the jmuxer library is used to decode the received NAL unit, jmuxer is responsible for decoding the H.264 encoded data into playable video frames and playing them through the HTML5 video element. The Go program continues to receive data from the ADB connection, processes the NAL unit, and sends it through WebSocket. The browser continues to receive data and decodes and plays it, realizing real-time screen mirroring.

[0074] The JavaScript code on the browser side receives NAL unit data from the PC side through the WebSocket protocol, and uses the jmuxer library to perform H.264 video decoding.

[0075] In the method for projecting a screen on an Android device based on USB and a network connection according to an embodiment of the present invention, the workflow of using an AVC video stream on the PC side is as follows:

[0076] 1. Device connection and initialization:

[0077] Connection method selection: Prepare the ADB tool and scrcpy.jar file on the PC, make sure that USB debugging is enabled on the Android device, and connect the Android device to the PC via USB or Ethernet IP. Users can choose to connect the Android device to the PC via USB or Ethernet (IP). If connected via USB, make sure that the device has the "USB debugging" mode enabled; if connected via the network, the Android device's IP address must be configured in the same LAN.

[0078] ADB communication establishment: Use the ADB (Android Debug Bridge) tool to establish a connection between the PC and the Android device. As a standard interface, ADB supports connections via USB or Ethernet and provides the ability to interact with Android devices.

[0079] 2.ADB connection:

[0080] The Go program uses the ADB library to establish a connection with the Android device.

[0081] Initializes the ADB client, searches for connected devices, and establishes a session with a specific device.

[0082] 3. Data collection and video encoding:

[0083] Transfer and start the SCRCPY tool: Use the ADB push command to transfer the scrcpy.jar tool to the Android device (transfer to the / data / local / tmp / directory).

[0084] 4. Start the service:

[0085] Use the ADB shell command to start the SCRCPY tool, capture the current screen content of the device through the screen capture function of the Android device, and perform video encoding. SCRCPY supports efficient H.264 / AVC encoding to ensure smooth video transmission with low resource usage.

[0086] 5. Port forwarding:

[0087] Use the ADB "forward" command to map the local socket on the Android device to a TCP port on the PC.

[0088] Use ADB's port forwarding function to map the local socket of the Android device to the TCP port of the PC. In this way, the video stream of the Android device can be transmitted to the PC through this port to form a data channel, which creates a channel that allows the PC to communicate with the scrcpy service running on the device through this port.

[0089] 6. Establish connection:

[0090] The Go program connects to the mapped TCP port. The program developed in the Go language on the PC establishes a connection with the mapped TCP port and starts receiving the H.264 / AVC video data stream encoded by SCRCPY.

[0091] Once the connection is established, the scrcpy server starts sending the encoded video data.

[0092] 7. Data reception:

[0093] The Go program reads raw H.264 / AVC encoded video data from a TCP connection to form a continuous video stream.

[0094] 8.NAL unit processing:

[0095] The received video data needs to be segmented into NAL (Network Abstraction Layer) units. Specifically, the Go program is responsible for segmenting the received H.264 video stream into NAL units (Network Abstraction Layer units), which are the basic units in H.264 encoding. By identifying specific start codes, the Go program can correctly segment and process the video stream; NAL units are the basic units of H.264 encoding. The Go program identifies the boundaries of NAL units by looking for specific start codes.

[0096] 9. WebSocket Service:

[0097] The Go program establishes a WebSocket server, allowing browser clients to connect to the Go program via the WebSocket protocol.

[0098] 10. Data forwarding:

[0099] The segmented NAL units are sent to the browser client via the WebSocket connection.

[0100] Each NAL unit is sent as a binary message.

[0101] 11. Browser receives:

[0102] The browser uses JavaScript to establish a WebSocket connection and receive NAL unit data from the server.

[0103] 12. Video decoding and playback:

[0104] The browser uses the jmuxer library to process the received NAL units.

[0105] jmuxer is responsible for decoding H.264-encoded data into playable video frames and playing them through the HTML5 video element.

[0106] 13.Continuous operation:

[0107] The Go program continues to receive data from the ADB connection, processes the NAL units, and sends them over WebSocket.

[0108] The browser side continuously receives data and decodes and plays it, realizing real-time screen mirroring.

[0109] To sum up, the embodiment of the present invention provides an Android device screen projection method based on USB and network connection, which can efficiently and non-invasively project the Android device screen to the PC browser, and realize real-time screen mirroring in multiple platforms and multiple scenarios.

[0110] It should be understood that, although described in a certain order, these steps are not necessarily performed in sequence in the above order. Unless there is clear explanation in this article, the execution of these steps does not have strict order restriction, and these steps can be performed in other orders. Moreover, a part of the steps of the present embodiment may include a plurality of steps or a plurality of stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a part of the steps or stages in other steps or other steps.

[0111] In one embodiment, the present invention provides an Android device screen projection system based on USB and network connection, which is used to execute the above-mentioned Android device screen projection method based on USB and network connection, and the system includes:

[0112] Android device, used to establish communication connection with PC through ADB tool, and capture and encode screen content;

[0113] PC, used to establish a communication connection with the Android device through the ADB tool, transfer the SCRCPY tool to the Android device, start the SCRCPY tool to capture and encode the screen content, forward the port to the TCP port, receive and process the video stream through the Go program;

[0114] Go program, used to connect to the Android device through the TCP port, receive the H.264 / AVC video stream collected by SCRCPY, split it into NAL units, start the WebSocket server, and send the segmented video data in the form of NAL units to the browser through WebSocket;

[0115] The browser side is used to establish a WebSocket connection through JavaScript, push NAL unit data, use the jmuxer library to decode the received NAL units, and display them in real time through the HTML5 video tag.

[0116] In this embodiment, the Android device screen projection system based on USB and network connection adopts the steps of the aforementioned Android device screen projection method based on USB and network connection during execution. Therefore, the operation process of the Android device screen projection system based on USB and network connection will not be introduced in detail in this embodiment.

[0117] In summary, the Android device screen projection method and system based on USB and network connection of the present invention is an efficient, real-time, cross-platform Android device screen projection solution, which solves the problems of high resource occupation, large delay, single connection method and poor firewall penetration in the prior art, and can meet the user's screen projection needs in various application scenarios. The present invention solves the problems of high resource occupation and large delay in the existing Android device screen projection through non-invasive design and efficient video transmission method, and can realize real-time, high-definition screen mirroring through a browser in a multi-platform environment, and is suitable for various PCs and network environments.

[0118] In one embodiment, a computer device is also provided in an embodiment of the present invention, comprising at least one processor and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor performs the steps of the method for projecting the screen of an Android device based on a USB connection to a network.

[0119] In one embodiment, the present invention also provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the steps of the Android device screen projection method based on USB and network connection.

[0120] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be realized by instructing the relevant hardware through a computer program represented by computer instructions, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory.

[0121] Non-volatile memory may include read-only memory, magnetic tape, floppy disk, flash memory or optical storage, etc. Volatile memory may include random access memory or external cache memory. As an illustration and not limitation, RAM may be in various forms, such as static random access memory or dynamic random access memory, etc.

[0122] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for projecting screen of an Android device based on USB and network connection, characterized in that: The method comprises the following steps: Step 1: Device connection and initialization: Establish a communication connection between PC and Android device through ADB tool; Step 2: Data collection and video encoding: Use the ADB push command to transfer the SCRCPY tool to the specified directory of the Android device; Use the ADB shell command to start SCRCPY on the Android device to capture and encode screen content; Use the ADB forward command to forward the port and map the local socket of the Android device to the TCP port of the PC; Step 3: Receiving and forwarding video streams: A program written in Go language connects to the Android device through the TCP port and receives the H.264 / AVC video stream captured by SCRCPY; The Go program splits the received video stream into NAL units; Step 4: Real-time display on the browser: The Go program starts a WebSocket server on the PC. The Go program sends the segmented NAL unit-formatted video data to the browser via WebSocket. The browser establishes a WebSocket connection through JavaScript and pushes NAL unit data; The jmuxer library is used to decode the received NAL units and display them in real time through the HTML5 video tag.

2. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 1, characterized in that: The PC and Android device are also connected via USB or Ethernet. When connected via USB, the Android device turns on USB debugging mode. When connected via the network, the IP address of the Android device is configured in the same local area network.

3. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 2, characterized in that: The PC transmits the SCRCPY acquisition software to the Android device via the TCP protocol.

4. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 1, characterized in that: Use the ADBshell command to start the SCRCPY tool for screen content capture and H.264 / AVC video encoding.

5. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 4, characterized in that: Before data collection and video encoding, the ADB tool and scrcpy.jar file are also prepared on the PC where the Go program is located. The Android device has USB debugging enabled and is connected to the PC via USB or Ethernet IP.

6. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 5, characterized in that: When transferring the SCRCPY tool to the specified directory of the Android device through the ADB push command, use the ADB push command to transfer the scrcpy.jar file from the PC to the specified directory of the Android device.

7. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 1, characterized in that: When using the ADB shell command to start SCRCPY on an Android device for screen content capture and encoding, use app_process to run scrcpy.jar on the Android device through the ADB shell command.

8. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 7, characterized in that: When using the jmuxer library to decode the received NAL units, jmuxer is responsible for decoding the H.264-encoded data into playable video frames and playing them through the HTML5 video element. The Go program continues to receive data from the ADB connection, processes the NAL units, and sends them through WebSocket. The browser continues to receive data and decodes and plays it, realizing real-time screen mirroring.

9. The method for projecting screen of an Android device based on USB and network connection as claimed in claim 8, characterized in that: The JavaScript code on the browser side receives NAL unit data from the PC side through the WebSocket protocol, and uses the jmuxer library to perform H.264 video decoding.

10. An Android device screen projection system based on USB and network connection, characterized in that: Used to execute the Android device screen projection method based on USB and network connection as described in any one of claims 1-9, the Android device screen projection system based on USB and network connection includes: Android device, used to establish communication connection with PC through ADB tool, and capture and encode screen content; PC, used to establish a communication connection with the Android device through the ADB tool, transfer the SCRCPY tool to the Android device, start the SCRCPY tool to capture and encode the screen content, forward the port to the TCP port, receive and process the video stream through the Go program; Go program, used to connect to the Android device through the TCP port, receive the H.264 / AVC video stream collected by SCRCPY, split it into NAL units, start the WebSocket server, and send the segmented video data in the form of NAL units to the browser through WebSocket; The browser side is used to establish a WebSocket connection through JavaScript, push NAL unit data, use the jmuxer library to decode the received NAL units, and display them in real time through the HTML5 video tag.

Citation Information

Cited By

  • Data communication method and device, equipment, storage medium and program product

    CN122179487A