Video playing method and device, electronic equipment and storage medium

By dividing web pages and decoding WebAssembly technology on the browser side, combined with FIFO queue and frame loss strategy, the problem of multi-channel video playback delay in the browser environment is solved, and smooth playback and high-quality decoding of multi-frame videos are achieved.

CN118632073APending Publication Date: 2024-09-10CHINA TELECOM CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410693436.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

It is difficult to achieve simultaneous playback of multiple videos in a browser environment with existing technology, resulting in problems of delay and excessive computing resources.

Method used

By dividing the pre-created web display page, N-channel video streams are obtained and cached in the FIFO queue, and the video stream is decoded based on the FFmpeg decoding library compiled with WebAssembly technology, and the frame loss strategy is combined to optimize data loading to achieve multi-grid video Smooth playback within a canvas.

Benefits of technology

It realizes the smooth playback of multi-channel videos on the browser side, reduces the streaming delay on the playback side, improves the user experience, and supports the decoding of high-quality encoding formats such as H.265.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118632073A
    Figure CN118632073A
Patent Text Reader

Abstract

The invention provides a video playing method and device, electronic equipment and a storage medium. The method comprises the steps that a web display page is divided to obtain N video display areas, and N is a positive integer larger than 1; caching the N paths of video streams in FIFO queues respectively corresponding to the N paths of video streams; a Wasm file is called based on the JS file to carry out video decoding processing on the N paths of video streams read from the FIFO queue, N decoded video data are obtained, the Wasm file is a file obtained by compiling a decoding library source code of FFmpeg based on the WebAssembly technology, and the JS file is a file which is obtained by compiling based on the calling requirement of the WebAssembly technology and used for calling the Wasm file; and respectively displaying each piece of decoded video data in the N pieces of decoded video data in the corresponding video display area in the corresponding N video display areas.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of video data processing, and in particular to a video playback method, device, electronic device and storage medium. Background Art

[0002] With the rapid development of the economy, the video surveillance market is also developing rapidly. The video surveillance industry will gradually mature, and the industrial system, value chain, product types and application scenarios will be further improved. From the perspective of market segmentation, it is expected that in 2023, the global government agencies, public institutions and commercial fields will account for more than 86% of the overall market, and the demand for video surveillance in the industry field will still dominate the overall demand.

[0003] In order to meet the overall development needs of the video surveillance market, there are currently several major development directions in the video surveillance field:

[0004] 1. Lightweight: B / S-based Web clients, i.e. browser-based clients, are a more attractive option. They are not restricted by a specific operating system and can run on a variety of operating systems, thus adapting to a variety of usage scenarios. In addition, Web clients are usually easier to update and maintain. Users do not need to install additional software, but can monitor and manage the security system by simply accessing it through a browser.

[0005] 2. High Definition: The H.265 encoding format is widely used in the video field due to its efficient compression capabilities and higher quality video transmission, especially for high-resolution and high-frame-rate video content. In the security industry, the popularity and application of H.265 has also brought new requirements and developments.

[0006] 3. Localization: With the promotion and popularization of domestic operating systems, the traditional security industry is facing some changes and adjustments. Traditional security systems based on PC (Personal Computer) clients need to adapt to the new operating system environment or adopt more flexible methods to meet user needs. The popularity of domestic operating systems and browsers will prompt the security industry to adopt more flexible and adaptable solutions.

[0007] 4. Multi-grid: Based on the video surveillance needs of the comprehensive management center of the political and legal public security industry, it is usually combined with emergency command. By pulling multiple videos at the same time and playing them on the large screen in a rotation, the comprehensive situation of social security can be grasped in real time.

[0008] For multi-grid playback, that is, a browser plays multiple videos on a single page (i.e. multi-grid playback, currently widely used in video surveillance centers, to achieve simultaneous viewing and patrol of multiple videos on one page), JavaScript or HTML5 is usually used. <video>and <audio>Tags are used to decode and play videos, but there are problems such as format compatibility, performance, and loading, which makes multi-grid playback difficult to achieve. The need to play multiple videos simultaneously often requires opening multiple browser windows, but this puts higher demands on computing resources, especially in the browser environment, because the browser itself is limited and it is difficult to process large amounts of data at the same time, resulting in greater delays. Summary of the invention

[0009] The technical problem to be solved by the embodiments of the present application is to provide a video playback method, device, electronic device and storage medium to achieve smooth playback of multiple videos on a single page.

[0010] In a first aspect, an embodiment of the present application provides a video playback method, the method comprising:

[0011] Dividing a pre-created web display page to obtain N video display areas on the web display page, where N is a positive integer greater than 1;

[0012] Cache the acquired N video streams in FIFO queues corresponding to the N video streams respectively;

[0013] Based on the pre-compiled JS file, the pre-compiled wasm file is called to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data, wherein the wasm file is a file obtained by compiling the decoding library source code of FFmpeg based on the WebAssembly technology, and the JS file is a file for calling the wasm file compiled based on the calling requirements of the WebAssembly technology, and the wasm file and the JS file are pre-loaded in the web display page;

[0014] Each decoded video data of the N decoded video data is displayed in a corresponding video display area of ​​the corresponding N video display areas.

[0015] Optionally, caching the acquired N video streams in FIFO queues respectively corresponding to the N video streams includes:

[0016] Use the websocket stream address to pull the N video streams;

[0017] Based on a preset frame loss strategy, determining whether the N video streams meet a caching condition;

[0018] When it is determined that the N video streams meet the caching condition, caching the N video streams in the FIFO queues respectively corresponding to the N video streams;

[0019] When it is determined that the N video streams do not meet the buffering condition, designated non-key frames in the N video streams are discarded.

[0020] Optionally, the determining whether the N video streams meet a caching condition based on a preset frame loss strategy includes:

[0021] In the case where the frame loss strategy is an available space strategy, determining whether the N video streams meet a caching condition based on a size relationship between the remaining storage space of the FIFO queue and the occupied storage space of the N video streams;

[0022] The step of discarding designated non-key frames in the N video streams when it is determined that the N video streams do not meet the cache condition includes:

[0023] When the remaining storage space is smaller than the storage space occupied by the N video streams, the designated non-key frames in the N video streams are discarded.

[0024] Optionally, the determining whether the N video streams meet a caching condition based on a preset frame loss strategy includes:

[0025] In the case where the frame loss strategy is a time strategy, determining whether the N video streams meet the caching condition based on the single frame decoding time, the single frame format conversion time and the single frame playback time;

[0026] The step of discarding designated non-key frames in the N video streams when it is determined that the N video streams do not meet the cache condition includes:

[0027] When the sum of the single frame decoding time and the single frame format conversion time is greater than the single frame playback time, the designated non-key frames in the N video streams are discarded based on the difference between the sum and the single frame playback time.

[0028] Optionally, discarding designated non-key frames in the N video streams based on the difference between the sum and the single frame playback time includes:

[0029] If the difference is less than or equal to the first duration, discard the P frame in the N video streams;

[0030] When the difference is greater than the first duration and less than or equal to the second duration, discard the B frames in the N video streams;

[0031] When the difference is greater than the second duration, the I frame in the N video streams is discarded.

[0032] Optionally, displaying each decoded video data of the N decoded video data in a corresponding video display area of ​​the corresponding N video display areas includes:

[0033] Calling the pre-loaded SDL2 file corresponding to each of the video display areas to read the corresponding decoded video data;

[0034] Based on the SDL2 file, the corresponding decoded video data is rendered and displayed in the corresponding video display area.

[0035] Optionally, dividing the pre-created web display page to obtain N video display areas on the web display page includes:

[0036] Obtaining display positions and display sizes of N pre-configured video display areas on the web display page;

[0037] N video display areas are created on the web display page based on the display position and the display size.

[0038] In a second aspect, an embodiment of the present application provides a video playback device, the device comprising:

[0039] A video display area acquisition module, used for dividing a pre-created web display page to obtain N video display areas on the web display page, where N is a positive integer greater than 1;

[0040] A video stream caching module, used for caching the acquired N video streams in FIFO queues corresponding to the N video streams respectively;

[0041] A decoding video data acquisition module is used to call a pre-compiled wasm file based on a pre-compiled JS file to perform video decoding processing on N video streams read from the FIFO queue to obtain N decoded video data, wherein the wasm file is a file compiled based on the WebAssembly technology to compile the decoding library source code of FFmpeg, and the JS file is a file compiled based on the calling requirements of the WebAssembly technology to call the wasm file, and the wasm file and the JS file are pre-loaded in the web display page;

[0042] The multi-channel video display module is used to display each decoded video data of the N decoded video data in a corresponding video display area of ​​the corresponding N video display areas.

[0043] Optionally, the video stream caching module includes:

[0044] A video stream pulling unit, used to pull the N video streams using a websocket stream address;

[0045] A cache condition determination unit, configured to determine whether the N video streams meet a cache condition based on a preset frame loss strategy;

[0046] A video stream caching unit, configured to cache the N video streams in the FIFO queues respectively corresponding to the N video streams when it is determined that the N video streams meet a caching condition;

[0047] The non-key frame discarding unit is used to discard the designated non-key frames in the N video streams when it is determined that the N video streams do not meet the buffering condition.

[0048] Optionally, the cache condition determination unit includes:

[0049] A first condition determination subunit is used to determine whether the N video streams meet the caching condition based on the size relationship between the remaining storage space of the FIFO queue and the occupied storage space of the N video streams when the frame loss strategy is the available space strategy;

[0050] The non-key frame discarding unit comprises:

[0051] The non-key frame discarding subunit is used to discard the specified non-key frames in the N video streams when the remaining storage space is smaller than the storage space occupied by the N video streams.

[0052] Optionally, the cache condition determination unit includes:

[0053] A second condition determination subunit is used to determine whether the N video streams meet the caching condition based on the single frame decoding time, the single frame format conversion time and the single frame playback time when the frame loss strategy is a time strategy;

[0054] The non-key frame discarding unit comprises:

[0055] The designated frame discarding subunit is used to discard designated non-key frames in the N video streams based on the difference between the sum and the single frame playback time when the sum of the single frame decoding time and the single frame format conversion time is greater than the single frame playback time.

[0056] Optionally, the designated frame discarding subunit includes:

[0057] A P frame discarding subunit, configured to discard the P frames in the N video streams if the difference is less than or equal to the first duration;

[0058] A B frame discarding subunit, configured to discard the B frames in the N video streams when the difference is greater than the first duration and less than or equal to a second duration;

[0059] The I frame discarding subunit is used to discard the I frame in the N video streams when the difference is greater than the second duration.

[0060] Optionally, the multi-channel video display module includes:

[0061] A decoded data reading unit, used for calling a pre-loaded SDL2 file corresponding to each of the video display areas to read corresponding decoded video data;

[0062] The multi-channel video display unit is used to render and display the corresponding decoded video data in the corresponding video display area based on the SDL2 file.

[0063] Optionally, the video display area acquisition module includes:

[0064] A display information acquisition unit, used to acquire the display positions and display sizes of N pre-configured video display areas on the web display page;

[0065] A display area creating unit is configured to create N video display areas on the web display page based on the display position and the display size.

[0066] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0067] A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned video playback methods when executing the program.

[0068] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute any of the video playback methods described above.

[0069] Compared with the prior art, the embodiments of the present application have the following advantages:

[0070] In an embodiment of the present application, by dividing the pre-created web display page, N video display areas on the web display page are obtained, where N is a positive integer greater than 1. The obtained N video streams are cached in the FIFO queues corresponding to the N video streams. Based on the pre-compiled JS file, the pre-compiled wasm file is called to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data. The wasm file is a file compiled based on the WebAssembly technology to compile the source code of the decoding library of FFmpeg. The JS file is a file for calling the wasm file compiled based on the calling requirements of the WebAssembly technology. The wasm file and the JS file are pre-loaded in the web display page. Each decoded video data in the N decoded video data is displayed in the corresponding video display area in the corresponding N video display areas. The embodiment of the present application realizes the application scenario of H.265 playback based on WebAssembly technology, realizes the playback and control of multi-grid videos in a canvas, and realizes the purpose of smoothly playing multiple video streams on a web page client at the same time.

[0071] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] Figure 1 A flowchart of a video playback method provided in an embodiment of the present application;

[0073] Figure 2 A schematic diagram of a system architecture provided for an embodiment of the present application;

[0074] Figure 3 A schematic diagram of the structure of a web page information extraction device provided in an embodiment of the present application;

[0075] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0076] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0077] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms of "a", "said", and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0078] Reference Figure 1 , shows a flow chart of the steps of a video playback method provided by an embodiment of the present application, such as Figure 1 As shown, the video playing method may include: step 101, step 102, step 103 and step 104.

[0079] Step 101: Divide a pre-created web display page to obtain N video display areas on the web display page, where N is a positive integer greater than 1.

[0080] In this embodiment, when multiple video streams are displayed simultaneously in a single web display page, the pre-created web display page may be divided to obtain N video display areas on the web display page, where N is a positive integer greater than 1. In a specific implementation, the display positions and display sizes of the pre-configured N video display areas on the web display page may be obtained, and the N video display areas may be created on the web display page based on the display positions and display sizes.

[0081] It can be understood that each of the N video display areas created in the web display page can display one channel of video stream data, and 4 or 9 video display areas can be created in a single web page. This embodiment does not limit the number of video display areas in a single web display page.

[0082] After the pre-created web display page is divided to obtain N video display areas on the web display page, step 102 is performed.

[0083] Step 102: Cache the acquired N video streams in FIFO queues corresponding to the N video streams respectively.

[0084] FIFO (First-In, First-Out) is a common data structure in computer science, which stands for "First-In, First-Out". It is a queue for data storage and retrieval, and the data items that are put into the queue first will be taken out first.

[0085] After the pre-created web display page is divided to obtain N video display areas on the web display page, N video streams can be obtained and cached in FIFO queues corresponding to the N video streams. That is, the number of FIFO queues is N, and each FIFO queue corresponds to one video stream. For example, when N=4, the four FIFO queues are: FIFO1, FIFO2, FIFO3, FIFO4, and the four video streams are: video stream 1, video stream 2, video stream 3, video stream 4, wherein video stream 1 can be cached in FIFO1, video stream 2 can be cached in FIFO1, video stream 3 can be cached in FIFO3, video stream 4 can be cached in FIFO4, etc.

[0086] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.

[0087] In a specific implementation of the present application, the websocket stream address can be called to pull N video streams, and based on the pre-set frame loss strategy, it is determined whether the N video streams meet the caching conditions. If it is determined that the N video streams meet the caching conditions, the N video streams can be cached in the FIFO queues corresponding to the N video streams. If it is determined that the N video streams do not meet the caching conditions, the specified non-key frames in the N video streams are discarded.

[0088] Among them, webSocket is a protocol for full-duplex communication on a single TCP (Transmission Control Protocol) connection. It makes data exchange between the client and the server easier and allows the server to actively push data to the client.

[0089] In this example, the frame loss strategy may include two types, one is an available space strategy, and the other is a time strategy. Specifically:

[0090] 1. When the frame dropping strategy is the available space strategy, it is possible to determine whether the N-channel video streams meet the caching conditions based on the size relationship between the remaining storage space of the FIFO queue and the occupied storage space of the N-channel video streams. If the remaining storage space is less than the occupied storage space of the N-channel video streams, the specified non-key frames in the N-channel video streams are discarded. In this example, the specified non-key frames can be some non-key frames in the video stream. The selection of the specified non-key frames can be selected according to business needs, and this embodiment does not limit this.

[0091] 2. When the frame loss strategy is a time strategy, determine whether the N-channel video streams meet the caching conditions based on the single-frame decoding time, the single-frame format conversion time and the single-frame playback time. When the sum of the single-frame decoding time and the single-frame format conversion time is greater than the single-frame playback time, the specified frames in the N-channel video streams are discarded based on the difference between the sum and the single-frame playback time. Specifically, when the difference is less than or equal to the first duration, the P frames in the N-channel video streams are discarded. When the difference is greater than the first duration and less than or equal to the second duration, the B frames in the N-channel video streams are discarded. When the difference is greater than the second duration, the I frames in the N-channel video streams are discarded.

[0092] The embodiment of the present application implements a decoding frame loss strategy during the playback process. The strategy matches the decoding time and the size of the cached data to discard some non-key frames to ensure smooth playback of audio and video with less impact on user experience, solving the problem of stuttering caused by insufficient resources. By optimizing data loading and decoding strategies, the present invention can reduce the streaming delay at the playback end, improve the streaming efficiency, and better achieve low-latency playback, thereby significantly improving the user's playback experience.

[0093] After the acquired N video streams are cached in the FIFO queues corresponding to the N video streams respectively, step 103 is executed.

[0094] Step 103: Based on the pre-compiled JS file, the pre-compiled wasm file is called to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data, wherein the wasm file is a file compiled by compiling the decoding library source code of FFmpeg based on the WebAssembly technology, and the JS file is a file for calling the wasm file compiled based on the calling requirements of the WebAssembly technology, and the wasm file and the JS file are pre-loaded in the web display page.

[0095] WebAssembly (often abbreviated as Wasm): is a virtual instruction set architecture (virtual ISA), the overall architecture includes the core ISA definition, binary encoding, definition and execution of program semantics, and application programming interfaces (WebAssembly API) for different embedded environments (such as the Web). Its initial goal is to compile programs written in languages ​​such as C / C++ and run them better on the Web platform while ensuring security and running speed close to that of native applications.

[0096] JavaScript ("JS" for short) is a lightweight, interpreted or just-in-time compiled programming language with function-first behavior. Although it is famous as a scripting language for developing web pages, it is also used in many non-browser environments. JavaScript is a prototype-based, multi-paradigm dynamic scripting language that supports object-oriented, imperative, declarative, and functional programming paradigms.

[0097] FFmpeg (Fast Forward MPEG): is an open source multimedia framework and tool set for processing audio, video, multimedia streams and related data. It is a cross-platform project that provides a series of libraries and command-line tools that allow developers to process, transcode, decode, encode, stream and edit multimedia content.

[0098] JS files are pre-compiled files used to call wasm files.

[0099] The wasm file is a file compiled from the FFmpeg decoding library source code based on WebAssembly technology.

[0100] The compilation process of JS files and wasm files can be described in detail in combination with the following steps.

[0101] 1. Source code preparation: Use C / C++ to write the corresponding functional modules, mainly including decryption functions, audio decoder, video decoder, SDL renderer, etc., which are used to call the wasm source code. The JS file can be obtained by compiling and packaging according to the calling requirements of WebAssembly technology.

[0102] 2. Preparation of FFmpeg library files that support H.265 decoding: You need to use the Emscripten tool to compile FFmpeg's H.265 decoding library into a library that can be used by WebAssembly. Among them, Emscripten is a commonly used tool for compiling C / C++ code into Wasm. It provides a complete set of tools, including compilers, linkers, and libraries, to simplify the process of converting existing code to Wasm.

[0103] 3. Compilation tool: Use the wasm compiler Emscripten to compile the source code into Wasm bytecode, that is, compile the H.265 decoding library into a library that can be used by WebAssembly.

[0104] 4. Compile to wasm: Run the compile command to compile the source code into a wasm module (i.e., the wasm file in this embodiment). Example command: emcc source.co output.wasm, etc.

[0105] 5. Output Wasm module: After compilation, a .wasm file will be obtained, which is the binary representation of the Wasm module. It can be called through a JS file.

[0106] After completing the above compilation process, when playing a multi-grid video in a web display page, the JS file can be called to load the wasm file into the web display page.

[0107] After caching the acquired N video streams in the FIFO queues corresponding to the N video streams respectively, the pre-compiled wasm file can be called based on the pre-compiled JS file to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data.

[0108] After obtaining N decoded video data, step 104 is executed.

[0109] Step 104: Display each of the N decoded video data in a corresponding video display area among the corresponding N video display areas.

[0110] After obtaining N decoded video data, each of the N decoded video data can be displayed in a corresponding video display area in the corresponding N video display areas. Specifically, the SDL2 file corresponding to each pre-loaded video display area can be called to read the corresponding decoded video data, and the corresponding decoded video data can be rendered and displayed in the corresponding video display area based on the SDL2 file. Among them, SDL2 (Simple Direct Media Layer 2) is a cross-platform multimedia development library for developing 2D games, multimedia applications and graphical user interfaces. It provides APIs for accessing multimedia functions such as audio, video, input devices, graphics hardware acceleration, etc., allowing developers to easily create cross-platform multimedia applications.

[0111] The embodiment of the present application improves the decoding performance and supports video decoding in high-quality encoding formats by compiling the decoder into a Wasm module. At the same time, in order to adapt to the multi-grid playback scenario, multi-grid rendering is performed directly in the wasm module. Only one canvas needs to be created to perform multi-grid rendering. The rendering of the screen can be controlled according to the interface, which is very different from the traditional rendering using JS. When rendering multiple grids, the data cache uses the FIFO mode to improve memory utilization and maintain long-term stable playback during multi-screen playback. The response and loading speed to terminal data requests are improved, and the video viewing experience is optimized.

[0112] Next, combine Figure 2 The implementation process of this embodiment is described as follows.

[0113] Reference Figure 2 , showing a schematic diagram of a system architecture provided in an embodiment of the present application.

[0114] like Figure 2 As shown in the figure, the browser is the main interface for users to interact with web applications. It is responsible for interpreting HTML, CSS, and JavaScript, and calling the wasm function module through js to play multi-grid audio and video.

[0115] JS: It is the backend logic of the web page, which is used to implement logical operations such as web page layout, websocket and HLS video stream pulling, identification, and processing.

[0116] WebAssembly: WebAssembly is responsible for converting C++ code into binary files that can be used by JS. It is a bridge between C++ and JS.

[0117] Network / IO: The Network / IO layer handles all network communications and input / output operations, as well as the transmission of internal data (such as JS transmitting video output to the C++ module).

[0118] C++: The C++ module is the core part of the embodiment of the present application. The decoding, rendering and display of H.265 video data are all completed by this part.

[0119] The specific implementation logic is as follows:

[0120] 1. The C++ module creates a management class to manage multiple video stream decoding, rendering, and display objects.

[0121] 2. The C++ module creates a video decoding, rendering, and display class. In addition to providing the decoding, rendering, and display capabilities of H.265 video data, this class also needs to provide a buffered memory (FIFO) data block for each video stream data.

[0122] 3. The C++ module provides necessary interfaces for each stream such as resource initialization (including memory, decoding objects, video display position, display width and height, etc.), resource release, start playback, stop playback, and insert video data.

[0123] 4. The JS module (including the JS file in this embodiment) first calculates the four-split screen according to the web page, the position of each video stream displayed in the canvas, and the display width and height.

[0124] 5. The JS module calls the video platform to obtain the websocket stream address, and uses these stream addresses to pull each H.265 video data to the web end.

[0125] 6. The JS module calls the C++ module initialization interface to allocate resources for each channel of H.265 video data (it should be noted here that the wasm file generated by the C++ module must be loaded before the initialization interface can be called).

[0126] 7. The JS module identifies the display window and streaming object of each video stream (such as 1, 2, 3, 4, etc.), and all interfaces of the C++ module correspond to the identification to avoid the intersection of data, memory, and objects.

[0127] 8. The JS module sends video data to the C++ module based on the reception of each video data.

[0128] 9. The C++ module first stores the data in the cache memory (FIFO) according to the video data reception situation, then reads the video data frame by frame from the memory, and uses the H.265 decoding module to decode and generate decoded video data.

[0129] 10. The C++ module sends the decoded video data generated by decoding to the corresponding SDL2 display object for display at the corresponding position of the stream.

[0130] 11. The JS module calls the data insertion method in a loop and keeps inserting video data into the C++ module. (It should be noted that in this process, since decoding and display consume a lot of CPU resources, it is very likely that the decoded data will be smaller than the inserted data, which will cause real-time video delays or even freezes. Here, the C++ module is required to process the data for frame loss.)

[0131] Next, the technical solution of the embodiment of the present application is described in detail as follows with reference to specific examples.

[0132] The embodiment is to play the four-grid video on the Edge browser:

[0133] 1. Module loading and initialization:

[0134] Load a web page on the Edge browser, and load the wasm module by calling js in the web page. The JS module will calculate the four-screen display position and display width and height of each video stream in the canvas based on the web page; create a canvas at the same time, and bind the canvas to the SDL window of the wasm module through the interface function provided by the Emscripten compiler, and then wasm will initialize some resources.

[0135] 2. Get multiple video data:

[0136] Create a streaming client on the web page to receive four-channel h.265 streaming data. At the same time, the JS module needs to call the C++ module initialization interface to allocate resources for each channel of H.265 video data. The real-time streaming data uses the wss protocol. This protocol can be used to directly create a websocket client on the web page using js to receive multiple channels of data without the need to implement additional background services for data reception. This method can effectively reduce transmission delays. At the same time, the audio and video packets are sent separately at the streaming service, and the internal wasm module makes judgments based on the packet header information when receiving the data packet. When multiple stream data is received on the web page, the module will first store the data in the cache memory (FIFO) according to the video data reception situation. And each channel of data is identified in the js layer (for multi-grid decoding and rendering). A stream analysis function is implemented inside the wasm interface. It mainly analyzes whether the data is audio or video data based on the packet header. Audio data will be placed in the audio buffer and video data will be placed in the video buffer. The data cache uses the FIFO mode and follows the first-in-first-out principle, which ensures the efficiency and completeness of the decoder when reading data from the memory. The size of this FIFO cache is set to a fixed value of 12MB.

[0137] Video file:

[0138] The video file is transmitted using the hls (HTTP Live Streaming) protocol. This protocol can be used to obtain multiple hls video data by using XMLHttpRequest. At the same time, the media service will divide the hls video file into a series of small segments and transmit them separately. Each channel of video data will also have a unique identifier (for multi-grid decoding and rendering). This segmented transmission helps to adapt to unstable network connections and allows dynamic adjustment of quality. Using XMLHttpRequest on the Js layer can realize segment-by-segment data reception, and at the same time, the decoder of the video file realizes the decoding of each series of small segments, thereby improving the decoding speed and making the playback of multiple videos smoother. The data of the video file is written to the virtual file system in wasm. The write function will write each channel of video data into its own virtual file through the identifier and arrange each segment of each channel in order. Then the decoder reads the video file data by reading the file.

[0139] 3. Multi-channel video data decoding:

[0140] The decoder is called and decoded according to the corresponding stream identifier. The H.265 decoder first reads the data in the cache memory (FIFO) frame by frame and decodes it to generate YUV video; the module will drop frames according to the video data reception (controlled by the frame drop strategy, which is described below)

[0141] In this solution, the decoder is implemented using the FFmpeg library. The decoders for decoding real-time streaming data and decoding recorded data are separate. At the same time, each channel of real-time streaming data will create its corresponding decoder based on the identifier established when acquiring the data, while the recorded file will create the corresponding decoder based on different virtual files.

[0142] Since the audio and video of the real-time stream are received separately and cached in FIFO, the decoder needs to read data from the FIFO. At the same time, the decoder is divided into two parts: audio and video. The audio stream will call the audio decoder, and the video stream will call the video decoder. The decoding information can be obtained by detecting the stream data through the function encapsulated by the FFmpeg library, and then the corresponding decoder is created for decoding based on the detected information.

[0143] The video file is stored in the virtual file system of wasm. In this solution, the video file can be opened directly through the function encapsulated by the FFmpeg library, the file information can be detected, and the corresponding decoder can be created for decoding.

[0144] 4. Multi-grid audio and video rendering:

[0145] The web page will pass the SDL rendering parameters (video width and height, rendering position, etc.) to the renderer module in the js layer through the rendering interface provided by the wasm module, and display the video in a four-square grid according to the identifier established when obtaining the data, according to the calculated video width and height. At the same time, the SDL renderer module will display the YUV video data generated by decoding in sequence on the Edge browser page.

[0146] The rendering of multi-channel audio is relatively simple. Call the SDL2 library function, and set the sampling rate, data format, and number of channels of the output audio. Use the conversion function to convert the decoded PCM data into the corresponding output audio format. Perform audio rendering through the callback function (set a callback for each channel). The decoded and converted audio data will also be cached in the FIFO, and then the output interval is controlled by the callback function to match the audio and video synchronization and the smooth and stable playback of the audio.

[0147] Video rendering is implemented through the SDL2 library. At the same time, SDL2 can directly render YUV (a data format) data, and the data decoded by the decoder is YUV. Before rendering, the js layer will create a Canvas canvas and bind it through wasm (this interface is described in the Emscripten interface document). At this time, the video data rendered by SDL2 will be displayed on the page through Canvas. The rendered YUV data is also converted through the conversion function. The main purpose of this is to dynamically change the width and height of the video screen to match the subsequent full-screen playback and multi-grid rendering.

[0148] The main principle of multi-grid rendering is to create multiple windows on a canvas. The size of each window is determined by the parameters passed in by the js layer. In this solution, each video will create a rendering window for the corresponding video according to the identifier. In the SDL2 library function, you can set the drawing area, and you can dynamically set the window position according to the size of the web page and the width and height of the video. Since each stream has a corresponding decoder and renderer, and each additional stream will dynamically expand the bottom canvas, and arrange the subsequent videos according to the position of the previous video. If the arrangement width exceeds the width of the display, it will be arranged downward in sequence, thereby realizing multi-grid rendering of the video. When multi-grid rendering is performed, the audio will be turned off by default, and the synchronization of audio and video is mainly matched by setting the playback timestamps of the audio and video.

[0149] 5. Rendering and frame dropping strategy:

[0150] There are two main places for rendering and frame dropping in this scheme. At the receiving end of real-time streaming data, the size of the FIFO buffer space will be used for judgment. When the current available space is less than the size of the incoming data, this part of the data will be directly discarded. The most direct impact of discarding this part of the received data is that the screen will suddenly jump. Because the FIFO buffer space is set to 12 megabytes, this space is usually sufficient. This strategy is mainly set to ensure the real-time streaming playback when the decoder works slowly or pauses due to some reasons (such as CPU resource shortage in multi-grid playback). In the decoder, the video frame rate, the time to decode a frame, and the time to convert the format of each frame can be counted in advance. Calculate 1000 / FPS to get the playback time of each frame. If the time to decode a frame plus the time to convert the format is less than the time to play a frame, it means that the performance is sufficient, and then the time to play a frame is set as the rendering interval; if the time to decode a frame plus the time to convert the format is greater than the time to play a frame, when the difference is within 3ms, the decoder will be notified and will not decode the P frame. If the difference is 3-5ms, the decoder will not decode the B frame at the same time. After it is greater than 5ms, only the I frame will be decoded. This strategy will be dynamically changed according to the above rules based on the actual decoding efficiency. At the same time, the above strategy will also be executed when playing the video file.

[0151] The core of this embodiment is to realize multi-grid playback of audio and video in multiple encoding formats across platforms, and mainly solve the following technical problems:

[0152] ①Real-time limitation: Traditional server-side transcoding introduces transmission delay, which limits the application scope of real-time audio and video playback. At the same time, when using HLS to play large files, traditional solutions may cause the cache time to be too long, affecting real-time performance and user experience. The present invention mainly compiles the decoder into a wasm module, which can be directly decoded in a native way on the browser. At the same time, corresponding optimizations are also made in data reception and data caching, breaking through the real-time limitation.

[0153] ② The problem of encoding and decoding audio and video streams in multiple formats: Traditional browsers do not natively support the decoding of some high-quality encodings (such as H.265, AV1, and other proprietary formats, etc.), so they need to rely on server-side transcoding or JavaScript-implemented decoders. This leads to insufficient decoding performance and the inability to achieve high-quality playback of some encoded audio and video streams. The present invention uses the FFmpeg library to support the decoding of most current encoding formats, including commonly used high-quality encoding formats.

[0154] ③ Multi-pane playback: For traditional web-side audio and video playback, usually only one page can play a single video, and if you want to play multiple videos at the same time, you often need to open multiple windows for playback. It is difficult to play multiple videos at the same time on one page or multiple streams on one page. The present invention uses the SDL2 library to play and control multi-grid videos in one canvas, and combines data caching, HLS slicing technology, decoding frame loss strategy and other technical means to achieve smooth video playback.

[0155] ④Compatibility issues: Traditional decoders are limited by the compatibility of browsers and operating systems, which limits cross-platform playback. The present invention achieves cross-platform compatibility by compiling the decoder into a wasm module.

[0156] The video playback method provided in the embodiment of the present application obtains N video display areas on the web display page by dividing the pre-created web display page, where N is a positive integer greater than 1. The N video streams obtained are cached in the FIFO queues corresponding to the N video streams. Based on the pre-compiled JS file, the pre-compiled wasm file is called to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data. The wasm file is a file compiled based on the WebAssembly technology to compile the source code of the decoding library of FFmpeg. The JS file is a file for calling the wasm file compiled based on the calling requirements of the WebAssembly technology. The wasm file and the JS file are pre-loaded in the web display page. Each decoded video data in the N decoded video data is displayed in the corresponding video display area in the corresponding N video display areas. The embodiment of the present application realizes the application scenario of H.265 playback based on WebAssembly technology, realizes the playback and control of multi-grid videos in a canvas, and realizes the purpose of smoothly playing multiple video streams on a web page client at the same time.

[0157] Reference Figure 3 , shows a schematic diagram of the structure of a video playback device provided in an embodiment of the present application, such as Figure 3 As shown, the video playback device 300 may include the following modules:

[0158] The video display area acquisition module 310 is used to divide the pre-created web display page to obtain N video display areas on the web display page, where N is a positive integer greater than 1;

[0159] The video stream caching module 320 is used to cache the acquired N video streams in FIFO queues corresponding to the N video streams respectively;

[0160] The decoded video data acquisition module 330 is used to call the pre-compiled wasm file based on the pre-compiled JS file to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data, wherein the wasm file is a file compiled by compiling the decoding library source code of FFmpeg based on the WebAssembly technology, and the JS file is a file compiled based on the calling requirements of the WebAssembly technology and used to call the wasm file, and the wasm file and the JS file are pre-loaded in the web display page;

[0161] The multi-channel video display module 340 is used to display each of the N decoded video data in a corresponding video display area among the corresponding N video display areas.

[0162] Optionally, the video stream caching module includes:

[0163] A video stream pulling unit, used to pull the N video streams using a websocket stream address;

[0164] A cache condition determination unit, configured to determine whether the N video streams meet a cache condition based on a preset frame loss strategy;

[0165] A video stream caching unit, configured to cache the N video streams in the FIFO queues respectively corresponding to the N video streams when it is determined that the N video streams meet a caching condition;

[0166] The non-key frame discarding unit is used to discard the designated non-key frames in the N video streams when it is determined that the N video streams do not meet the buffering condition.

[0167] Optionally, the cache condition determination unit includes:

[0168] A first condition determination subunit is used to determine whether the N video streams meet the caching condition based on the size relationship between the remaining storage space of the FIFO queue and the occupied storage space of the N video streams when the frame loss strategy is the available space strategy;

[0169] The non-key frame discarding unit comprises:

[0170] The non-key frame discarding subunit is used to discard the specified non-key frames in the N video streams when the remaining storage space is smaller than the storage space occupied by the N video streams.

[0171] Optionally, the cache condition determination unit includes:

[0172] A second condition determination subunit is used to determine whether the N video streams meet the caching condition based on the single frame decoding time, the single frame format conversion time and the single frame playback time when the frame loss strategy is a time strategy;

[0173] The non-key frame discarding unit comprises:

[0174] The designated frame discarding subunit is used to discard designated non-key frames in the N video streams based on the difference between the sum and the single frame playback time when the sum of the single frame decoding time and the single frame format conversion time is greater than the single frame playback time.

[0175] Optionally, the designated frame discarding subunit includes:

[0176] A P frame discarding subunit, configured to discard the P frames in the N video streams if the difference is less than or equal to the first duration;

[0177] A B frame discarding subunit, configured to discard the B frames in the N video streams when the difference is greater than the first duration and less than or equal to a second duration;

[0178] The I frame discarding subunit is used to discard the I frame in the N video streams when the difference is greater than the second duration.

[0179] Optionally, the multi-channel video display module includes:

[0180] A decoded data reading unit, used for calling a pre-loaded SDL2 file corresponding to each of the video display areas to read corresponding decoded video data;

[0181] The multi-channel video display unit is used to render and display the corresponding decoded video data in the corresponding video display area based on the SDL2 file.

[0182] Optionally, the video display area acquisition module includes:

[0183] A display information acquisition unit, used to acquire the display positions and display sizes of N pre-configured video display areas on the web display page;

[0184] A display area creating unit is configured to create N video display areas on the web display page based on the display position and the display size.

[0185] The video playback device provided in the embodiment of the present application obtains N video display areas on the web display page by dividing the pre-created web display page, where N is a positive integer greater than 1. The obtained N video streams are cached in the FIFO queues corresponding to the N video streams. Based on the pre-compiled JS file, the pre-compiled wasm file is called to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data. The wasm file is a file compiled based on the WebAssembly technology to compile the decoding library source code of FFmpeg. The JS file is a file for calling the wasm file compiled based on the calling requirements of the WebAssembly technology. The wasm file and the JS file are pre-loaded in the web display page. Each decoded video data in the N decoded video data is displayed in the corresponding video display area in the corresponding N video display areas. The embodiment of the present application realizes the application scenario of H.265 playback based on WebAssembly technology, realizes the playback and control of multi-grid videos in a canvas, and realizes the purpose of smoothly playing multiple video streams on a web page client at the same time.

[0186] An embodiment of the present application further provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the above-mentioned video playback method when executed by the processor.

[0187] Figure 4 FIG. 4 is a schematic diagram showing the structure of an electronic device 400 according to an embodiment of the present invention. Figure 4 As shown, the electronic device 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 402 or computer program instructions loaded from a storage unit 408 into a random access memory (RAM) 803. In RAM 403, various programs and data required for the operation of the electronic device 400 can also be stored. CPU 401, ROM 402 and RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0188] Multiple components in the electronic device 400 are connected to the I / O interface 405, including: an input unit 406, such as a keyboard, a mouse, a microphone, etc.; an output unit 407, such as various types of displays, speakers, etc.; a storage unit 408, such as a disk, an optical disk, etc.; and a communication unit 409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 409 allows the electronic device 400 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0189] The various processes and processing described above may be performed by the processing unit 401. For example, the method of any of the above embodiments may be implemented as a computer software program, which is tangibly contained in a computer-readable medium, such as the storage unit 408. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 400 via the ROM 402 and / or the communication unit 409. When the computer program is loaded into the RAM 403 and executed by the CPU 401, one or more actions in the method described above may be performed.

[0190] In addition, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned video playback method is implemented.

[0191] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0192] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0193] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminals (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0194] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0195] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal so that a series of operating steps are executed on the computer or other programmable terminal to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0196] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0197] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal. In the absence of further restrictions, the elements defined by the statement "comprise a..." do not exclude the presence of other identical elements in the process, method, article or terminal including the elements.

[0198] The above is a detailed introduction to a video playback method, a video playback device, an electronic device and a computer-readable storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.< / audio> < / video>

Claims

1. A video playback method, characterized in that: The method comprises: Dividing a pre-created web display page to obtain N video display areas on the web display page, where N is a positive integer greater than 1; Cache the acquired N video streams in FIFO queues corresponding to the N video streams respectively; Based on the pre-compiled JS file, the pre-compiled wasm file is called to perform video decoding processing on the N video streams read from the FIFO queue to obtain N decoded video data, wherein the wasm file is a file obtained by compiling the decoding library source code of FFmpeg based on the WebAssembly technology, and the JS file is a file for calling the wasm file compiled based on the calling requirements of the WebAssembly technology, and the wasm file and the JS file are pre-loaded in the web display page; Each decoded video data of the N decoded video data is displayed in a corresponding video display area of ​​the corresponding N video display areas.

2. The method according to claim 1, characterized in that The step of caching the acquired N video streams in FIFO queues respectively corresponding to the N video streams includes: Use the websocket stream address to pull the N video streams; Based on a preset frame loss strategy, determining whether the N video streams meet a caching condition; When it is determined that the N video streams meet the caching condition, caching the N video streams in the FIFO queues respectively corresponding to the N video streams; When it is determined that the N video streams do not meet the buffering condition, designated non-key frames in the N video streams are discarded.

3. The method according to claim 2, characterized in that The determining whether the N video streams meet the caching condition based on the preset frame loss strategy includes: In the case where the frame loss strategy is an available space strategy, determining whether the N video streams meet a caching condition based on a size relationship between the remaining storage space of the FIFO queue and the occupied storage space of the N video streams; The step of discarding designated non-key frames in the N video streams when it is determined that the N video streams do not meet the cache condition includes: When the remaining storage space is smaller than the storage space occupied by the N video streams, the designated non-key frames in the N video streams are discarded.

4. The method according to claim 2, characterized in that: The determining whether the N video streams meet the caching condition based on the preset frame loss strategy includes: In the case where the frame loss strategy is a time strategy, determining whether the N video streams meet the caching condition based on the single frame decoding time, the single frame format conversion time and the single frame playback time; The step of discarding designated non-key frames in the N video streams when it is determined that the N video streams do not meet the cache condition includes: When the sum of the single frame decoding time and the single frame format conversion time is greater than the single frame playback time, the designated non-key frames in the N video streams are discarded based on the difference between the sum and the single frame playback time.

5. The method according to claim 4, characterized in that The discarding of the designated non-key frames in the N video streams based on the difference between the sum and the single frame playback time includes: If the difference is less than or equal to the first duration, discard the P frame in the N video streams; When the difference is greater than the first duration and less than or equal to the second duration, discard the B frames in the N video streams; When the difference is greater than the second duration, the I frame in the N video streams is discarded.

6. The method according to claim 1, characterized in that The step of displaying each decoded video data of the N decoded video data in a corresponding video display area of ​​the corresponding N video display areas comprises: Calling the pre-loaded SDL2 file corresponding to each of the video display areas to read the corresponding decoded video data; Based on the SDL2 file, the corresponding decoded video data is rendered and displayed in the corresponding video display area.

7. The method according to claim 1, characterized in that The pre-created web display page is divided to obtain N video display areas on the web display page, including: Obtaining display positions and display sizes of N pre-configured video display areas on the web display page; N video display areas are created on the web display page based on the display position and the display size.

8. A video playback device, characterized in that: The device comprises: A video display area acquisition module, used for dividing a pre-created web display page to obtain N video display areas on the web display page, where N is a positive integer greater than 1; A video stream caching module, used for caching the acquired N video streams in FIFO queues corresponding to the N video streams respectively; A decoding video data acquisition module is used to call a pre-compiled wasm file based on a pre-compiled JS file to perform video decoding processing on N video streams read from the FIFO queue to obtain N decoded video data, wherein the wasm file is a file compiled based on the WebAssembly technology to compile the decoding library source code of FFmpeg, and the JS file is a file compiled based on the calling requirements of the WebAssembly technology to call the wasm file, and the wasm file and the JS file are pre-loaded in the web display page; The multi-channel video display module is used to display each decoded video data of the N decoded video data in a corresponding video display area of ​​the corresponding N video display areas.

9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the video playback method according to any one of claims 1 to 7 when executing the program.

10. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the video playback method according to any one of claims 1 to 7.