Video processing method, video processing device, electronic device and storage medium
By adding a quick index to the inode of the video file and pointing to the storage location of the target data block, the problem of high storage costs for fast playback of video files is solved, and video files are played efficiently in a low-cost storage system.
Patent Information
- Application Number
- CN202410241696.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-04
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-03-04
AI Technical Summary
The prior art requires high storage costs when realizing fast playback of video files, especially streaming file formats and pre-index information file formats, and redundant data space is required to describe the same content, resulting in high storage costs.
When the video file is written to the storage space, the target data block is identified as metadata information, and a quick index is added to the inode based on the information of the target data block, pointing to the storage location of the target data block, realizing the fast playback of the video file, and reading it Metadata information is preferred when fetching.
While keeping the video file structure and format unchanged, the video file is quickly played, reducing the use of storage space and saving storage costs.
Smart Images

Figure CN118158469B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of video processing technology, and in particular to a video processing method, a video processing device, an electronic device and a storage medium. Background Art
[0002] With the popularization of the Internet, more and more users have the demand for online video playback. In order to better achieve the effect of video playback, the player often needs to meet the requirement of fast playback when playing video files online so that users can have a better user experience.
[0003] The principle of fast playback is that the player can quickly obtain index information (such as metadata information of the video file) to decode the video file, thereby determining the structure of the video file and the location of each data block in the file for easy playback and parsing. Streaming file formats or file formats with pre-indexed information can pre-place index information so that the player can quickly obtain index information, thereby achieving fast playback.
[0004] However, for the file system of the device, if you want to achieve fast playback of video files through the above two file formats, you need to pay a certain storage cost. For example, for the streaming file format, it has a fixed data packet header format, which requires redundant data space to describe the same content, and also needs to rely on other index information to achieve fast playback; and for the file format with pre-index information, it is necessary to reserve space for index information at the beginning of the file, and the recorded audio and video information starts to be written after the reserved space. When the file recording is finished, go back to the beginning of the file to fill the index information into the reserved space, that is, this method also requires redundant data space.
[0005] To this end, the device often requires a large amount of redundant data space. For storage systems with limited storage costs, the cost is high and it is difficult to achieve fast playback of video files. Summary of the invention
[0006] The present application provides a video processing method, a video processing device, an electronic device and a storage medium, which solves the problem in the related art that high storage costs are required to achieve fast playback of video files. The present solution can easily achieve fast playback of video files while occupying less storage space.
[0007] In a first aspect, the present application provides a video processing method, the method comprising:
[0008] In the process of writing the recorded video into the storage space, identifying a target data block in the generated video file, the target data block being used to store metadata information of the video file;
[0009] In the case where the target data block is located at the end of the video file, a quick index is added to the index node corresponding to the video file based on the data block information of the target data block, and the quick index is used to point to the storage location of the target data block in the storage space;
[0010] When receiving a play instruction or a read instruction for a target video file, accessing a target index node corresponding to the target video file, and searching for a target quick index in the target index node to determine whether the target quick index exists;
[0011] When a target quick index exists in the target index node, the storage location pointed to by the target quick index is used as the starting position for reading the target video file, so as to play the target video file or read the file and output the first video file. The data block pointed to by the target quick index in the format of the first video file is used as the initial data block.
[0012] Therefore, the device can add a quick index to the index node corresponding to the video file to point to the storage location of the target data block in the video file in the storage space, and keep the structure and format of the video file unchanged. Then, when reading the video file, the quick index can be used to preferentially read the metadata information of the video file, thereby realizing the fast playback of the video file. In addition, the quick index in the scheme occupies less storage space. For a storage system with limited storage cost, it can realize the fast playback of the video file at a relatively low cost. Moreover, when outputting the first video file, the device will use the data block carrying the metadata information in the first video file as the initial data block of the first video file, so that other devices can also achieve the effect of fast start when playing the first video file.
[0013] In some embodiments, the interface for performing file operations includes a write interface and a close interface; in the process of writing the recorded video into the storage space, identifying a target data block in the generated video file, the target data block is used to store metadata information of the video file, including:
[0014] Call the write interface to read and parse the video file to find the target data block;
[0015] When it is determined that the target data block is located at the end of the video file, identification information is transmitted to the close interface, where the identification information is used to indicate that the target data block exists in the video file.
[0016] Therefore, the device can call the write interface to parse the video file, so as to quickly find the target data block in the video file, so as to generate a fast index.
[0017] In some embodiments, calling a write interface to read and parse a video file to find a target data block includes:
[0018] Based on the write interface, read the size character and type character of each data block in the video file;
[0019] When the size character and the type character corresponding to the current data block are the same as the size character and the type character corresponding to the target data block, it is determined that the target data block exists.
[0020] In some embodiments, when the target data block is located at the end of the video file, a quick index is added to the index node corresponding to the video file based on the data block information of the target data block, and the quick index is used to point to the storage location of the target data block in the storage space, including:
[0021] Call the close interface to read the data block information of the identified target data block, and search for the index node corresponding to the video file in the storage space;
[0022] Based on the data block information, a quick index of the corresponding target data block is generated through the close interface, and the quick index is added to the index node.
[0023] Therefore, after identifying the target data block, the device adds the generated quick index to the index node so that when reading the video file, the target data can be read preferentially according to the storage location pointed to by the quick index, thereby realizing fast playback of the video file.
[0024] In some embodiments, the data block information of the target data block includes a first address and a data block capacity of the target data block;
[0025] Based on the data block information, a quick index of the corresponding target data block is generated through the close interface, and a quick index is added to the index node, including:
[0026] Pointing the pointer of the fast index to the first address of the target data block, and recording the data block capacity of the target data block in the index information of the fast index, so as to obtain the fast index;
[0027] Add the resulting quick index in the index node.
[0028] In some embodiments, when a target quick index exists in a target index node, a storage location pointed to by the target quick index is used as a starting location when reading a target video file, so as to play the target video file or read the file and output a first video file, and a data block pointed to by the target quick index in a format of the first video file is used as an initial data block, including:
[0029] Obtaining the first address of the target data block pointed to by the target quick index in the storage space and the data block capacity of the target data block;
[0030] Based on the head address, the target data block is set at the starting position in the reading order to preferentially read the data stored in the target data block;
[0031] Based on the data block capacity, other data blocks of the target video file are arranged after the target data block in the reading order.
[0032] Therefore, in the reading order, the target data block is the beginning of the file, and the device will rearrange other data blocks according to the data block capacity of the target data block in the reading order to arrange other data blocks after the target data block. As a result, the device can first obtain the metadata information of the video file, thereby realizing fast playback of the video file.
[0033] In some embodiments, based on the data block capacity, arranging other data blocks of the target video file after the target data block in the reading order includes:
[0034] Determine the read offset according to the data block capacity of the target data block;
[0035] According to the read offset, other data blocks of the target video file are offset in the reading order.
[0036] Therefore, while maintaining the original structure and format of the video file, this solution can give priority to reading the target data block in the video file during the reading process to obtain the metadata information of the video file, thereby achieving fast playback of the video file.
[0037] In a second aspect, the present application further provides a video processing device, the device comprising:
[0038] A data writing module is configured to identify a target data block in a generated video file during a process of writing the recorded video into a storage space, the target data block being used to store metadata information of the video file;
[0039] An index generation module, configured to add a quick index in an index node corresponding to the video file based on data block information of the target data block when the target data block is located at the end of the video file, wherein the quick index is used to point to a storage location of the target data block in the storage space;
[0040] The data access module is configured to access a target index node corresponding to the target video file and search for a target quick index in the target index node to determine whether the target quick index exists when receiving a play instruction or a read instruction for the target video file.
[0041] The video playback module is configured to use the storage location pointed to by the target quick index as the starting position for reading the target video file when there is a target quick index in the target index node, so as to play the target video file or read the file and output the first video file, and the data block pointed to by the target quick index in the format of the first video file is used as the initial data block.
[0042] In a third aspect, the present application further provides an electronic device, comprising:
[0043] one or more processors;
[0044] a storage device for storing one or more programs,
[0045] When one or more programs are executed by one or more processors, the one or more processors implement the video processing method of the present application.
[0046] In a fourth aspect, the present application also provides a storage medium storing computer executable instructions, which are used to execute the video processing method of the present application when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A schematic diagram of the steps of a video processing method provided in one embodiment of the present application;
[0048] Figure 2 A schematic diagram of the steps of identifying a target data block provided in an embodiment of the present application;
[0049] Figure 3 A schematic diagram of the steps of adding a quick index provided in an embodiment of the present application;
[0050] Figure 4 This is a schematic diagram of the steps of reading a target video file in one embodiment of the present application;
[0051] Figure 5 A logical diagram of the physical storage location corresponding to the video file (MP4 format) in the storage space of the device;
[0052] Figure 6 A schematic diagram of the structure of a video processing device provided in one embodiment of the present application;
[0053] Figure 7 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0054] The embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are only used to explain the embodiments of the present application, rather than to limit the embodiments of the present application. It should also be noted that, for ease of description, only the parts related to the embodiments of the present application rather than all structures are shown in the accompanying drawings, and those skilled in the art should be able to think of it after reading the specification of this application that as long as the technical features do not contradict each other, any combination of the technical features can constitute an optional implementation method.
[0055] The terms "first", "second", etc. in the specification and claims of the present application 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 interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally a class, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally represents that the objects associated with each other are in an "or" relationship. In the description of the present application, "multiple" means two or more, and "several" means one or more.
[0056] Electronic devices such as integrated recorders (hereinafter referred to as devices) are equipped with corresponding operating systems, such as Linux systems, Ubuntu systems, etc. The devices provide users with operations such as creating, storing, reading, modifying, and dumping files, and controlling file access through the file system provided on them. In order to meet the demand for fast playback of video files, the file system of the device in the related art is difficult to achieve the generation of streaming file formats or file formats with pre-index information.
[0057] For example, for streaming file formats, taking TS (Transport Stream) format as an example, it has a fixed data packet header format, which takes up redundant data space to describe the same content. For devices with limited storage costs, it is necessary to sacrifice a certain amount of storage space, and the storage cost is high. Moreover, streaming files in TS format cannot achieve fast positioning (such as jumping to any second of the video for playback), and they often need to rely on other information, such as M3U8 files of HLS (HTTP Live Streaming, HTTP-based adaptive bit rate streaming media transmission) protocol.
[0058] For another example, the modification method of the conventional file format is to prepend the index information to the beginning of the file. Taking the MP4 video file as an example, since the index information of the MP4 video file is stored in the moov box data block, and the moov box data block is located at the end of the file, it cannot meet the file format requirements for online playback.
[0059] Therefore, one way to modify a video file in MP4 format is to regenerate a new file from the recorded video file through post-processing, and then put the index information in front of the new file. This method is equivalent to performing one more write operation on the file, but in the case where the recorded video generates a large number of large files, repeated and multiple write operations will reduce the life of the disk.
[0060] Another method is to reserve space for index information at the beginning of the file in advance, write the recorded video file from the reserved position, and then return to the beginning of the file to add the index information. However, this method cannot accurately predict the size of the index information, and usually requires more space to ensure that the index information can be fully stored. Therefore, it is easy for the space required for the index information to be much smaller than the reserved space. For devices with limited storage costs, it requires more redundant storage space, which results in higher storage costs.
[0061] In this regard, the present application provides a video processing method, such as Figure 1 As shown, Figure 1 This is a schematic diagram of the steps of a video processing method provided in an embodiment of the present application. When the method is used in the above-mentioned device, a quick index can be added to the index node corresponding to the video file to point to the storage location of the metadata information in the video file in the storage space through the quick index. Therefore, when reading the video file, the device can give priority to reading the storage location pointed to by the quick index, that is, give priority to reading the metadata information of the video file, thereby realizing fast playback of the video file, and occupying less storage space. Compared with the solutions of the related technology, this solution can save the storage cost of the device. The specific steps are as follows:
[0062] Step S110: In the process of writing the recorded video into the storage space, a target data block in the generated video file is identified, where the target data block is used to store metadata information of the video file.
[0063] After the user turns on video recording through the application in the device, the data generated when the device records the video will first be stored in the device's cache, and then stored in a storage device, such as a hard disk, to complete the generation and storage of the video file.
[0064] Furthermore, after the video recording is finished, the device will identify the information of the video file while writing the recorded video into the storage space, so as to identify the target data block in the video file used to store the metadata information of the video file. For example, for a video file in MP4 format, its index information is stored in the data block moov box at the end of the file. The data block moov box does not store specific media data, but stores the metadata information of the video file, that is, the data block moov box serves as the target data block of the video file in MP4 format. After the player obtains the data block moov box, the player can obtain the structure of the video file and the position of each data block for parsing and playback. Therefore, in the case where the generated video file is in MP4 format, the file system of the device can identify whether the data block moov box exists at the end of the video file.
[0065] Step S120: When the target data block is located at the end of the video file, a quick index is added to the index node corresponding to the video file based on the data block information of the target data block, and the quick index is used to point to the storage position of the target data block in the storage space.
[0066] In the Linux system, applications complete basic file operations, such as opening files, closing files, and reading files, by calling the file operation interfaces provided by the system (such as the open interface, close interface, write interface, and read interface, etc.). In addition, in the Linux system, the access to disk data and other operations are implemented through the index node inode. It can be understood that the smallest unit of data is a block. The data blocks of large files are often not continuous in the storage space, but are stored discretely in various locations on the disk. The index node inode can mark the data block address of the file, so that the application can read the file continuously. That is, when the application reads the file, the device's file system can continuously traverse the data blocks according to the file pointer provided by the index node inode, so as to read the corresponding data and return it to the application.
[0067] When the device determines that the target data block is at the end of the video file, the file system thereon generates a quick index according to the data block information of the target data block. It can be imagined that the data block information of the target data block includes the storage position of the target data block in the storage space and the size of the target data block. Furthermore, the file system of the device can add the generated quick index to the index node inode corresponding to the video file, thereby using the quick index to point to the storage position of the target data block in the storage space, so that when reading data, the file system can preferentially return the data in the target data block to the application.
[0068] Step S130: when a play instruction or a read instruction for a target video file is received, a target index node corresponding to the target video file is accessed, and a target quick index is searched in the target index node to determine whether the target quick index exists.
[0069] It is conceivable that the play instruction may be initiated by the user through an application (such as a player), and the application may pass the play instruction to the file system so that the file system can perform file operations on the corresponding video file.
[0070] In addition, the video file to be played specified in the play instruction is used as the target video file. After determining the target video file, the file system of the device accesses the target index node corresponding to the target video file, and then searches the target quick index in the target index node to determine whether the target quick index exists in the target index node. It can be understood that the quick index can be used as a pointer to the file entity in the index node. Therefore, the file system determines the storage location of the data block to be read by searching the target quick index in the target index node.
[0071] Step S140: When a target quick index exists in the target index node, the storage location pointed to by the target quick index is used as the starting position for reading the target video file, so as to play the target video file or read the file and output the first video file. The data block pointed to by the target quick index in the format of the first video file is used as the initial data block.
[0072] After finding the target quick index, the device's file system can determine the storage location corresponding to the data block pointed to by the target quick index through analysis, and then in the process of reading the video file, use the storage location pointed to by the target quick index as the starting position of the target video file in the reading order, thereby giving priority to reading the data block pointed to by the target quick index to read and play the target video file.
[0073] It is worth noting that after the target video file is stored, the storage location of each data block in the target video file has not changed. The data block pointed to by the target quick index stores the metadata information of the target video file. In this regard, in the process of reading the target video file, the data block pointed to by the target quick index is read first. The file system can first feedback the metadata information of the target video file to the application, so that the application can parse and determine the structure of the target video file and the storage location of each data block, thereby achieving the effect of fast playback without the file system having to read all the data blocks of the target video file before starting to play. It can be imagined that after reading the data block pointed to by the target quick index, the file system can read the information of other data blocks in sequence to play the corresponding video through the application.
[0074] In addition, when the target video file needs to be copied or uploaded, that is, when a read instruction for the target video file is received, the local device will also search the target quick index for the target video file, so that when the target quick index exists in the target index node of the target video file, the data block pointed to by the target quick index is read preferentially. Therefore, in the first video file output to other devices, the data block pointed to by the target quick index is used as the initial data block of the first video file. It can be imagined that the data block pointed to by the target quick index is a data block storing metadata information of the video file, and then, in the first video file, the data block located at the initial position of the file (i.e., the initial data block) is a data block for storing metadata information of the file. Therefore, when other devices play the first video file, they can first read the metadata information of the file, thereby realizing fast playback of the first video file.
[0075] It can be seen from the above scheme that this scheme expands a new quick index in the index node through the file system to point to the storage location of the target data block in the video file in the storage space. When the device reads the video file, it can search for the quick index to give priority to reading the metadata information of the video file, which helps to achieve fast playback of the video file. At the same time, there is no need for additional redundant data space to modify the file structure. Compared with the scheme provided by the related technology, this scheme occupies less storage space and helps to save the storage cost of the device.
[0076] Figure 2 A schematic diagram of steps for identifying a target data block provided in an embodiment of the present application is shown in the figure. When identifying a target data block in a video file, the device can quickly search for the target data block by calling an interface for performing file operations. For example, the interface for performing file operations provided by the device includes a write interface and a close interface. The specific steps are as follows:
[0077] Step S210: calling the write interface to read and parse the video file to find the target data block.
[0078] Step S220: When it is determined that the target data block is located at the end of the video file, identification information is transmitted to the close interface, where the identification information is used to indicate that the target data block exists in the video file.
[0079] It is understandable that the write interface can write data to a file. In the process of writing the recorded video to the storage space, the device can call the write interface to write the audio and video data of the recorded video to the storage space, thereby generating a corresponding video file. In the writing process, the device can call the write interface to parse the video file, thereby quickly finding the target data block in the video file, so as to generate a quick index.
[0080] Exemplarily, taking a video file in MP4 format as an example, the metadata information is stored in the data block moov box in the video file. The device can call the write interface to identify and locate the box structure and attributes in which it is located, such as using the size character size and type character type. The device can locate the storage position of the data block by the size character size. When the size character size is 0, the corresponding data block is the last data block of the file. Moreover, the size character size is located in the first 4 bytes of the data block, and the type character type is located after the size character size. The type character type of each data block is predefined, including "ftyp", "moov", etc. Therefore, the device can obtain the size character and type character of each data block in the video file in MP4 format by calling the write interface, and then compare them with the size character and type character corresponding to the data block moov box.
[0081] It can be imagined that in the MP4 format video file, the data block moov box is the last data block of the file, and its type character is moov. Therefore, the size character and type character corresponding to the data block moov box as the target data block in the MP4 format video file can be determined.
[0082] When the size character and type character corresponding to the current data block are the same as the size character and type character corresponding to the target data block, that is, the size character of the current data block is the same as the size character of the data block moov box, and the type character of the current data block is the same as the type character of the data block moov box, it is determined that there is a target data block storing metadata information of the video file in the current video file, that is, for a video file in MP4 format, the device can find the data block moov box at the end of the video file.
[0083] When it is determined that the target data block is located at the end of the video file, identification information for identifying the existence of the target data block in the video file is transmitted to the close interface accordingly. It is conceivable that the device can transmit the identification information to the close interface through the write interface.
[0084] It should be noted that, in some embodiments, the device may call the write interface to directly read the last data block of the file to determine whether the data block is the target data block storing metadata information of the video file, thereby realizing the search for the target data block.
[0085] Figure 3 A schematic diagram of the steps for adding a quick index provided in an embodiment of the present application. In an embodiment, the device can add a quick index in an index node corresponding to a video file through an interface for performing file operations, such as through a close interface. The specific steps are as follows:
[0086] Step S310: calling the close interface to read the data block information of the identified target data block, and searching the index node corresponding to the video file in the storage space.
[0087] Step S320: Based on the data block information, generate a quick index corresponding to the target data block through the close interface, and add the quick index to the index node.
[0088] It is understandable that after the device completes writing the video file, it can call the close interface to close the file, and in the process of calling the close interface, after determining that the target data block exists, the device can read the data block information of the target data block through the close interface. The data block information includes the first address and data block capacity of the data block, that is, the location of the data block in the storage space and the size of the data block can be determined through the data block information. Therefore, the device can determine the storage location of the target data block in the storage space and the size of the target data block based on the data block information of the target data block.
[0089] After finding the index node corresponding to the video file, the device can call the close interface to generate a quick index of the corresponding target data block. It can be imagined that the data block information of the target data block includes the first address and data block capacity of the target data block. Accordingly, in one embodiment, the pointer of the generated quick index can point to the first address of the target data block, so that when reading the video file, the storage position of the target data block in the storage space can be located by reading the quick index. In addition, the data block capacity of the target data block is also recorded in the index information corresponding to the quick index, so that the size of the target data block can be determined when reading. After determining the information of the quick index, add the quick index to the index node corresponding to the video file, so that the quick index can be read during the process of reading the video file, and then the target data block is read preferentially.
[0090] Therefore, after identifying the target data block, the device adds the generated quick index to the index node so that when reading the video file, the target data can be read preferentially according to the storage location pointed to by the quick index, thereby realizing fast playback of the video file.
[0091] In the related art, the device reads the data blocks in sequence according to the file pointer provided by the index node, that is, there is a reading order for reading all the data blocks in the corresponding video file, so that all the data blocks of the video file are read in sequence according to the reading order. For example, for a video file in MP4 format, the reading order in the related art is to read from the beginning of the file to the end of the file, that is, from the first data block of the file to the last data block (that is, the data block moov box).
[0092] The present application solution adds a quick index in the index node to implement priority reading of the target data block by pointing to the storage location of the target data block. Figure 4 As shown, Figure 4 The following is a schematic diagram of the steps for reading a target video file in an embodiment of the present application. In response to a play instruction for a target video file, the device accesses a target index node corresponding to the target video file, and then searches for a target quick index in the target index node, so that if a target quick index exists in the target index node, the target data block pointed to by the target quick index is preferentially read. The specific steps are as follows:
[0093] Step S410: Obtain the first address of the target data block pointed to by the target quick index in the storage space and the data block capacity of the target data block.
[0094] Step S420: Based on the head address, the target data block is set at the starting position in the reading order to preferentially read the data stored in the target data block.
[0095] Step S430: Based on the data block capacity, arrange other data blocks of the target video file after the target data block in the reading order.
[0096] It is understandable that the target quick index records the first address of the target data block in the storage space and the data block capacity of the target data block. When accessing the target quick index, the device obtains the first address and data block capacity of the target data block, and then sets the target data block at the starting position in the reading order. That is, in the case of the existence of a target quick index, the file pointer provided by the index node first points to the first address of the target data block, so that in the reading order of each data block of the target video file, the device will give priority to reading the data stored in the target data block. Therefore, in the reading order, the target data block is the beginning of the file, and the device will rearrange other data blocks according to the data block capacity of the target data block in the reading order, so as to arrange other data blocks after the target data block, and then for the device, it can first obtain the metadata information of the video file, thereby realizing the fast playback of the video file.
[0097] In addition, when the device responds to the read instruction of the target video file, it will also access the target index node corresponding to the target video file, so as to read the data block pointed to by the target quick index when there is a target quick index in the target index node. The device will also output the first video file to other devices. The first video file is read and output in the above-mentioned reading order, that is, the data block storing the metadata information in the first video file is used as the initial data block of the first video file. It can be imagined that when other devices play the first video file, they can first read the metadata information of the file, thereby obtaining the file structure of the first video file, and then can realize the fast playback of the video.
[0098] Therefore, when outputting video files to other devices, this device can place the data block carrying metadata information at the starting position of the video file, so that other devices can quickly obtain the metadata information of the video file when playing the video file, allowing other devices to quickly play the video file.
[0099] In one embodiment, when the device plays or reads the target video file, it determines the reading offset of other data blocks in the reading order according to the data block capacity of the target data block, and then the device can offset the other data blocks in the target video file except the target data block according to the reading offset, that is, the device offsets the other data blocks in the reading order according to the size of the target data block, thereby offsetting the other data blocks in the reading order to after the target data block.
[0100] For example, if the data block capacity of the target data block is 2MB, then in the reading order, the data block starting position of other data blocks is changed to a position that is offset 2MB from the original position. Therefore, in the reading order, for the application, the first 2MB of the data it reads is the data of the target data block, followed by the data of other data blocks.
[0101] It is understandable that, except for the target data block which will be read first, the other data blocks of the target video file are read in the original order. For example, data block I is the first data block in the storage order of the target video file. In the reading order, data block I is located in the next order of the target data block, that is, data block I is the second data block to be read. Data block II is the next data block of data block I in the storage order. It is also located in the next order of data block I in the reading order, that is, data block II is the third data block to be read.
[0102] Therefore, in the present solution, the device can preferentially read the target data block in the video file during the reading process to obtain the metadata information of the video file, thereby realizing fast playback of the video file.
[0103] For example, for video files in container formats, such as MP4 format and MKV format, when reading the file, the metadata information serving as index information cannot be obtained preferentially, that is, the effect of fast playback cannot be achieved. The present application scheme can process this type of video file so that it can be played quickly. The present application scheme is explained below using the MP4 format video file as an example.
[0104] Figure 5 The figure is a logical diagram of the physical storage location corresponding to the video file (MP4 format) in the storage space of the device. Among them, data block m is the data block moov box to record the metadata information of the video file. It can be understood that in terms of storage location, data block 1, data block 2, ..., data block n and data block m are not necessarily continuous. For ease of understanding, the figure takes the entire file as a whole.
[0105] Data block 1 is the first data block in the file, and data block m is the last data block in the file. In the related art, the video file needs to be read sequentially from data block 1 to data block m, that is, the reading order is data block 1, data block 2, ..., data block m. Therefore, the application (such as a player) needs to read the video file completely before obtaining the metadata information recorded in data block m.
[0106] In the solution of the present application, for the data block m (ie, the data block moov box) in the video file, a quick index is added to the index node corresponding to the video file, and the quick index points to the storage location of the data block m in the storage space.
[0107] Furthermore, when reading the video file, the file system of the device can first read the metadata information in data block m, and then complete the reading of data blocks 1 to n in sequence, that is, the reading order is data block m, data block 1, ..., data block n, ..., data block m-1 (not shown in the figure). Therefore, the player can obtain the metadata information of the video file at the beginning of reading the video file, without having to read the video file completely before obtaining the metadata information of the video file.
[0108] It can be seen that for video files in MP4 format, the present application solution does not need to reserve additional data space when writing them into the storage space, but instead maintains the original structure and format of the file. When reading, it can give priority to reading the data block moov box as the target data block, so that the player can play the video file quickly. That is, the solution achieves the effect of fast playback of video files while not requiring redundant data space. Compared with the solutions provided by related technologies, the present application solution occupies less storage space, which helps to save the storage cost of the device.
[0109] Similarly, taking a video file in MP4 format as an example, when the first video file needs to be output to other devices, this device sets a quick index in the index node of the video file when storing the video file to point to the data block m (i.e., data block moov box) of the video file. Due to the setting of the quick index, when reading the video file, this device will give priority to reading data block m, and then read other data blocks, such as reading data blocks 1 to data blocks n in sequence. Furthermore, when outputting the first video file, data block m is located at the starting position of the first video file, and other data blocks are arranged in sequence after data block m. Therefore, when other devices play the first video file, they can quickly obtain the metadata information of the file, and then can quickly play the first video file.
[0110] Figure 6 This is a schematic diagram of the structure of a video processing device provided in one embodiment of the present application. The device is used to execute the video processing method provided in the above embodiment and has the functional modules and beneficial effects required for executing the method. Figure 6 As shown, the device includes a data writing module 601, an index generating module 602, a data access module 603 and a video playing module 604.
[0111] The data writing module 601 is configured to identify a target data block in the generated video file during the process of writing the recorded video into the storage space, the target data block being used to store metadata information of the video file;
[0112] The index generation module 602 is configured to add a quick index in an index node corresponding to the video file based on the data block information of the target data block when the target data block is located at the end of the video file, wherein the quick index is used to point to the storage location of the target data block in the storage space;
[0113] The data access module 603 is configured to access the target index node corresponding to the target video file and search the target quick index in the target index node to determine whether the target quick index exists when receiving a play instruction or a read instruction for the target video file;
[0114] The video playback module 604 is configured to use the storage location pointed to by the target quick index as the starting position for reading the target video file when there is a target quick index in the target index node, so as to play the target video file or read the file and output the first video file, and the data block pointed to by the target quick index in the format of the first video file is used as the initial data block.
[0115] Based on the above embodiment, the interface for performing file operations includes a write interface and a close interface, and the data writing module 601 is further configured as follows:
[0116] Call the write interface to read and parse the video file to find the target data block;
[0117] When it is determined that the target data block is located at the end of the video file, identification information is transmitted to the close interface, where the identification information is used to indicate that the target data block exists in the video file.
[0118] Based on the above embodiment, the data writing module 601 is further configured as follows:
[0119] Based on the write interface, read the size character and type character of each data block in the video file;
[0120] When the size character and the type character corresponding to the current data block are the same as the size character and the type character corresponding to the target data block, it is determined that the target data block exists.
[0121] Based on the above embodiment, the index generation module 602 is further configured as follows:
[0122] Call the close interface to read the data block information of the identified target data block, and search for the index node corresponding to the video file in the storage space;
[0123] Based on the data block information, a quick index of the corresponding target data block is generated through the close interface, and the quick index is added to the index node.
[0124] Based on the above embodiment, the data block information of the target data block includes the first address and data block capacity of the target data block, and the index generation module 602 is further configured as follows:
[0125] Pointing the pointer of the fast index to the first address of the target data block, and recording the data block capacity of the target data block in the index information of the fast index, so as to obtain the fast index;
[0126] Add the resulting quick index in the index node.
[0127] Based on the above embodiment, the video playback module 604 is further configured as follows:
[0128] Obtaining the first address of the target data block pointed to by the target quick index in the storage space and the data block capacity of the target data block;
[0129] Based on the head address, the target data block is set at the starting position in the reading order to preferentially read the data stored in the target data block;
[0130] Based on the data block capacity, other data blocks of the target video file are arranged after the target data block in the reading order.
[0131] Based on the above embodiment, the video playback module 604 is further configured as follows:
[0132] Determine the read offset according to the data block capacity of the target data block;
[0133] According to the read offset, other data blocks of the target video file are offset in the reading order.
[0134] It is worth noting that in the embodiment of the above-mentioned video processing device, each module is only divided according to functional logic, but is not limited to the above-mentioned division, as long as the corresponding functions can be realized; in addition, the specific name of each module is only for the convenience of distinguishing each other, and is not used to limit the scope of protection of this application.
[0135] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the device is used to execute the video processing method provided in the above embodiment, and has functional modules and beneficial effects corresponding to the execution method. As shown in the figure, the device includes a processor 701, a memory 702, an input device 703 and an output device 704. The number of processors 701 can be one or more, and one processor 701 is taken as an example in the figure; the processor 701, the memory 702, the input device 703 and the output device 704 can be connected by a bus or other means, and the figure takes the connection through a bus as an example. The memory 702, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the video processing method in the embodiment of the present application. The processor 701 executes various corresponding functional applications and data processing by running the software programs, instructions and modules stored in the memory 702, that is, realizing the above-mentioned video processing method.
[0136] The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data recorded or created during use, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 702 may further include a memory remotely arranged relative to the processor 701, and these remotely arranged memories may be connected to the terminal device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0137] The input device 703 can be used to input corresponding digital or character information to the processor 701, and to generate key signal input related to the user settings and function control of the device; the output device 704 can be used to send or display key signal output related to the user settings and function control of the device.
[0138] An embodiment of the present application also provides a storage medium storing computer executable instructions, which, when executed by a processor, are used to perform relevant operations in the video processing method provided in any embodiment of the present application.
[0139] Computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0140] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0141] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A video processing method, characterized in that: include: In the process of writing the recorded video into the storage space, identifying a target data block in the generated video file, the target data block being used to store metadata information of the video file; In the case where the target data block is located at the end of the video file, a quick index is added in the index node corresponding to the video file based on the data block information of the target data block, the quick index is used to point to the storage location of the target data block in the storage space, the pointer of the quick index points to the first address of the target data block, and the data block capacity of the target data block is recorded in the index information of the quick index; When receiving a play instruction or a read instruction for a target video file, accessing a target index node corresponding to the target video file, and searching for a target quick index in the target index node to determine whether the target quick index exists; When the target quick index exists in the target index node, the storage location pointed to by the target quick index is used as the starting position for reading the target video file, so as to play the target video file or read the file and output the first video file, and the data block pointed to by the target quick index in the format of the first video file is used as the initial data block.
2. The video processing method according to claim 1, characterized in that: The interfaces for file operations include write interface and close interface; In the process of writing the recorded video into the storage space, identifying a target data block in the generated video file, wherein the target data block is used to store metadata information of the video file, including: Calling the write interface to read and parse the video file to find the target data block; In the case where it is determined that the target data block is located at the end of the video file, identification information is transmitted to the close interface, where the identification information is used to indicate that the target data block exists in the video file.
3. The video processing method according to claim 2, characterized in that: The calling of the write interface to read and parse the video file to find the target data block includes: Based on the write interface, read the size character and type character of each data block in the video file; When the size character and the type character corresponding to the current data block are the same as the size character and the type character corresponding to the target data block, it is determined that the target data block exists.
4. The video processing method according to claim 1 or 2, characterized in that: In the case where the target data block is located at the end of the video file, adding a quick index in an index node corresponding to the video file based on data block information of the target data block, wherein the quick index is used to point to a storage location of the target data block in the storage space, includes: Call the close interface to read the data block information of the identified target data block, and search the index node corresponding to the video file in the storage space; Based on the data block information, a quick index corresponding to the target data block is generated through the close interface, and the quick index is added to the index node.
5. The video processing method according to claim 4, characterized in that: The data block information of the target data block includes the first address and data block capacity of the target data block; The generating a quick index corresponding to the target data block through the close interface based on the data block information and adding the quick index in the index node includes: Pointing the pointer of the fast index to the first address of the target data block, and recording the data block capacity of the target data block in the index information of the fast index to obtain the fast index; The obtained quick index is added in the index node.
6. The video processing method according to claim 1, characterized in that: In the case where the target quick index exists in the target index node, the storage location pointed to by the target quick index is used as the starting position when reading the target video file, so as to play the target video file or read the file and output a first video file, and the data block pointed to by the target quick index in the format of the first video file is used as the initial data block, including: Obtaining a first address of a target data block pointed to by the target fast index in the storage space and a data block capacity of the target data block; Based on the head address, the target data block is set at a starting position in a reading order to preferentially read data stored in the target data block; Based on the data block capacity, other data blocks of the target video file are arranged after the target data block in the reading order.
7. The video processing method according to claim 6, characterized in that: The step of arranging other data blocks of the target video file after the target data block in the reading order based on the data block capacity includes: Determining a read offset according to a data block capacity of the target data block; According to the read offset, other data blocks of the target video file in the read sequence are offset.
8. A video processing device, characterized in that: include: A data writing module, configured to identify a target data block in a generated video file during a process of writing the recorded video into a storage space, wherein the target data block is used to store metadata information of the video file; An index generation module, configured to add a quick index in an index node corresponding to the video file based on data block information of the target data block when the target data block is located at the end of the video file, wherein the quick index is used to point to a storage location of the target data block in the storage space, a pointer of the quick index points to a first address of the target data block, and index information of the quick index records a data block capacity of the target data block; A data access module is configured to, upon receiving a play instruction or a read instruction for a target video file, access a target index node corresponding to the target video file, and search for a target quick index in the target index node to determine whether the target quick index exists; The video playback module is configured to use the storage location pointed to by the target quick index as the starting position for reading the target video file when the target quick index exists in the target index node, so as to play the target video file or read the file and output a first video file, in which the data block pointed to by the target quick index in the format of the first video file is used as the initial data block.
9. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the video processing method as described in any one of claims 1-7.
10. A storage medium storing computer executable instructions, characterized in that: When the computer executable instructions are executed by a processor, they are used to perform the video processing method according to any one of claims 1 to 7.
