Video playing method and device, electronic equipment and storage medium
By separating the video decoding and rendering processes on the computer and using shared memory blocks for data transmission, the display level problems and resource waste problems during video playback in the prior art are solved, and efficient and stable multi-video playback effect is achieved.
Patent Information
- Application Number
- CN202411366836.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-01-03
AI Technical Summary
The prior art has display hierarchy problems and waste of window handle resources when playing videos on the computer, resulting in large resources occupancy when playing multiple videos, which can easily lead to software crashes.
By dividing video decoding and rendering into two processes, using shared memory blocks for data transmission, the decoding process writes video frame data to shared memory, and the rendering process reads from shared memory and renders it to the display interface, realizing any superposition of video content and efficient playback.
It completely solves the hierarchical problem of video playback, reduces the risk of software crash, reduces the consumption of CPU and memory usage, and achieves smooth playback of multiple videos.
Smart Images

Figure CN119255043A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video processing technology, and in particular to a video playing method, device, electronic equipment and storage medium. Background Art
[0002] With the rise of voice social networking, live broadcast social networking and other Internet social methods, virtual gifts have become a common interactive function. Usually, after a user gives a virtual gift, the corresponding animation effect of the virtual gift will be played on the client. Common virtual gift video animations include MP4, SVGA (Scalable Vector Graphics Animation), VAP (Video Animation Player) and other formats.
[0003] Currently, to play video multimedia files on a computer, you need to use FFmpeg (Fast Forward Moving Picture Experts Group) for video decoding and DirectX for rendering. During video playback, using DirectX for rendering requires a window handle, and the rendered video is located in the entire window, resulting in the need to open a window to play a video. In addition, the content rendered in the window cannot be superimposed on other displayed video content, resulting in a display level problem. As a result, when playing multiple videos, resources are occupied more, the software is prone to crash, and the use of the software is greatly affected. Summary of the invention
[0004] The present invention provides a video playback method, device, electronic device and storage medium, which are used to solve the defects of display level problems and waste of window handle resources in the prior art when playing videos on a computer, and completely solve the level problem of video playback. The displayed video content can be arbitrarily superimposed with other video content, and the video no longer relies on window display, thereby reducing the impact of software crashes.
[0005] The present invention provides a video playback method, comprising:
[0006] The first process sends playback information of at least one target video to the second process;
[0007] The second process loads and decodes the target video according to the playback information, and sequentially obtains each frame of video frame data of the target video;
[0008] The second process writes each frame of video frame data into the shared memory block in sequence;
[0009] The first process reads each frame of video frame data from the shared memory block in sequence;
[0010] The first process renders each frame of video frame data sequentially to a display interface to achieve playback.
[0011] According to a video playback method provided by the present invention, the second process writes each frame of video frame data into a shared memory block in sequence, including:
[0012] When the second process writes a frame of video frame data into the shared memory block, it is determined whether the currently written video frame data is the last frame of video frame data of the target video;
[0013] If not, changing the preset memory flag of the shared memory block to a first preset flag, wherein the first preset flag is used to indicate that the currently written video frame data is in an unread state;
[0014] If yes, the preset memory flag of the shared memory block is changed to a second preset flag, wherein the second preset flag is used to indicate that the target video is in a write-completed state.
[0015] According to a video playback method provided by the present invention, the first process sequentially reads each frame of video frame data from the shared memory block, including:
[0016] Each time the first process accesses the shared memory block, reading and determining the preset memory flag bit;
[0017] If the preset memory flag is the first preset identifier, a frame of video frame data is read, and the preset memory flag is changed to a third preset identifier, wherein the third preset identifier is used to indicate that the written video frame data is in a read state.
[0018] According to a video playback method provided by the present invention, each time the first process accesses the shared memory block, after reading and judging the preset memory flag bit, the method further includes:
[0019] If the preset memory flag is the second preset flag, read the last frame of video frame data in the shared memory block, and change the preset memory flag to a fourth preset flag, wherein the fourth preset flag is used to indicate that the target video is in a read completion state;
[0020] Finish reading the shared memory block and release the memory resources.
[0021] According to a video playback method provided by the present invention, each time the first process accesses the shared memory block, after reading and judging the preset memory flag bit, the method further includes:
[0022] If the preset memory flag is the third preset identifier, repeatedly reading the preset memory flag;
[0023] If the number of times that the preset memory flag is repeatedly read to be the third preset identifier exceeds a preset threshold, the reading of the shared memory block is stopped and the memory resources are released.
[0024] According to a video playback method provided by the present invention, the second process loads and decodes the target video according to the playback information, and sequentially obtains each frame of video frame data of the target video, including:
[0025] The second process loads the target video according to the playback information;
[0026] Decoding the target video;
[0027] When the first frame of video frame data is obtained through decoding, the shared memory block is created, and the memory address of the shared memory block is sent to the first process;
[0028] The second process writes each frame of video frame data into a shared memory block in sequence, including:
[0029] The second process writes the first frame of video frame data into the shared memory block.
[0030] According to a video playback method provided by the present invention, the first process renders each frame of video frame data sequentially to a display interface to achieve playback, including:
[0031] The first process obtains the playback area information of the target video;
[0032] According to the playback area information, each frame of the video frame data of the target video is sequentially rendered into a corresponding playback area, wherein the playback area is within the range of the display interface.
[0033] According to a video playback method provided by the present invention, the method further includes:
[0034] When the second process detects that data cannot be written to the shared memory block, it stops decoding the target video and restarts the process to wait for receiving the next decoding task.
[0035] The present invention also provides a video playback device, comprising:
[0036] A sending module, used for the first process to send the playback information of at least one target video to the second process;
[0037] A decoding module, used for the second process to load and decode the target video according to the playback information, and obtain each frame of video frame data of the target video in sequence;
[0038] A writing module, used for the second process to write each frame of video frame data into a shared memory block in sequence;
[0039] A reading module, used for the first process to read each frame of video frame data from the shared memory block in sequence,
[0040] The rendering module is used for the first process to render each frame of the video frame data sequentially to the display interface to achieve playback.
[0041] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned video playback methods is implemented.
[0042] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the video playback method described in any one of the above is implemented.
[0043] The present invention provides a video playback method, device, electronic device and storage medium. When it is necessary to play a video, the video decoding and video rendering are divided into two processes for execution. The video decoding process writes the decoded video frame data into a shared memory, and the video rendering process reads the video frame data from the shared memory for rendering, thereby realizing playback in the display interface. The present invention realizes efficient video playback performance based on memory sharing. The video no longer relies on the video playback component for decoding and rendering, and does not need to rely on window display. It can be displayed in any area of the display interface, and the hierarchical problem of video playback is completely solved. The displayed content can be arbitrarily superimposed with other content to realize multiple video playback displays. Compared with the prior art in which the video playback component occupies a large amount of memory and playing too many videos easily causes the software to crash, the present invention can minimize the impact caused by the crash and can also reduce the consumption and requirements for the CPU. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 This is one of the flow charts of the video playback method provided by the present invention;
[0046] Figure 2 This is the second flow chart of the video playback method provided by the present invention;
[0047] Figure 3 It is a structural schematic diagram of the video playback device provided by the present invention;
[0048] Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] It should be noted that, in the description of the embodiments of the present invention, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "include one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to the specific circumstances.
[0051] The terms "first", "second", etc. in the present invention are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" means at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0052] Combine the following Figure 1-Figure 4 The present invention describes a video playback method, device, electronic device and storage medium.
[0053] like Figure 1 As shown, the present invention provides a video playback method, which can be applied to computer software with a video playback function, and specifically includes the following steps:
[0054] Step 110: The first process sends playback information of at least one target video to the second process.
[0055] Specifically, in the computer software, the video playback process is divided into two processes to collaborate. The two processes work respectively: video decoding and video rendering, among which the second process is mainly used for video decoding, and the first process is mainly used for video rendering. After the two processes are created, inter-process communication can be achieved through the RPC (Remote Procedure Call) protocol. When the video needs to be played, the first process sends the playback information to the second process, and the second process can obtain the playback information of the target video to be played.
[0056] In some embodiments, the target video playback information may come from a playback operation instruction of a software client, such as receiving a playback operation instruction from a user. In other embodiments, the playback information may come from a push from a software server, such as a client of a voice social software receiving a video animation playback event of a virtual gift pushed by a server.
[0057] The first process obtains the playback information of the target video and sends the playback information to the second process, which then loads and decodes the target video according to the playback information. Taking the application scenario of playing a video animation of a virtual gift as an example, when the client receives a video animation playback event of a virtual gift pushed by the server, it obtains the playback information of the target video carried in the video animation playback event, and the first process sends the playback information to the second process.
[0058] Specifically, the play information may include the video file path of the target video, so that the second process can load the target video through the video file path. The play information may also include information such as play duration, video type, and a unique identifier of a rendering or decoding thread.
[0059] It should be understood that when multiple videos need to be played, the second process will load and decode the multiple target videos according to the playback information of the multiple target videos.
[0060] Step 120: the second process loads and decodes the target video according to the playback information, and obtains each frame of video frame data of the target video in sequence.
[0061] Step 130: the second process writes each frame of video frame data into a shared memory block in sequence.
[0062] Specifically, the second process finds and loads the video file of the target video according to the video file path carried in the playback information. The type of the video file is basically not limited, such as MP4, VAP, PAG, GIF, SVGA, etc. The second process decodes the video file frame by frame, obtains each frame of video frame data in turn, and writes each frame of video frame data into the shared memory block in turn. Each time the second process decodes a frame of video frame data, it writes the video frame data into the shared memory, and then decodes the next frame of video frame data.
[0063] In some embodiments, hardware accelerated decryption can be performed through FFmpeg to parse the video frame data.
[0064] In some embodiments, step 120 specifically includes:
[0065] The second process loads the target video according to the playback information;
[0066] Decoding the target video;
[0067] When the first frame of video frame data is obtained through decoding, the shared memory block is created, and the memory address of the shared memory block is sent to the first process.
[0068] Step 130 specifically includes: the second process writes the first frame of video frame data into the shared memory block.
[0069] Specifically, when the second process decodes the first frame of video frame data of the target video, it creates a shared memory block corresponding to the target video, writes the first frame of video frame data into the shared memory block, and sends the memory address of the shared memory block to the first process, so that the first process can read each frame of video frame data of the target video according to the memory address.
[0070] It can be understood that each time the second process decodes a frame of video frame data, it writes a frame of video frame data to the shared memory. As a result, the first process can quickly read a frame of video frame data from the shared memory block for rendering, thereby achieving decoding and rendering at the same time. The present invention achieves efficient video playback performance based on memory sharing.
[0071] In some embodiments, the second process loads and decodes the target video according to the playback information. If the second process fails to decode the first frame of video frame data, the second process sends a decoding failure message to the first process. The first process can know that the target video playback fails, release resources, and improve device performance.
[0072] It should be understood that the first process can continuously send playback information to the second process, and the second process responds upon receiving the playback information. The second process can decode multiple target videos in parallel and write the video frame data of different target videos into different shared memory blocks. In other words, one shared memory block stores the video frame data of one target video.
[0073] Step 140: The first process reads each frame of video frame data from the shared memory block in sequence.
[0074] Step 150: the first process renders each frame of the video frame data sequentially to a display interface to achieve playback.
[0075] Specifically, when the first process receives the memory address sent by the second process, it can find the corresponding shared memory block according to the memory address, and read each frame of video frame data corresponding to the target video in sequence for rendering. Each time the first process reads a frame of video frame data, it renders a frame of video frame data to the display interface to achieve the playback of the target video.
[0076] It is understandable that the second process can send the memory address of the created shared memory block together with the decoding result. In addition, it can also send information such as the resolution and frame rate of the target video obtained by loading and decoding.
[0077] In some embodiments, the decoding speed of the second process and the rendering speed of the first process can be determined according to the frame rate of the target video. Specifically, the decoding and rendering speeds of the processes can be calculated according to the frame rate of the target video, or in other words, the speeds of the second process writing data and the first process reading data can be determined, so that after the second process writes a frame of video frame data, the first process reads the frame of video frame data, that is, decoding one frame and rendering one frame, and rendering and playing while decoding.
[0078] In the present invention, D3D (Direct3D, a 3D graphics programming interface developed by Microsoft on the Microsoft Windows operating system) can be used for off-screen rendering, so that the texture image of the video frame data can be rendered off-screen to the memory without using the window handle, and then the D3D rendering memory BUF is converted into bitmap pixels. In this process, hardware and GPU are used for efficient decoding and rendering, reducing the consumption and requirements of the CPU.
[0079] Therefore, each target video does not need to occupy a window handle independently. Multiple video playback areas can be divided in one display interface through code, and different target videos can be rendered in different playback areas.
[0080] In some embodiments, step 150 specifically includes:
[0081] The first process obtains the playback area information of the target video;
[0082] According to the playback area information, each frame of the video frame data of the target video is sequentially rendered into a corresponding playback area, wherein the playback area is within the range of the display interface.
[0083] In this embodiment, the playback area information may be included in the playback information. The first process determines the playback area of the target video in the display interface based on the playback area information, and renders each frame of video frame data read into the playback area, thereby achieving playback of the target video.
[0084] The playback area can be determined based on the strategy preset by the business needs, for example, randomly determining the playback area; or determining it based on the area sorting; for example, in the playback scenario of a virtual gift video animation, the playback area of the target video is determined based on the level of the gift-giving user and the preset level of the playback area.
[0085] The above embodiment provides a video playback method. When it is necessary to play a video, the video decoding and video rendering are divided into two processes for execution. The video decoding process writes the decoded video frame data into a shared memory, and the video rendering process reads the video frame data from the shared memory for rendering, thereby realizing playback in the display interface. The present invention realizes efficient video playback performance based on memory sharing. The video no longer relies on the video playback component for decoding and rendering, and does not need to rely on window display. It can be displayed in any area of the display interface, and the hierarchical problem of video playback is completely solved. The displayed content can be arbitrarily superimposed with other content to realize multiple video playback displays. Compared with the prior art in which the video playback component occupies a large amount of memory and playing too many videos easily causes the software to crash, the present invention can minimize the impact caused by the crash and reduce the consumption and requirements of the CPU.
[0086] In order to ensure that each frame of the target video is decoded and rendered, in some embodiments, step 130 specifically includes:
[0087] When the second process writes a frame of video frame data into the shared memory block, it is determined whether the currently written video frame data is the last frame of video frame data of the target video;
[0088] If not, changing the preset memory flag of the shared memory block to a first preset flag, wherein the first preset flag is used to indicate that the currently written video frame data is in an unread state;
[0089] If yes, the preset memory flag of the shared memory block is changed to a second preset flag, wherein the second preset flag is used to indicate that the target video is in a write-completed state.
[0090] Accordingly, step 140 specifically includes:
[0091] Each time the first process accesses the shared memory block, reading and determining the preset memory flag bit;
[0092] If the preset memory flag is the first preset identifier, a frame of video frame data is read, and the preset memory flag is changed to a third preset identifier, wherein the third preset identifier is used to indicate that the written video frame data is in a read state.
[0093] In this embodiment, a memory flag is set for the shared memory block. The memory flag is a specified byte of the shared memory block, which is used to indicate the write and read status of the target video. Different preset identifiers are used to represent different statuses. The specific statuses may include: the unread status of the written video frame data, the read status, and the write completion status of the target video. For example, the first byte of the memory flag is used to indicate the above status.
[0094] In some embodiments, at least one designated byte of the shared memory block can be used to represent the length of the video frame data of the target video. When the first process reads the designated byte, the length of the video frame data to be read can be known. For example, the second byte of the shared memory block is used to represent the length of the video frame data of the target video. In some embodiments, the remaining bytes of the shared memory block represent the video frame data of the target video.
[0095] Specifically, the first preset identifier is used to indicate that the currently written video frame data is in an unread state, the second preset identifier is used to indicate that the target video is in a write-completed state, and the third preset identifier is used to indicate that the written video frame data is in a read state.
[0096] When the second process writes a frame of video frame data to the shared memory block, it will determine whether the currently written video frame data is the last frame of video frame data obtained by decoding the target video.
[0097] If the current frame being written is not the last frame, the second process changes the preset memory flag to the first preset flag after completing writing the video frame data, indicating that the written video frame data is in an unread state, that is, the written video frame data has not been read yet.
[0098] If the last frame is currently being written, the second process changes the preset memory flag to a second preset flag after completing writing the last frame of video frame data, indicating that the target video is in a write-completed state, that is, all video frame data of the target video has been written into the shared memory block.
[0099] Thus, the second process writes data in a loop, writes the video frame data obtained by decoding the video file frame by frame into the shared memory block, and changes the preset memory flag to the first preset flag each time writing, until all the video frame data of the target video is written, and changes the preset memory flag to the second preset flag, indicating that the writing of the video frame data of the target video has been completed, that is, the decoding of the target video has been completed.
[0100] Correspondingly, the first process accesses the shared memory block in sequence to read data. Each time the shared memory block is accessed, the preset memory flag is first read to determine the current flag.
[0101] If the preset memory flag read is the first preset flag (ie, unread state), the first process reads a frame of video frame data, and after reading, changes the preset memory flag to the third preset flag, indicating that a frame of video frame data has been read.
[0102] In this way, the first process can determine whether the video frame data written in the shared memory block has been read by judging the preset memory flag bit. If not, the video frame data written by the second process is read. In this way, it can effectively ensure that each frame of the target video is rendered, prevent frame drops, and avoid repeated reading and rendering of video frame data, ensuring smooth playback of the target video.
[0103] In order to further ensure the rendering and playback of the video, in some embodiments, the state of the target video further includes a read completion state (which may also be a rendering completion state or a playback completion state). In this embodiment, a fourth preset identifier is used to represent the read completion state of the target video.
[0104] Each time the first process accesses the shared memory block, after reading and determining the preset memory flag bit, the method further includes:
[0105] If the preset memory flag is the second preset flag, read the last frame of video frame data in the shared memory block, and change the preset memory flag to a fourth preset flag, wherein the fourth preset flag is used to indicate that the target video is in a read completion state;
[0106] Finish reading the shared memory block and release the memory resources.
[0107] Specifically, if the preset memory flag read by the first process is the second preset flag (i.e., the target video writing completion status), that is, the first process will read the last frame of video frame data of the target video, then after reading, the preset memory flag is changed to the fourth preset flag, indicating that the target video reading completion status. At this point, the target video has been read, and then the first process no longer reads the shared memory block corresponding to the target video and releases memory resources. In this way, when playing multiple videos, memory resources are released immediately after the video playback ends, reducing memory usage and effectively reducing device crashes.
[0108] In order to further reduce memory usage, in some embodiments, each time the first process accesses the shared memory block, after reading and determining the preset memory flag, the method further includes:
[0109] If the preset memory flag is the third preset identifier, repeatedly reading the preset memory flag;
[0110] If the number of times that the preset memory flag is repeatedly read to be the third preset identifier exceeds a preset threshold, the reading of the shared memory block is stopped and the memory resources are released.
[0111] Specifically, if the preset memory flag read by the first process is the third preset flag (i.e., the written video frame data is in the read state), it means that the second process has not written new video frame data, and the first process repeatedly reads the preset memory flag. If the number of times the preset memory flag is repeatedly read and the state is not read exceeds a preset threshold, the reading is stopped and the memory resources are released.
[0112] It can be understood that if the number of times the preset memory flag is repeatedly read as the third preset flag does not exceed the preset threshold, that is, the first preset flag (unread state) or the second preset flag (written state) may be read, the first process reads a frame of video frame data for rendering according to the normal process, and changes the preset memory flag to the third preset flag (read state) or the fourth preset flag (read completed state).
[0113] The situation that the second process is currently unable to write new data to the shared memory generally indicates that the second process has crashed or is abnormal. In some embodiments, the method further includes: when the second process detects that it is unable to write data to the shared memory block, stopping decoding the target video and restarting the process to wait for receiving the next decoding task.
[0114] In this embodiment, when the second process crashes or becomes abnormal, it will automatically restart and wait for the next decoding task. In this way, the next video playback will automatically return to normal, ensuring normal playback of subsequent videos.
[0115] Figure 2 The following is a specific flow chart of a video playback method according to an exemplary embodiment of the present invention. Figure 2 As shown, the first process tells the second process the playback information of the target video through RPC communication technology, and the second process loads and decodes the target video according to the playback information. If the second process fails to decode, it sends a decoding failure message to the first process, and the first process ends the process after knowing it.
[0116] If the second process decodes the first frame of video frame data, a shared memory block is created, and the first frame of video frame data is written to the shared memory block, and the preset memory flag is changed to the first preset flag (unread state). At the same time, a decoding success message is sent to the first process, and the first process is notified of the memory address of the shared memory block where the video frame data is written. The first process accesses the shared memory block according to the memory address, reads the preset memory flag, and if the first preset flag is read, reads a frame of video frame data for rendering, and changes the preset memory flag to the third preset flag (read state).
[0117] Similarly, the second process writes each frame of video frame data into the shared memory block in turn. Each time a frame of video frame data is written, it is determined whether the currently written video frame data is the last frame of video frame data of the target video. If not, the preset memory flag is changed to the first preset flag (unread state), and data is continued to be written subsequently; if yes, the preset memory flag is changed to the second preset flag (written state), and the process ends.
[0118] The first process accesses the shared memory block in sequence and reads the preset memory flag. If the first preset flag is read (unread state), a frame of video frame data is read for rendering, and the preset memory flag is changed to the third preset flag (read state), and then the data is continued to be read. If the second preset flag is read (written state), the last frame of video frame data is read for rendering, and the preset memory flag is changed to the fourth preset flag (read state), and the process ends, that is, the target video is played and the memory resources are released.
[0119] If the first process reads the third preset identifier (read status), the preset memory flag is read repeatedly. If the number of repeated readings exceeds the preset threshold, the first process stops the reading operation and ends the process, that is, the target video stops playing and memory resources are released.
[0120] The video playback device provided by the present invention is described below. The video playback device described below and the video playback method described above can be referenced to each other.
[0121] like Figure 3As shown, the present invention provides a video playback device, comprising:
[0122] A sending module 310, configured for the first process to send the playback information of at least one target video to the second process;
[0123] A decoding module 320, configured for the second process to load and decode the target video according to the playback information, and sequentially obtain each frame of video data of the target video;
[0124] A writing module 330, configured for the second process to write each frame of video frame data into a shared memory block in sequence;
[0125] The reading module 340 is used for the first process to read each frame of video frame data from the shared memory block in sequence.
[0126] The rendering module 350 is used for the first process to render each frame of the video frame data sequentially to the display interface to achieve playback.
[0127] Figure 4 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the video playback method, which includes: the second process loads and decodes the target video according to the playback information, and sequentially obtains each frame of video frame data of the target video; the second process sequentially writes each frame of video frame data into a shared memory block; the first process sequentially reads each frame of video frame data from the shared memory block; the first process sequentially renders each frame of video frame data to a display interface to achieve playback.
[0128] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
[0129] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the video playback method provided by the above methods, and the method includes: a first process sends playback information of at least one target video to a second process; the second process loads and decodes the target video according to the playback information, and obtains each frame of video frame data of the target video in turn; the second process writes each frame of video frame data into a shared memory block in turn; the first process reads each frame of video frame data from the shared memory block in turn; the first process renders each frame of video frame data to a display interface in turn to achieve playback.
[0130] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the video playback method provided by the above-mentioned methods. The method includes: a first process sends playback information of at least one target video to a second process; the second process loads and decodes the target video according to the playback information, and obtains each frame of video frame data of the target video in sequence; the second process writes each frame of video frame data into a shared memory block in sequence; the first process reads each frame of video frame data from the shared memory block in sequence; the first process renders each frame of video frame data to a display interface in sequence to achieve playback.
[0131] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0132] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0133] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A video playback method, characterized in that: include: The first process sends playback information of at least one target video to the second process; The second process loads and decodes the target video according to the playback information, and sequentially obtains each frame of video frame data of the target video; The second process writes each frame of video frame data into the shared memory block in sequence; The first process reads each frame of video frame data from the shared memory block in sequence; The first process renders each frame of video frame data sequentially to a display interface to achieve playback.
2. The video playback method according to claim 1, characterized in that: The second process writes each frame of video frame data into a shared memory block in sequence, including: When the second process writes a frame of video frame data into the shared memory block, it is determined whether the currently written video frame data is the last frame of video frame data of the target video; If not, changing the preset memory flag of the shared memory block to a first preset flag, wherein the first preset flag is used to indicate that the currently written video frame data is in an unread state; If yes, changing the preset memory flag of the shared memory block to a second preset flag, wherein the second preset flag is used to indicate that the target video is in a write-completed state; The first process sequentially reads each frame of video frame data from the shared memory block, including: Each time the first process accesses the shared memory block, reading and determining the preset memory flag bit; If the preset memory flag is the first preset identifier, a frame of video frame data is read, and the preset memory flag is changed to a third preset identifier, wherein the third preset identifier is used to indicate that the written video frame data is in a read state.
3. The video playback method according to claim 2, characterized in that: Each time the first process accesses the shared memory block, after reading and determining the preset memory flag bit, the method further includes: If the preset memory flag is the second preset flag, read the last frame of video frame data in the shared memory block, and change the preset memory flag to a fourth preset flag, wherein the fourth preset flag is used to indicate that the target video is in a read completion state; Finish reading the shared memory block and release the memory resources.
4. The video playback method according to claim 2, characterized in that: Each time the first process accesses the shared memory block, after reading and determining the preset memory flag bit, the method further includes: If the preset memory flag is the third preset identifier, repeatedly reading the preset memory flag; If the number of times that the preset memory flag is repeatedly read to be the third preset identifier exceeds a preset threshold, the reading of the shared memory block is stopped and the memory resources are released.
5. The video playback method according to claim 1, characterized in that: The second process loads and decodes the target video according to the playback information, and sequentially obtains each frame of video frame data of the target video, including: The second process loads the target video according to the playback information; Decoding the target video; When the first frame of video frame data is obtained through decoding, the shared memory block is created, and the memory address of the shared memory block is sent to the first process; The second process writes each frame of video frame data into a shared memory block in sequence, including: The second process writes the first frame of video frame data into the shared memory block.
6. The video playback method according to claim 1, characterized in that: The first process renders each frame of the video frame data sequentially to a display interface to achieve playback, including: The first process obtains the playback area information of the target video; According to the playback area information, each frame of the video frame data of the target video is sequentially rendered into a corresponding playback area, wherein the playback area is within the range of the display interface.
7. The video playback method according to claim 1, characterized in that: The method further comprises: When the second process detects that data cannot be written into the shared memory block, it stops decoding the target video and restarts the process to wait for receiving the next decoding task.
8. A video playback device, characterized in that: include: A sending module, used for the first process to send the playback information of at least one target video to the second process; A decoding module, used for the second process to load and decode the target video according to the playback information, and obtain each frame of video frame data of the target video in sequence; A writing module, used for the second process to write each frame of video frame data into a shared memory block in sequence; A reading module, used for the first process to read each frame of video frame data from the shared memory block in sequence, The rendering module is used for the first process to render each frame of the video frame data sequentially to the display interface to achieve playback.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the video playback method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the video playback method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Streaming media second opening method, system and equipment based on ring buffer
CN122248222A
