Video file detection method and device, electronic equipment and storage medium
By obtaining multimodal information of video files and analyzing them, the frame rate and the duration of each frame are determined, and combined with the time difference between two consecutive frames, the problem of poor portability of video file detection in the prior art is solved, and the rapid and effective detection of video files is achieved to ensure the integrity and authenticity of video content.
Patent Information
- Application Number
- CN202510034260.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-09
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2045-01-09
AI Technical Summary
The prior art is poorly portable when detecting video file corruption, cannot work effectively in separate applications, and cannot be implemented on other third-party applications.
By obtaining multimodal information of the video file, including data size and video stream information, if the data size is greater than the preset threshold, the video stream information is parsed to obtain multi-frame data packets, the frame rate and the duration of each frame are determined based on these data packets, and the time difference between two consecutive frames is obtained to determine the detection result of the video file.
It realizes rapid detection of video files, avoids unnecessary processing of files that are too large or do not meet the requirements, can detect abnormal frames or frame rate changes in video files, ensures the integrity and authenticity of video content, and is suitable for video files of different sizes and formats.
Smart Images

Figure CN119893163A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of video file detection, and in particular to a video file detection method, device, electronic device, and computer-readable storage medium. Background Art
[0002] With the development of technology, USB media file browsing and viewing is a common multimedia entertainment function in the in-vehicle central control entertainment system. Because the sources of local videos are different, and the video files may be damaged to varying degrees due to operational errors during the transfer of various media, various strange problems may occur when displaying the list or playing, so it is necessary to detect whether the video file is damaged as early as possible.
[0003] In the related art, most of them use the ffmpeg command line detection method, but this method requires first integrating the ffmpeg application in the system to support the ffmpeg command line, and then using Runtime in the application to write the string command into the system for execution, wait for completion, read the string result, and then parse the string to determine whether there is an error through specific information in the returned string. However, this method has poor portability and is not portable for a single application, and cannot be implemented on other third-party applications. Therefore, a highly adaptable video file detection method is urgently needed. Summary of the invention
[0004] To solve the above technical problems, the embodiments of the present application provide a video file detection method and device, an electronic device, a computer-readable storage medium, and a computer program product.
[0005] According to one aspect of an embodiment of the present application, a video file detection method is provided, including: obtaining multimodal information of a video file to be detected, the multimodal information including a data size and video stream information of the video file to be detected; if the data size is greater than a preset data size threshold, parsing the video stream information to obtain a parsed multi-frame data packet; determining the frame rate information of the video file to be detected based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information; obtaining the time difference between any two consecutive frames in the video file to be detected, and determining the detection result of the video file to be detected based on the time difference and the duration of each frame.
[0006] According to one aspect of an embodiment of the present application, parsing the video stream information to obtain a parsed multi-frame data packet includes: obtaining basic information of the video stream, the basic information including the duration of the video file to be detected; if the duration is greater than a preset duration threshold, obtaining the screen size of the video in the video stream information; if the screen size is greater than a preset size threshold, parsing the video stream information to obtain a parsed multi-frame data packet.
[0007] According to one aspect of an embodiment of the present application, parsing the video stream information to obtain a parsed multi-frame data packet includes: obtaining a target decoder corresponding to the video stream information to decode the video stream based on the target decoder to obtain a decoded video stream; obtaining a multi-frame data packet from the decoded video stream, wherein the multi-frame data packet includes multiple frames of data constituting the video stream.
[0008] According to one aspect of the embodiment of the present application, the frame rate information of the video file to be detected is determined based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information, including: obtaining the frame rate information in the multi-frame data packet; if the frame rate information is consistent with the actual playback speed of the video file to be detected, determining the frame rate information to be valid frame rate information; and determining the duration of each frame corresponding to the video file to be detected based on the valid frame rate information.
[0009] According to one aspect of an embodiment of the present application, after determining the frame rate information of the video file to be detected based on the multi-frame data packet, and determining the duration of each frame corresponding to the video file to be detected based on the frame rate information, the method also includes: if the duration of any frame in the video file to be detected is less than or equal to zero, obtaining a detection result that the video file to be detected is damaged; if the duration of any frame in the video file to be detected is greater than zero, obtaining the timestamp of each frame in the video file to be detected.
[0010] According to one aspect of an embodiment of the present application, the method of obtaining the time difference between any two consecutive frames in the video file to be detected and determining the detection result of the video file to be detected based on the time difference and the duration of each frame includes: obtaining the timestamps corresponding to each of any two consecutive frames in the video file to be detected; calculating the time difference between any two consecutive frames based on the corresponding timestamps; if the time difference is less than or equal to zero or the time difference is greater than the duration of each frame, obtaining a detection result that the video file to be detected is damaged.
[0011] According to one aspect of an embodiment of the present application, the detection result of the video file to be detected is determined based on the time difference and the duration of each frame, including: if the time difference is greater than zero and the time difference is less than the duration of each frame, then obtaining the timestamp of each frame in the video file to be detected; if the timestamps of each frame show an increasing relationship in time, then obtaining a normal detection result of the video file to be detected.
[0012] According to one aspect of an embodiment of the present application, a video file detection device is provided, the device comprising: an acquisition module, acquiring multimodal information of a video file to be detected, the multimodal information comprising a data size and video stream information of the video file to be detected; a parsing module, parsing the video stream information to obtain a parsed multi-frame data packet if the data size is greater than a preset data size threshold; a determination module, determining the frame rate information of the video file to be detected based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information; a detection module, acquiring the time difference between two consecutive frames in the video file to be detected, and determining the detection result of the video file to be detected based on the time difference and the duration of each frame.
[0013] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the video file detection method as described above.
[0014] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the video file detection method as described above.
[0015] According to one aspect of an embodiment of the present application, a computer program product is also provided, including a computer program, which implements the steps in the video file detection method described above when executed by a processor.
[0016] In the technical solution provided in the embodiments of the present application, by first checking the data size of the video file, unnecessary processing of files that are too large or do not meet the requirements can be avoided, thereby saving computing resources and time. By comparing the time difference between two consecutive frames and the duration of each frame, abnormal frames or frame rate changes in the video file can be detected, which is particularly important for application scenarios such as video monitoring and content review. Anomaly detection can reveal potential problems in video files, such as frame loss, freezes, or editing traces, thereby ensuring the integrity and authenticity of the video content. On the other hand, this solution can process video files of different sizes and formats, enhancing the flexibility and adaptability of the system. This solution can run as a standalone application or be integrated as part of other video processing systems, which allows it to be easily deployed in different application scenarios and work seamlessly with other components.
[0017] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0019] Figure 1 is a schematic diagram of an implementation environment for video file detection shown in an exemplary embodiment of the present application;
[0020] Figure 2 is a flow chart of a video file detection method shown in an exemplary embodiment of the present application;
[0021] Figure 3 is a flow chart of a video file detection method shown in another exemplary embodiment of the present application;
[0022] Figure 4 is a flow chart of a video file detection method shown in another exemplary embodiment of the present application;
[0023] Figure 5 is a flow chart of a video file detection method shown in another exemplary embodiment of the present application;
[0024] Figure 6 is a flow chart of a video file detection method shown in another exemplary embodiment of the present application;
[0025] Figure 7is a flow chart of a video file detection method shown in another exemplary embodiment of the present application;
[0026] Figure 8 is a flow chart of a video file detection method shown in another exemplary embodiment of the present application;
[0027] Fig. 9 It is a schematic diagram of a brief process of detecting video files in a navigation interface in an exemplary application scenario;
[0028] Fig.10 is a block diagram of a video file detection device shown in an exemplary embodiment of the present application;
[0029] Fig.11 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0030] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0031] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0032] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0033] The term "multiple" as used in this application refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0034] FFmpeg is a powerful open source computer program that is specifically designed to handle a variety of tasks such as encoding, decoding, conversion, streaming, filtering, and playback of digital audio and video files. It supports almost all common audio and video formats and can run on multiple operating system platforms including the Android system. The following is a detailed introduction to FFmpeg: The main functions include: Encoding / decoding: FFmpeg supports a variety of audio and video codecs, and can convert files in one format to another; Format conversion: Video and audio files can be converted from one container format to another, such as converting MP4 files to AVI files; Streaming: FFmpeg can be used to create and receive live streaming media, supporting a variety of streaming protocols; Filtering and editing: It provides a wealth of filters and editing functions, which can crop, scale, add watermarks, adjust the volume, and other operations on video and audio; Device compatibility: It can generate video and audio files suitable for various devices and platforms (such as mobile phones, tablets, smart TVs, etc.). In some achievable embodiments of the present application, a method for detecting whether a video file is damaged using java / kotlin code can be implemented in an Android system based on the ffmpeg library through JNI (Java Native Interface) technology, which is a programming framework, thereby taking into account portability and versatility.
[0035] Figure 1 FIG. 1 is a schematic diagram of an implementation environment for performing video file detection on a locally stored video file, shown in an exemplary embodiment of the present application. Figure 1 As shown, a video file is stored on the local memory 110, and the multimodal information of the video file to be detected on the local memory 110 can be obtained through the server 120, wherein the multimodal information can include the data size and video stream information of the video file to be detected. If the server 120 detects that the data size of the video file to be detected is greater than a preset data size threshold, the video stream information can be further parsed to obtain a parsed multi-frame data packet, and then the frame rate information of the video file to be detected can be determined according to the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information; thereafter, the server 120 obtains the time difference between two consecutive frames in the video file to be detected, and determines the detection result of the video file to be detected based on the time difference and the duration of each frame, thereby realizing the detection of the local video file.
[0036] in, Figure 1 The server end 120 shown can be any terminal device that supports the installation of navigation map software, such as a smart phone, a car computer, a tablet computer, a laptop computer, or a wearable device, but is not limited thereto.
[0037] In the related art, most of them use the ffmpeg command line detection method, but this method requires first integrating the ffmpeg application in the system to support the ffmpeg command line, and then using Runtime in the application to write the string command into the system for execution, wait for completion, read the string result, and then parse the string to determine whether there is an error through specific information in the returned string. However, this method has poor portability and is not portable for a single application, and cannot be implemented on other third-party applications.
[0038] The problems pointed out above are generally applicable in general local video file detection. Therefore, in order to solve these problems, the embodiments of the present application respectively propose a video file detection method, a video file detection device, an electronic device, a computer-readable storage medium and a computer program product. These embodiments will be described in detail below.
[0039] See also Figure 2 , Figure 2 is a flowchart of a video file detection method shown in an exemplary embodiment of the present application, which can be applied to Figure 1 The implementation environment shown in FIG. 1 is specifically executed by the smart server 120 in the implementation environment. It should be understood that the method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments. This embodiment does not limit the implementation environment to which the method is applicable.
[0040] like Figure 2 As shown, in an exemplary embodiment, the video file detection method includes at least steps S210 to S240, which are described in detail as follows:
[0041] Step S210, obtaining multimodal information of the video file to be detected, where the multimodal information includes the data size and video stream information of the video file to be detected.
[0042] Exemplarily, the data size of a video file can be obtained through the attribute information of the file system. In most operating systems, the file manager or command line tool can display the size of a file. For example, in Windows, you can right-click a file and select "Properties" to view the file size; in Linux or macOS, you can use the ls -lh command to list files and their sizes. If you need to obtain the size of a video file programmatically, you can choose a suitable file processing library. For example, in Python, you can use the os.path.getsize() function in the os library to obtain the size of the file (in bytes), and then convert it to a more appropriate unit (such as KB, MB, etc.) as needed.
[0043] Video stream information usually includes the video encoding format, resolution, frame rate, bit rate, etc. This information is crucial for video processing and analysis. Obtaining video stream information can be achieved through a dedicated video processing library or tool, or you can use FFmpeg commands to obtain detailed video stream information.
[0044] Step S220: If the data size is greater than a preset data size threshold, the video stream information is parsed to obtain a parsed multi-frame data packet.
[0045] For example, a preset data size threshold of the video file to be detected can be set according to actual business needs, and the size of the video file can be easily obtained by using the API or command of the file system (such as the os.path.getsize() function in Python). The obtained file size is compared with the preset threshold to determine whether the video stream information needs to be further parsed. FFmpeg is a powerful open source tool that can parse multiple video formats and extract video frames.
[0046] Run FFmpeg command: To extract video frames, you need to run a specific FFmpeg command. For example, you can extract a frame from a video at a certain time interval: According to actual needs, you can adjust the FPS (frames per second) value, or change the format and naming of the output file.
[0047] Processing and parsing results: After the FFmpeg command is executed, a series of image files will be found in the specified directory, which represent the multi-frame data packets extracted from the video.
[0048] Step S230, determining the frame rate information of the video file to be detected based on the multi-frame data packets, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information.
[0049] Exemplarily, first, some key information needs to be obtained from the previously extracted multi-frame data packets (usually picture files). However, the frame rate cannot be directly read directly from these picture files because the frame rate information is embedded in the original video file. But you can use the information that FFmpeg has already obtained when extracting frames, or rerun the FFmpeg command to get the frame rate. The frame rate (Frames Per Second, FPS) represents the number of frames played per second. Therefore, the duration of each frame (in seconds) can be calculated by dividing 1 second by the frame rate. Once the frame rate is known (for example, 25FPS), the duration of each frame can be calculated. For a 25FPS video, the duration of each frame is 1 / 25 second or 0.04 seconds.
[0050] Step S240, obtaining the time difference between two consecutive frames in the video file to be detected, and determining the detection result of the video file to be detected based on the time difference and the duration of each frame.
[0051] For example, in order to obtain the actual time difference between two consecutive frames, it may be necessary to parse the video stream more deeply. This usually involves a detailed understanding of video encoding, because inter-frame delays or jumps may be introduced during the encoding process. Tools such as FFmpeg can provide timestamp information for each frame, which can be used to calculate the time difference between two consecutive frames. In order to determine the detection result of the video file, a time difference threshold needs to be set. This time difference threshold can be set according to the expected frame rate of the video file, the application scenario, or the user's requirements. The calculated time difference between two consecutive frames is compared with the set threshold. If the time difference exceeds the threshold, it may indicate that there is frame loss, frame duplication, or encoding problems in the video file. Based on the comparison results, the detection result of the video file is generated. This may include marking the inter-frame time difference that exceeds the threshold, calculating the overall quality score of the video file, or providing other relevant information.
[0052] In some embodiments of the present application, by first checking the data size of the video file, unnecessary processing of files that are too large or do not meet the requirements can be avoided, thereby saving computing resources and time. By comparing the time difference between two consecutive frames and the duration of each frame, abnormal frames or frame rate changes in the video file can be detected, which is particularly important for application scenarios such as video monitoring and content review. Anomaly detection can reveal potential problems in video files, such as frame loss, freezes, or editing traces, thereby ensuring the integrity and authenticity of the video content. On the other hand, this solution can process video files of different sizes and formats, enhancing the flexibility and adaptability of the system. This solution can run as a standalone application or be integrated as part of other video processing systems, which allows it to be easily deployed in different application scenarios and work seamlessly with other components.
[0053] Based on the above embodiments, please refer to Figure 3 In one of the exemplary embodiments provided in the present application, the specific implementation process of parsing the video stream information to obtain the parsed multi-frame data packets may also include steps S310 to S330, which are described in detail as follows:
[0054] Step S310, obtaining basic information of the video stream, the basic information including the duration of the video file to be detected;
[0055] Step S320, if the duration is greater than the preset duration threshold, obtaining the screen size of the video in the video stream information;
[0056] Step S330: If the picture size is greater than a preset size threshold, the video stream information is parsed to obtain a parsed multi-frame data packet.
[0057] Exemplarily, multimedia processing tools such as FFmpeg are used to analyze video files to obtain their basic information, which generally includes the encoding format, bit rate, frame rate, duration, etc. of the video. If the duration is lower than a preset duration threshold, wherein the preset duration threshold may be a reasonable duration threshold set according to actual business needs, wherein the preset duration threshold may also be zero, then the extracted video duration is compared with the preset duration threshold, if the duration of the video file does not exceed the preset duration threshold, it is proved that the video file is damaged, if the duration of the video file exceeds the preset duration, then the screen size of the video in the video stream is obtained, for example, the length and width of the screen, and then the length and width of the screen are compared with the preset length and width thresholds, wherein the length and width thresholds may be zero, if either the length and width of the screen is zero, then the detection result of the damage of the video file is obtained, if the size of the screen of the video stream exceeds the preset size threshold, then the video stream information may be further parsed to obtain the parsed multi-frame data packet.
[0058] Optionally, FFmpeg can also be used to implement the specific operation process. For example, from the output of FFmpeg, find the field indicating the duration of the video (such as Duration), and in the output of FFmpeg, find the field indicating the size of the video screen (such as width and height). If the duration and screen size of the video exceed the preset threshold, you can build an FFmpeg command for extracting video frames according to demand. For example, you can use the ffmpeg-iinput_video.mp4frame_%04d.png command to extract all frames. Execute the constructed FFmpeg command in the command line or script, which will start the video parsing process and generate an output directory containing multi-frame data packets (such as picture files). Then get the multi-frame data packets after the video file is parsed.
[0059] In some embodiments of the present application, by first checking the duration of the video file, subsequent processing of video files that are too short (may not contain useful information or do not require in-depth analysis) can be avoided, thereby saving computing resources and time. When the duration and screen size of the video file meet specific conditions, the video stream information will be deeply parsed to obtain multi-frame data packets. This processing method makes subsequent video analysis or processing more targeted and improves the accuracy and efficiency of the analysis.
[0060] Based on the above embodiments, please refer to Figure 4In one of the exemplary embodiments provided in the present application, the specific implementation process of parsing the video stream information to obtain the parsed multi-frame data packet may also include step S410 and step S420, which are described in detail as follows:
[0061] Step S410, obtaining a target decoder corresponding to the video stream information, so as to decode the video stream based on the target decoder to obtain a decoded video stream;
[0062] Step S420, obtaining a multi-frame data packet from the decoded video stream, wherein the multi-frame data packet includes a multi-frame data constituting the video stream.
[0063] Exemplary, first, it is necessary to determine the encoding format of the video stream. This can usually be obtained by viewing the metadata of the video file or using a multimedia processing tool (such as FFmpeg). According to the encoding format of the video stream, select the corresponding decoder. The decoder can be a software decoder (such as the built-in decoder of FFmpeg) or a hardware decoder (such as a GPU-accelerated decoder). Configure the parameters of the decoder as needed, such as the position of the input video stream, the output format after decoding, etc. Use the decoder to decode the video stream. This usually involves reading the video stream data, passing it to the decoder, and receiving the decoded output. The decoded video stream usually contains a series of continuous frames. The boundaries of the frame need to be determined so that each frame can be correctly segmented. According to the frame boundaries, extract the data of each frame from the decoded video stream. This may require converting the frame data into a specific format or storing it in a corresponding data structure. Organize the extracted frame data into multi-frame data packets. These data packets can contain a series of continuous frames for subsequent processing or analysis.
[0064] In addition, if no target decoder is found to be available during the process of querying or selecting a decoder, it may mean that the encoding format of the video file is not supported or the file itself is damaged. In this case, a detection result can be generated to mark the video file as damaged or undecodable.
[0065] In some embodiments of the present application, using a target decoder that matches the target video stream information can ensure that the video stream is decoded correctly and efficiently, and multiple frame data packets are directly extracted from the decoded video stream, making subsequent video processing steps (such as frame analysis, feature extraction, etc.) more convenient and efficient, which avoids the complexity and uncertainty that may be caused by direct operations in the original encoded video stream.
[0066] Based on the above examples, please refer to Figure 5In one of the exemplary embodiments provided in the present application, the specific implementation process of determining the frame rate information of the video file to be detected based on the multi-frame data packet to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information may also include steps S510 to S530, which are described in detail as follows:
[0067] Step S510, obtaining frame rate information in a multi-frame data packet;
[0068] Step S520: if the frame rate information is consistent with the actual playback speed of the video file to be detected, then the frame rate information is determined to be valid frame rate information;
[0069] Step S530: determining the duration of each frame of the video file to be detected based on the effective frame rate information.
[0070] Exemplarily, a multi-frame data packet is parsed using an appropriate tool or library (such as FFmpeg, libavcodec, etc.) to extract the video frames and related metadata contained therein. Frame rate information is extracted from the parsed multi-frame data packet or related metadata. The frame rate is usually expressed in frames per second (FPS). This can usually be obtained by playing the video and measuring its playback time, or using a video processing tool to analyze the metadata of the video file to obtain playback speed information.
[0071] It should be noted that if the video is recorded at a constant frame rate, then its actual playback speed should match the frame rate information (i.e., the number of frames played per second is equal to the frame rate). Compare the extracted frame rate information with the actual playback speed of the video file to be detected. If the two match (or match within a certain error range), the frame rate information is considered valid. Once the valid frame rate information is determined, it can be used to calculate the duration of each frame. Among them, the frame duration (in seconds) can be calculated by dividing 1 second by the frame rate, that is, frame duration = 1 / frame rate.
[0072] In some embodiments of the present application, by verifying the consistency of the frame rate information with the actual playback speed of the video, it is possible to ensure that the frame rate information used is accurate and valid, which helps subsequent frame rate-based video analysis, processing or synchronization operations maintain high precision and improves the accuracy and effectiveness of video file detection.
[0073] Based on the above embodiments, please refer to Figure 6 In one of the exemplary embodiments provided in the present application, after determining the frame rate information of the video file to be detected based on the multi-frame data packet, and determining the duration of each frame corresponding to the video file to be detected based on the frame rate information, the specific implementation process of the above video file detection method may further include step S610 and step S620, which are described in detail as follows:
[0074] Step S610, if the duration of any frame in the video file to be detected is less than or equal to zero, a detection result indicating that the video file to be detected is damaged is obtained;
[0075] Step S620: If the duration of any frame in the video file to be detected is greater than zero, then the timestamp of each frame in the video file to be detected is obtained.
[0076] Exemplarily, all frames in the video file to be detected are traversed, and the duration of each frame is checked. For each frame, check whether its duration is less than or equal to zero. If it is found that the duration of any frame is less than or equal to zero, it indicates that the video may be damaged or data is lost. If it is found that the duration of any frame is less than or equal to zero during the inspection process, a detection result is immediately generated, marking the video file to be detected as damaged. This detection result can be an error code, a Boolean value, or an object containing error information. If after checking the duration of all frames, it is confirmed that the duration of each frame is greater than zero, the video can be considered to be complete and undamaged. After confirming the integrity of the video, use appropriate tools or libraries (such as FFmpeg, libavformat, etc.) to obtain the timestamp of each frame in the video, where the timestamp is usually used to indicate the relative position or absolute time of the frame in the video.
[0077] In some embodiments of the present application, in order to avoid wasting time and resources in subsequent processing, when it is confirmed that the duration of all frames in the video file is greater than zero, it becomes meaningful to obtain the timestamp of each frame. The timestamp is key information for video synchronization, editing and processing. They ensure the correct order and time relationship of the video content. By obtaining the accurate timestamp, a reliable basis can be provided for subsequent video file detection.
[0078] Based on the above examples, please refer to Figure 7 In one of the exemplary embodiments provided in the present application, the specific implementation process of obtaining the time difference between any two consecutive frames in the video file to be detected and determining the detection result of the video file to be detected based on the time difference and the duration of each frame may also include steps S710 to S730, which are described in detail as follows:
[0079] Step S710, obtaining the timestamps corresponding to any two consecutive frames in the video file to be detected;
[0080] Step S720, calculating the time difference between any two consecutive frames based on their corresponding timestamps;
[0081] Step S730: If the time difference is less than or equal to zero or the time difference is greater than the duration of each frame, a detection result indicating that the video file to be detected is damaged is obtained.
[0082] Following the above embodiment, select the timestamps corresponding to any two consecutive frames in the video file to be detected, calculate the difference between the timestamp of the latter frame and the time difference of the previous frame, and obtain the time difference. If the time difference is less than or equal to zero, it usually means that the timestamp information is incorrect or the video frame sequence is disrupted, so it can be considered that the video file may be damaged. The duration of each frame is known (calculated according to the above embodiment). If the time difference between two consecutive frames is greater than this duration, this may also indicate that there is a problem with the video file, because under normal circumstances, the time interval between two consecutive frames should not exceed the duration of a single frame.
[0083] Optionally, in some feasible embodiments, if any unreasonable situation is found in the process of checking the time difference (the time difference is less than or equal to zero or greater than the duration of each frame), a flag is set to indicate that the video file is damaged to record detailed information leading to the damage detection result, such as frame number, timestamp and time difference, etc., for subsequent analysis and debugging.
[0084] In some embodiments of the present application, by comparing the timestamps of two consecutive frames to calculate the time difference, damage in the video file can be identified more accurately. If the time difference is less than or equal to zero, or the time difference is greater than the duration of each frame, this is usually a sign of video file damage or improper editing, indicating that there may be problems such as frame loss, duplication, or timestamp errors, thereby improving the accuracy and effectiveness of video file detection.
[0085] Based on the above embodiments, please refer to Figure 8 In one of the exemplary embodiments provided in the present application, the specific implementation process of determining the detection result of the video file to be detected based on the time difference and the duration of each frame may also include step S810 and step S820, which are described in detail as follows:
[0086] Step S810, if the time difference is greater than zero and the time difference is less than the duration of each frame, then obtaining the timestamp of each frame in the video file to be detected;
[0087] Step S820: If the time stamps of each frame are in an increasing relationship in time, a detection result indicating that the video file to be detected is normal is obtained.
[0088] Exemplarily, the video processing tool or library mentioned in the above embodiment traverses each frame in the video and calculates the time difference between two consecutive frames. Verify whether each time difference is greater than zero and less than the known duration of each frame. If all time differences meet this condition, then we can preliminarily assume that the video is continuous in time and there is no problem of jumping or repeating frames. Traverse the extracted timestamps and check whether they increase in chronological order. This means that the timestamp of each subsequent frame should be greater than the timestamp of the previous frame. If all inter-frame time differences are greater than zero and less than the duration of each frame, and all timestamps are in an increasing relationship, then it can be concluded that the video file to be detected is normal.
[0089] In some embodiments of the present application, the status of the video file can be determined very accurately by strictly checking the time difference and the timestamp increment relationship. This method can identify even very minor video damage or timestamp errors, ensuring the integrity and accuracy of the video file. Before video processing, this process can ensure the normality of the video file, thereby avoiding errors or anomalies caused by file damage or timestamp errors in subsequent processing, which helps to improve the stability and reliability of video processing.
[0090] Fig. 9 It is a brief flow chart of video file inspection in an exemplary application scenario. In the application scenario shown in 9, the multimodal information of the video file to be detected is obtained, and the multimodal information includes the data size of the video file to be detected and the video stream information; the basic information of the video stream is obtained, and the basic information includes the duration of the video file to be detected; if the duration is greater than the preset duration threshold, the screen size of the video in the video stream information is obtained; if the screen size is greater than the preset size threshold, the video stream information is parsed to obtain the parsed multi-frame data packet. The target decoder corresponding to the video stream information is obtained to decode the video stream based on the target decoder to obtain the decoded video stream; if the duration of any frame in the video file to be detected is less than or equal to zero, the detection result that the video file to be detected is damaged is obtained; if the duration of any frame in the video file to be detected is greater than zero, the timestamp of each frame in the video file to be detected is obtained. If the time difference is less than or equal to zero or the time difference is greater than the duration of each frame, the detection result that the video file to be detected is damaged is obtained, and if the timestamps of each frame present an increasing relationship in time relationship, the detection result that the video file to be detected is normal is obtained. For the detailed implementation process, please refer to the records in the aforementioned embodiments, which will not be described in detail here.
[0091] Fig.10 is a block diagram of a video file detection device shown in an exemplary embodiment of the present application. The device can be applied to Figure 1The implementation environment shown in the figure is specifically configured in the server end 120. The device can also be applied to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment to which the device is applied.
[0092] like Fig.10 As shown, the exemplary video file detection device includes: an acquisition module 1010, which acquires multimodal information of the video file to be detected, the multimodal information including the data size of the video file to be detected and the video stream information; a parsing module 1020, which parses the video stream information to obtain a parsed multi-frame data packet if the data size is greater than a preset data size threshold; a determination module 1030, which determines the frame rate information of the video file to be detected based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information; a detection module 1040, which acquires the time difference between any two consecutive frames in the video file to be detected, and determines the detection result of the video file to be detected based on the time difference and the duration of each frame.
[0093] According to one aspect of an embodiment of the present application, the above-mentioned parsing module 1020 also includes obtaining basic information of the video stream, the basic information including the duration of the video file to be detected; if the duration is greater than a preset duration threshold, obtaining the screen size of the video in the video stream information; if the screen size is greater than a preset size threshold, parsing the video stream information to obtain a multi-frame data packet after parsing.
[0094] According to one aspect of an embodiment of the present application, the above-mentioned parsing module 1020 also includes obtaining a target decoder corresponding to the video stream information, so as to decode the video stream based on the target decoder to obtain a decoded video stream; and obtaining a multi-frame data packet from the decoded video stream, wherein the multi-frame data packet includes multiple frames of data constituting the video stream.
[0095] According to one aspect of an embodiment of the present application, the above-mentioned parsing module 1020 also includes obtaining frame rate information in a multi-frame data packet; if the frame rate information is consistent with the actual playback speed of the video file to be detected, the frame rate information is determined to be valid frame rate information; based on the valid frame rate information, the duration of each frame corresponding to the video file to be detected is determined.
[0096] According to one aspect of an embodiment of the present application, the above-mentioned determination module 1030 also includes: if the duration of any frame in the video file to be detected is less than or equal to zero, a detection result that the video file to be detected is damaged is obtained; if the duration of any frame in the video file to be detected is greater than zero, the timestamp of each frame in the video file to be detected is obtained.
[0097] According to one aspect of an embodiment of the present application, the above-mentioned detection module 1040 also includes obtaining the timestamps corresponding to any two consecutive frames in the video file to be detected; calculating the time difference between any two consecutive frames based on the corresponding timestamps; if the time difference is less than or equal to zero or the time difference is greater than the duration of each frame, a detection result of damage to the video file to be detected is obtained.
[0098] According to one aspect of an embodiment of the present application, the above-mentioned detection module 1040 also includes, if the time difference is greater than zero and the time difference is less than the duration of each frame, obtaining the timestamp of each frame in the video file to be detected; if the timestamp of each frame presents an increasing relationship in time, then a normal detection result of the video file to be detected is obtained.
[0099] The video file detection device provided in the above embodiment and the video file detection method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment, and will not be repeated here. In practical applications, the video file detection device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0100] An embodiment of the present application also provides an electronic device, including: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by one or more processors, the electronic device implements the video file detection method provided in the above-mentioned embodiments.
[0101] Fig.11 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. Fig.11 The computer system 1100 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0102] like Fig.11As shown, the computer system 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1102 or the program loaded from the storage part 1108 to the random access memory (RAM) 1103, such as executing the method in the above embodiment. In the RAM 1103, various programs and data required for system operation are also stored. The CPU 1101, the ROM 1102 and the RAM 1103 are connected to each other through the bus 1104. The input / output (I / O) interface 1105 is also connected to the bus 1104.
[0103] The following components are connected to the I / O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to the I / O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1110 as needed so that a computer program read therefrom is installed into the storage section 1108 as needed.
[0104] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 1109, and / or installed from a removable medium 1111. When the computer program is executed by a central processing unit (CPU) 1101, various functions defined in the system of the present application are executed.
[0105] The computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0106] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0107] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0108] Another aspect of the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the video file detection method as described above is implemented. The computer-readable storage medium can be included in the electronic device described in the above embodiment, or it can exist independently without being assembled into the electronic device.
[0109] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the video file detection method provided in each of the above embodiments.
[0110] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A video file detection method, characterized in that: include: Acquire multimodal information of the video file to be detected, wherein the multimodal information includes the data size and video stream information of the video file to be detected; If the data size is greater than a preset data size threshold, the video stream information is parsed to obtain a parsed multi-frame data packet; Determine the frame rate information of the video file to be detected based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information; The time difference between any two consecutive frames in the video file to be detected is obtained, and a detection result of the video file to be detected is determined based on the time difference and the duration of each frame.
2. The method according to claim 1, characterized in that The parsing of the video stream information to obtain a parsed multi-frame data packet includes: Acquire basic information of the video stream, wherein the basic information includes the duration of the video file to be detected; If the duration is greater than a preset duration threshold, obtaining the screen size of the video in the video stream information; If the picture size is greater than a preset size threshold, the video stream information is parsed to obtain a parsed multi-frame data packet.
3. The method according to claim 2, characterized in that The step of parsing the video stream information to obtain a parsed multi-frame data packet includes: Obtaining a target decoder corresponding to the video stream information, so as to decode the video stream based on the target decoder to obtain a decoded video stream; A multi-frame data packet is obtained from the decoded video stream, wherein the multi-frame data packet includes a multi-frame data constituting the video stream.
4. The method according to claim 3, characterized in that The determining the frame rate information of the video file to be detected based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information, comprises: Obtaining frame rate information in the multi-frame data packet; If the frame rate information is consistent with the actual playback speed of the video file to be detected, determining that the frame rate information is valid frame rate information; The duration of each frame corresponding to the to-be-detected video file is determined based on the effective frame rate information.
5. The method according to claim 1, characterized in that After determining the frame rate information of the video file to be detected based on the multi-frame data packet, and determining the duration of each frame corresponding to the video file to be detected based on the frame rate information, the method further includes: If the duration of any frame in the video file to be detected is less than or equal to zero, a detection result indicating that the video file to be detected is damaged is obtained; If the duration of any frame in the to-be-detected video file is greater than zero, then the timestamp of each frame in the to-be-detected video file is obtained.
6. The method according to claim 5, characterized in that The obtaining of the time difference between any two consecutive frames in the video file to be detected, and determining the detection result of the video file to be detected based on the time difference and the duration of each frame, includes: Obtaining the timestamps corresponding to any two consecutive frames in the video file to be detected; Calculate the time difference between any two consecutive frames based on the respective corresponding timestamps; If the time difference is less than or equal to zero or the time difference is greater than the duration of each frame, a detection result of damage to the video file to be detected is obtained.
7. The method according to claim 1, characterized in that The step of determining the detection result of the video file to be detected based on the time difference and the duration of each frame includes: If the time difference is greater than zero and the time difference is less than the duration of each frame, then obtaining the timestamp of each frame in the video file to be detected; If the timestamps of each frame are in an increasing relationship in time, a detection result of the video file to be detected is normal.
8. A video file detection device, characterized in that: The device comprises: An acquisition module is used to acquire multimodal information of a video file to be detected, wherein the multimodal information includes a data size and video stream information of the video file to be detected; A parsing module, if the data size is greater than a preset data size threshold, then parses the video stream information to obtain a parsed multi-frame data packet; A determination module, which determines the frame rate information of the video file to be detected based on the multi-frame data packet, so as to determine the duration of each frame corresponding to the video file to be detected based on the frame rate information; The detection module obtains the time difference between any two consecutive frames in the video file to be detected, and determines the detection result of the video file to be detected based on the time difference and the duration of each frame.
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, enables the electronic device to implement the video file detection method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is enabled to execute the video file detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and terminal for playing video on low-side embedded product
CN102595114A
Locomotive video data integrity automatic detection method
CN105049915A
Video processing method and terminal
CN105578254A
Video frame drop compensation method and device, computer equipment and storage medium
CN117579821A
Method and device for repairing ARW damaged file
CN118170575A