Video file cutting method and device
Technical Field
The present disclosure relates to the field of multimedia technologies, and in particular, to a method and an apparatus for cutting a video file.
Background
With the continuous development of big data (big data), video segmentation technology suitable for big data processing framework is also strong. However, the traditional video file cutting tool has a relatively coarse control on the size of the video and cannot be accurate to the frame level; the fault-tolerant capability of the original video file header is weak, such as the problem of messy codes of the initial part of the Haikang video file; the control interface for the output video file coding format after being divided is less, and the requirement of special application development is difficult to meet.
Disclosure of Invention
In view of this, the present disclosure provides a video file cutting method and apparatus.
According to an aspect of the present disclosure, there is provided a video file cutting method, including: acquiring segmentation parameters, wherein the segmentation parameters comprise an expected segmentation frame number and an expected segmentation number; acquiring a video file, and estimating the total frame number of the video file; determining a segmentation strategy according to the total frame number, the expected segmentation frame number and the expected segmentation number; and segmenting the video file according to the segmentation strategy.
In a possible implementation manner, determining a segmentation policy according to the total frame number, the expected segmentation frame number, and the expected number of segmentation copies includes: and not dividing the video file under the condition that the total frame number is less than or equal to the expected dividing frame number.
In a possible implementation manner, determining a segmentation policy according to the total frame number, the expected segmentation frame number, and the expected number of segmentation copies includes: under the condition that the total frame number is greater than the expected segmentation frame number, comparing the ratio obtained by dividing the total frame number by the expected segmentation frame number with the size of the expected segmentation number; and determining the actual number of divided parts of the video file as the expected number of divided parts when the ratio is larger than the expected number of divided parts.
In a possible implementation manner, determining a segmentation policy according to the total frame number, the expected segmentation frame number, and the expected number of segmentation copies further includes: under the condition that the total frame number is greater than the expected segmentation frame number, comparing the ratio obtained by dividing the total frame number by the expected segmentation frame number with the size of the expected segmentation number; and determining the actual number of divided parts of the video file as the ratio in the case that the ratio is less than or equal to the expected number of divided parts.
In a possible implementation manner, in a case that the remaining frame number of the last file obtained by the division is smaller than the expected division frame number, the remaining frame number is accommodated in the last file, and a completion operation is not performed.
According to another aspect of the present disclosure, there is provided a video file cutting apparatus, comprising: the parameter acquisition module is used for acquiring segmentation parameters, and the segmentation parameters comprise expected segmentation frame numbers and expected segmentation numbers; the video acquisition module is used for acquiring a video file and estimating the total frame number of the video file; the strategy determining module is used for determining a segmentation strategy according to the total frame number, the expected segmentation frame number and the expected segmentation number; and the video segmentation module is used for segmenting the video file according to the segmentation strategy.
In one possible implementation, the policy determination module includes: a first policy sub-module for not segmenting the video file if the total frame number is less than or equal to the expected segmentation frame number.
In one possible implementation manner, the policy determining module further includes: the second strategy submodule is used for comparing the ratio obtained by dividing the total frame number by the expected segmentation frame number with the size of the expected segmentation number under the condition that the total frame number is greater than the expected segmentation frame number; and determining the actual number of divided parts of the video file as the expected number of divided parts when the ratio is larger than the expected number of divided parts.
In one possible implementation manner, the policy determining module further includes: a third strategy submodule, configured to compare a ratio obtained by dividing the total frame number by the expected split frame number with the expected split number when the total frame number is greater than the expected split frame number; and determining the actual number of divided parts of the video file as the ratio in the case that the ratio is less than or equal to the expected number of divided parts.
In one possible implementation, the video segmentation module includes: and the first segmentation submodule is used for accommodating the residual frame number in the last file without completion operation under the condition that the residual frame number of the last file obtained by segmentation is smaller than the expected segmentation frame number.
According to still another aspect of the present disclosure, there is provided a video file cutting apparatus including:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to:
the parameter acquisition module is used for acquiring segmentation parameters, and the segmentation parameters comprise expected segmentation frame numbers and expected segmentation numbers; the video acquisition module is used for acquiring a video file and estimating the total frame number of the video file; the strategy determining module is used for determining a segmentation strategy according to the total frame number, the expected segmentation frame number and the expected segmentation number; and the video segmentation module is used for segmenting the video file according to the segmentation strategy.
According to yet another aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium having instructions therein, which when executed by a processor of a terminal and/or a server, enable the terminal and/or the server to perform a video file cutting method, the method including: acquiring segmentation parameters, wherein the segmentation parameters comprise an expected segmentation frame number and an expected segmentation number; acquiring a video file, and estimating the total frame number of the video file; determining a segmentation strategy according to the total frame number, the expected segmentation frame number and the expected segmentation number; and segmenting the video file according to the segmentation strategy.
According to the video file cutting method and device provided by the disclosure, the video file is cut in a non-mechanical mode, the cutting strategy is intelligently selected according to the size of the expected cutting frame number and the expected cutting number of the video file, the cutting of the video file is accurate to the fine granularity of the frame, and the cutting method is wide in application range and strong in fault tolerance.
Other features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments, which proceeds with reference to the accompanying drawings.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.
Fig. 1 shows a flow chart of a video file cutting method according to an embodiment of the present disclosure;
FIG. 2 shows a system architecture diagram of a video file cutting method according to another embodiment of the present disclosure;
FIG. 3 shows a flow diagram of a video file cutting method according to another embodiment of the present disclosure;
FIG. 4 shows a block diagram of a video file cutting apparatus according to an embodiment of the present disclosure;
fig. 5 shows yet another block diagram of a video file cutting apparatus according to an embodiment of the present disclosure.
Detailed Description
Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers can indicate functionally identical or similar elements. While the various aspects of the embodiments are presented in drawings, the drawings are not necessarily drawn to scale unless specifically indicated.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present disclosure. It will be understood by those skilled in the art that the present disclosure may be practiced without some of these specific details. In some instances, methods, means, elements and circuits that are well known to those skilled in the art have not been described in detail so as not to obscure the present disclosure.
Example 1
Fig. 1 shows a flow chart of a video file cutting method according to an embodiment of the present disclosure. As shown in fig. 1, the method includes steps 11 to 14.
And 11, acquiring segmentation parameters, wherein the segmentation parameters comprise an expected segmentation frame number and an expected segmentation number.
In this embodiment, the segmentation parameters may further include an input video file absolute path, a video file processing frame offset, an output video file absolute path, and the like. The video file can be obtained according to the absolute path of the input video file, and the storage position of the segmented video can be determined according to the absolute path of the output video file.
And step 12, acquiring a video file and estimating the total frame number of the video file.
In this embodiment, the video file may be acquired according to an absolute path of the input video file. The acquired Video file may be a file encoded by h.264 (highly compressed digital Video codec standard) such as MP4(Moving Picture Experts Group 4), MOV (QuickTime film format, an Audio/Video file format developed by Apple inc.), AVI (Audio Video Interleaved format), and the like.
In the process of estimating the total frame number of the video file, whether a header file of the video file is readable or not needs to be confirmed. If the header file of the video file cannot be read, decoding the video file by using a different coding mode is attempted. If the video image can be correctly decoded, the pre-reading is carried out according to the current decoding mode, and the total frame number of the video file is estimated and obtained. If the header file of the video file is readable, the total frame number of the video file is directly estimated.
And step 13, determining a segmentation strategy according to the total frame number, the expected segmentation frame number and the expected segmentation number.
In one possible implementation, determining a segmentation strategy according to the total frame number, the expected segmentation frame number, and the expected number of segmentation copies (step 13) may include the following implementation manners:
in the first mode, the video file is not divided under the condition that the total frame number is less than or equal to the expected dividing frame number.
A second mode, under the condition that the total frame number is greater than the expected segmentation frame number, comparing the ratio obtained by dividing the total frame number by the expected segmentation frame number with the size of the expected segmentation number; and determining the actual number of divided parts of the video file as the expected number of divided parts when the ratio is larger than the expected number of divided parts.
Comparing the ratio obtained by dividing the total frame number by the expected division frame number with the expected division number under the condition that the total frame number is greater than the expected division frame number; and determining the actual number of divided parts of the video file as the ratio in the case that the ratio is less than or equal to the expected number of divided parts.
And step 14, segmenting the video file according to the segmentation strategy.
In this embodiment, the video segmentation preferentially determines readability of the video head file, acquires an encoding mode, then selects a corresponding decoder to decode, segments the processed video file, and supports multiple MPEG (Moving Picture experts group) encoding. In the process of segmenting the video file, because the total frame number of the video file is an estimated value, in order to prevent the boundary overflow when the video file is read, the actual frame number contained in the video file is counted in real time in the segmenting process, and the frame number of each segmented video file is accurately calculated. The segmented video file can meet the requirements of computation frameworks such as MapReduce (a programming model for parallel operation of large-scale data sets (larger than 1 TB)) on streaming media data segmentation.
In one possible implementation manner, the segmenting the video file according to the segmentation policy includes: and under the condition that the residual frame number of the last file obtained by segmentation is smaller than the expected segmentation frame number, the residual frame number is contained in the last file, and a completion operation is not carried out.
It should be noted that the above method is also applicable to the cutting of video streams, the specific cutting process is the same as that of video files, and the method steps can also be modified appropriately according to the characteristics of the video streams, and the disclosure is not limited thereto.
The method provided by the embodiment of the disclosure adopts a non-mechanical mode to cut the video file, intelligently selects the cutting strategy according to the size of the expected cutting frame number and the expected cutting number of the video file, and the like, and accurately cuts the video file to the fine granularity of the frame, and the cutting method has wide application range and strong fault-tolerant capability. Moreover, the method is suitable for various fields of streaming media data processing, video data segmentation and parallel computation, smart city data center construction and the like, and can realize automatic cutting and code conversion of video files or video streams with various formats. Further, the obtained segmented video file or video stream can meet the requirements of computation frameworks such as MapReduce and the like on the segmentation of streaming media data. In addition, the method is convenient for a big data platform to realize data distribution and scheduling of multiprocessing tasks, thereby realizing efficient processing and analysis of video streaming media data.
It should be noted that, although the video file cutting method is described above by taking the above embodiment 1 as an example, those skilled in the art can understand that the present disclosure should not be limited thereto. In fact, the user can flexibly set the related method steps according to personal preference and/or actual application scenes, as long as the design idea of the technical scheme is met.
Example 2
In order to better describe the video file cutting method provided by the embodiment of the present disclosure, the video file cutting method according to the embodiment of the present disclosure is generally described below through the system architecture diagram of the above method, and fig. 2 shows a system architecture diagram of a video file cutting method according to another embodiment of the present disclosure, as shown in fig. 2, in the system architecture, the video file cutting method may include:
reading in parameters and video files: reading segmentation parameters (02) including an expected segmentation frame number, an expected segmentation number and the like; a video file/stream, i.e. a video file or a video stream, is acquired (01).
Calculating a segmentation strategy according to a video segmentation algorithm: estimating the total frame number of the video file/stream, and then determining a segmentation strategy (03) according to the total frame number, the expected segmentation frame number and the expected segmentation number on the basis of a pre-designed video segmentation algorithm.
And (3) dividing the video file according to a dividing strategy: the video file/stream is divided into at least one small video file according to the obtained division strategy and stored (04).
Fig. 3 shows a flow chart of a video file cutting method according to another embodiment of the present disclosure. As shown in fig. 3, the method includes steps 21 to 27.
Step 21, reading parameters. And acquiring and reading parameters such as an absolute path of an input video file, the number of frames of an expected video file, the number of copies of the expected video file, the offset of processing frames of the video file, an absolute path of an output video file and the like.
Step 22, parameter checking. It is checked whether the parameters read in step 21 are reasonable and the parameters are initialized. Whether the parameters are reasonable may include whether the absolute path of the input video file is really valid, etc.
And step 23, reading the video. And reading in the video file according to the input video file absolute path video. In the present embodiment, the reading of video files encoded in H264, such as MP4, MOV, AVI, and the like, is supported.
And step 24, calculating the total frame number. The total number of frames of the video file read in is estimated. First, the readability of the header file of the read video file is confirmed, and in the case where the header file is readable, the total number of frames of the video file is directly estimated. When the header file of the video file cannot be read, decoding of the video file using a different encoding scheme is attempted. If the video image can be correctly decoded, the pre-reading is carried out according to the current decoding mode, and then the total frame number of the video file is estimated. Note that the error of the total frame number obtained by estimation is within 25 frames.
And step 25, calculating a segmentation strategy. And determining a video file segmentation strategy according to the expected segmentation frame number and the expected segmentation number in the input parameters and the estimated total frame number of the video file. Wherein the expected number of split frames has a relatively higher priority than the expected number of split shares. Assuming that the total frame number of the video is a, the expected number of divided frames is E, and the expected number of divided parts is C, the actual number of divided parts N may be calculated as follows:
if A is less than E, then N is 1, i.e. not divided.
If A > E, and A/E > C, let N be C.
If A > E and A/E ≦ C, then N ═ A/E.
The calculation method is only an example, and in practical applications, other methods may be adopted for calculation.
And 26, video segmentation, namely segmenting the video file according to the obtained segmentation strategy. And the readability of the video head file is judged by the video segmentation priority, the coding mode is obtained, and then a corresponding decoder is selected for decoding. Because the total frame number of the video file is an estimated value, in order to prevent the boundary overflow when the video file is read, the real frame number contained in the video is counted in real time in the segmentation process, and the frame number of each segmented video file is accurately calculated. And in the last video file obtained, if the residual frame number is less than the expected video file frame number, the residual frame number is accommodated, and the completion operation is not carried out.
And 27, storing the video, namely storing the divided video file according to the absolute path of the output video file. The divided video file supports an encoding format such as XVID (MPEG-4 video codec written by OpenDivX) or MPEG.
The method provided by the embodiment of the disclosure adopts a non-mechanical mode to cut the video file, intelligently selects the cutting strategy according to the size of the expected cutting frame number and the expected cutting number of the video file, and the like, and accurately cuts the video file to the fine granularity of the frame, and the cutting method has wide application range and strong fault-tolerant capability. Moreover, the method is suitable for various fields of streaming media data processing, video data segmentation and parallel computation, smart city data center construction and the like, and can realize automatic cutting and code conversion of video files or video streams with various formats. Further, the obtained segmented video file or video stream can meet the requirements of computation frameworks such as MapReduce and the like on the segmentation of streaming media data. In addition, the method is convenient for a big data platform to realize data distribution and scheduling of multiprocessing tasks, thereby realizing efficient processing and analysis of video streaming media data.
It should be noted that, although the video file cutting method is described above by taking the above embodiment 2 as an example, those skilled in the art can understand that the present disclosure should not be limited thereto. In fact, the user can flexibly set the related method steps according to personal preference and/or actual application scenes, as long as the design idea of the technical scheme is met.
Example 3
Based on the video file cutting method, the disclosure provides a video file cutting device. Fig. 3 shows a block diagram of a video file cutting apparatus according to an embodiment of the present disclosure. As shown in fig. 3, the apparatus includes:
a parameter obtaining module 301, configured to obtain a segmentation parameter, where the segmentation parameter includes an expected number of segmented frames and an expected number of segmented copies.
The video obtaining module 302 is configured to obtain a video file and estimate a total frame number of the video file.
And a strategy determining module 303, configured to determine a segmentation strategy according to the total frame number, the expected segmentation frame number, and the expected number of segments.
A video segmentation module 304, configured to segment the video file according to the segmentation policy.
Based on fig. 3, fig. 4 shows a further block diagram of a video file cutting apparatus according to an embodiment of the present disclosure.
In one possible implementation, as shown in fig. 4, the policy determining module 303 includes:
a first policy submodule 3031, configured to not divide the video file if the total frame number is less than or equal to the expected number of divided frames.
In one possible implementation manner, as shown in fig. 4, the policy determining module 303 further includes:
a second policy submodule 3032, configured to compare, when the total frame number is greater than the expected split frame number, a ratio obtained by dividing the total frame number by the expected split frame number with the size of the expected split number; and determining the actual number of divided parts of the video file as the expected number of divided parts when the ratio is larger than the expected number of divided parts.
In one possible implementation manner, as shown in fig. 4, the policy determining module 303 further includes:
a third policy submodule 3033, configured to compare, when the total frame number is greater than the expected split frame number, a ratio obtained by dividing the total frame number by the expected split frame number with the size of the expected split number; and determining the actual number of divided parts of the video file as the ratio in the case that the ratio is less than or equal to the expected number of divided parts.
In a possible implementation manner, as shown in fig. 4, the video segmentation module 304 further includes: the first dividing submodule 3041 is configured to, when the remaining frame number of the last file obtained by dividing is smaller than the expected divided frame number, accommodate the remaining frame number in the last file, and do not perform a completion operation.
It should be noted that, although the video file cutting apparatus is described above by taking the above embodiment 3 as an example, those skilled in the art will understand that the present disclosure should not be limited thereto. In fact, the user can flexibly set the relevant modules according to personal preferences and/or actual application scenes, as long as the design idea of the technical scheme is met.
The device provided by the embodiment of the disclosure cuts the video file in a non-mechanical mode, intelligently selects the cutting strategy according to the size of the expected cutting frame number and the expected cutting number of the video file, and the like, and precisely cuts the video file to the fine granularity of the frame, and the cutting method has the advantages of wide application range and strong fault-tolerant capability. Moreover, the method is suitable for various fields such as streaming media data processing, video data segmentation and parallel computation, smart city data center construction and the like, and can realize automatic cutting and code conversion of video files or video streams with various formats; the obtained segmented video file or video stream can meet the requirements of computation frameworks such as MapReduce and the like on the segmentation of streaming media data; the method is convenient for the big data platform to realize the distribution of data and the scheduling of multiprocessing tasks, thereby realizing the high-efficiency processing and analysis of the video streaming media data.
Based on the video file cutting method and device, the present disclosure provides a video file cutting device, including:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to:
the parameter acquisition module is used for acquiring segmentation parameters, and the segmentation parameters comprise expected segmentation frame numbers and expected segmentation numbers; the video acquisition module is used for acquiring a video file and estimating the total frame number of the video file; the strategy determining module is used for determining a segmentation strategy according to the total frame number, the expected segmentation frame number and the expected segmentation number; and the video segmentation module is used for segmenting the video file according to the segmentation strategy.
The present disclosure may be systems, methods, and/or computer program products. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied thereon for causing a processor to implement various aspects of the present disclosure.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a Static Random Access Memory (SRAM), a portable compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD), a memory stick, a floppy disk, a mechanical coding device, such as punch cards or in-groove projection structures having instructions stored thereon, and any suitable combination of the foregoing. Computer-readable storage media as used herein is not to be construed as transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through a fiber optic cable), or electrical signals transmitted through electrical wires.
The computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present disclosure may be assembler instructions, Instruction Set Architecture (ISA) instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider). In some embodiments, the electronic circuitry that can execute the computer-readable program instructions implements aspects of the present disclosure by utilizing the state information of the computer-readable program instructions to personalize the electronic circuitry, such as a programmable logic circuit, a Field Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA).
Various aspects of the present disclosure are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the disclosure. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Having described embodiments of the present disclosure, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen in order to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.