Video file clipping method and device
Technical field
The present invention relates to a kind of file montage technology, relate in particular to a kind of clipping method for video file and device.
Background technology
Video file record finish after, generally all can pass through montage, the processing such as splicing.For example one grade of news program may be trimmed into a plurality of video segments according to each event.There are a variety of video clipping softwares that the function of video editing is provided in the prior art.
Video file is alternately to be made of key frame (I frame) and predictive frame (P frame and B frame), and wherein I frame is own absolute coding, does not rely on other frame data; P frame relies on I frame data; Bframe relies on I frame, P frame or other B frame data; Predictive frame is used for predicting the variation of key frame, and its encoding and decoding depend on key frame.
In the prior art, the montage of video is if begin from predictive frame, and then montage file out has no idea to play, because the decoding of predictive frame will rely on key frame.Therefore can only from the key frame montage, have no idea to realize from the arbitrary frame montage in the prior art.
Summary of the invention
The object of the invention is to address the above problem, a kind of video file clipping method and device are provided, can realize beginning montage from arbitrary frame.
Technical scheme of the present invention is: the present invention has disclosed a kind of video file clipping method, and video file is alternately to be made of key frame and predictive frame, and described method comprises:
In key frame or the predictive frame which frame that the judgement montage begins be;
If key frame, then directly from this key frame montage, if predictive frame, then begin to re-start coding to all predictive frames between the rear key frame from this predictive frame, so that after this predictive frame that montage begins converts the predictive frame that key frame and remaining predictive frame converts the key frame after this conversion to, the key frame montage after this conversion.
According to an embodiment of video file clipping method of the present invention, this video file is the file that adopts the flv form of h264 coded system formation.
According to an embodiment of video file clipping method of the present invention, be the situation of predictive frame for montage place, the recompile process of predictive frame comprises:
Read the description document of this predictive frame and the description document of the key frame that this predictive frame relies on from file header;
According to the description document that reads, this predictive frame that reads is decoded into the yuv video sequence;
This predictive frame recompile is become new key frame and generates new description document, feed back to file header;
For each frame in remaining predictive frame, the description document of the key frame that reads the description document of all the other each predictive frames and rely on, according to the description document that reads all the other each predictive frames are decoded into the yuv video sequence, and recompile forms the predictive frame of described new key frame, feeds back to file header.
The present invention has also disclosed a kind of video file montage device, and video file is alternately to be made of key frame and predictive frame, and described device comprises:
In key frame or the predictive frame which frame of video determined property module, the frame that the judgement montage begins are;
Key frame montage module, if key frame, then directly from this key frame montage;
Predictive frame montage module, if predictive frame, then begin to re-start coding to all predictive frames between the rear key frame from this predictive frame, so that after this predictive frame that montage begins converts the predictive frame that key frame and remaining predictive frame converts the key frame after this conversion to, the key frame montage after this conversion.
According to an embodiment of video file montage device of the present invention, this video file is the file that adopts the flv form of h264 coded system formation.
Embodiment according to video file montage device of the present invention, this predictive frame montage module further comprises key frame modular converter and predictive frame recodification module, wherein the key frame modular converter comprises description document reading unit, decoding unit and recodification unit, wherein:
Described description document reading unit reads the description document of this predictive frame and the description document of the key frame that this predictive frame relies on from file header;
Described decoding unit according to the description document that reads, is decoded into the yuv video sequence with this predictive frame that reads;
Described recodification unit becomes this predictive frame recompile new key frame and generates new description document, feeds back to file header;
Described predictive frame recodification module, for each frame in remaining predictive frame, the description document of the key frame that reads the description document of all the other each predictive frames and rely on, according to the description document that reads all the other each predictive frames are decoded into the yuv video sequence, and recompile forms the predictive frame of described new key frame, feeds back to file header.
The present invention contrasts prior art following beneficial effect: the solution of the present invention is to judge whether key frame of frame that montage begins, if then directly montage of key frame, if predictive frame begins montage after then converting thereof into key frame.The contrast prior art, the present invention not only can begin montage from key frame, can also begin montage from predictive frame, has realized the montage to the video file arbitrary frame.
Description of drawings
Fig. 1 shows the flow chart of the preferred embodiment of video file clipping method of the present invention.
Fig. 2 shows the schematic diagram of the preferred embodiment of video file montage device of the present invention.
Embodiment
The invention will be further described below in conjunction with drawings and Examples.
Fig. 1 shows the flow process of the preferred embodiment of video file clipping method of the present invention.See also Fig. 1, the below is the detailed description to each implementation step of the video file clipping method of the present embodiment.In the present embodiment, video file can adopt the file of the flv form of h264 coded system formation.
Step 10: which in key frame or the predictive frame frame that the judgement montage begins be, if key frame then enters step S11, if predictive frame then enters step S12.
Step S11: directly from the key frame montage, flow process finishes.
Step S12: the predictive frame that begins from montage is carried out recompile, convert thereof into new key frame.
For this step, the specific implementation process is as follows.
Adopt the predictive code of the flv file of h264 coded system formation for example to be:
Read the description document of predictive frame (what suppose the beginning montage is the 3rd frame) and the description document of the key frame (i.e. the 1st frame) that predictive frame relies on from file header.Then according to the description document that reads, the predictive frame that reads is decoded into the yuv video sequence.At last the predictive frame recompile is become new key frame and generate new description document, feed back to file header.
Step S13: the predictive frame that begins from montage is begun to re-start coding to all the other all predictive frames between the rear key frame, convert the predictive frame that depends on new key frame to.
Processing procedure to predictive frame (for example being the 3rd frame) among the cataloged procedure of remaining predictive frame and the step S12 is similar, comprise: read the description document of all the other each predictive frames and the description document of the key frame that relies on, according to the description document that reads all the other each predictive frames are decoded into the yuv video sequence, and recompile forms the predictive frame depend on new key frame, feeds back to file header.
Step S14: the key frame after conversion begins montage.
Fig. 2 shows the principle of the embodiment of video file montage device of the present invention.See also Fig. 2, the device of the present embodiment comprises: frame of video determined property module 10, key frame montage module 12, predictive frame montage module 14.In the present embodiment, video file is the file that adopts the flv form of h264 coded system formation.
In key frame or the predictive frame which frame that the 10 judgement montages of frame of video determined property module begin be.Key frame montage module 12 is to be the processing of key frame for the frame that montage begins, directly from the key frame montage.Predictive frame montage module 14 is to be the processing of predictive frame for the frame that montage begins, begin to re-start coding to all predictive frames between the rear key frame from predictive frame, so that the predictive frame that montage begins converts key frame and remaining predictive frame to convert the predictive frame that depends on the key frame after the conversion to after, the key frame montage after the conversion.
Predictive frame montage module 14 further comprises key frame modular converter 140 and predictive frame recodification module 142, and wherein key frame modular converter 140 comprises description document reading unit 1400, decoding unit 1402 and recodification unit 1404.
Description document reading unit 1400 reads the description document of predictive frame and the description document of the key frame that predictive frame relies on from file header.
Decoding unit 1402 is decoded into the yuv video sequence according to the description document that reads with the predictive frame that reads.
Recodification unit 1404 becomes the predictive frame recompile new key frame and generates new description document, feeds back to file header.
Predictive frame recodification module 1404 is for each frame in remaining predictive frame, the description document of the key frame that reads the description document of all the other each predictive frames and rely on, according to the description document that reads all the other each predictive frames are decoded into the yuv video sequence, and recompile forms the predictive frame depend on new key frame, feeds back to file header.
Above-described embodiment provides to those of ordinary skills and realizes and use of the present invention; those of ordinary skills can be in the situation that do not break away from invention thought of the present invention; above-described embodiment is made various modifications or variation; thereby protection scope of the present invention do not limit by above-described embodiment, and should be the maximum magnitude that meets the inventive features that claims mention.