Summary of the invention
The technical problem that the present invention will solve is; Audio frequency and video transcoding software of the prior art to making video can not be with a plurality of files; Connect into the defective of a file output, a kind of connection output intent and device that can the video file of a plurality of inputs be connected into the video file of a video file output is provided.
The present invention constructs a kind of connection output intent of video file, comprising step: S1, decoded at least two video files are carried out the timestamp smoothing processing; S2, said at least two video files after the timestamp smoothing processing are carried out registration process; S3, with said at least two video files after the registration process encode, synthetic output.
In the connection output intent of a kind of video file of the present invention, said step S1 comprises: S11, handle and to make said frame of video export by preset frame per second through the frame of video of decoded video file being carried out repeating frame or frame losing; S12, through mending quiet to the audio frame of said decoded video file or abandoning corresponding voice data, make said audio frame align by theoretical timestamp.
In the connection output intent of a kind of video file of the present invention, said step S11 comprises: S111, obtain the theoretical timestamp of current video frame and said current video frame; S112, when the timestamp of said current video frame during less than the theoretical timestamp of said current video frame, through an input video frame duration, turn back to step S111; S113, when the timestamp of said current video frame during more than or equal to the theoretical timestamp of said current video frame, said current video frame is set to current output video frame, and the output time of said current video frame stabs and is set to said theoretical timestamp; S114, the difference of stabbing when said current video frame and a last video frame time are more than or equal to the output video frame duration of twice; A said last frame of video be set to said current video frame and and the difference of the timestamp of current video frame more than or equal to the output video frame between the last frame of video of the output video frame duration of twice, and the output time of a said last frame of video stab be set to the output video frame between said current video frame and the said last frame of video theoretical timestamp with the assurance output frame rate.
In the connection output intent of a kind of video file of the present invention, said step S12 comprises: S121, obtain the theoretical timestamp of current audio frame and said current audio frame; S122, when the timestamp of said current audio frame theoretical timestamp less than said current audio frame; Then said current audio frame abandons the data volume in time of difference of timestamp of said theoretical timestamp and said current audio frame; Said current audio frame is set to current output audio frame, and the output time of said current audio frame stabs the theoretical timestamp that is set to said current audio frame; When the timestamp of said current audio frame equals the theoretical timestamp of said current audio frame, said current audio frame is set to current output audio frame; When the timestamp of said current audio frame theoretical timestamp greater than said current audio frame; Quiet data in the time of the timestamp of the additional said current audio frame of then said current audio frame and the difference of said theoretical timestamp; Said current audio frame is set to current output audio frame, and the output time of said current audio frame stabs the said theoretical timestamp that is set to said current audio frame.
In the connection output intent of a kind of video file of the present invention, said step S2 comprises: S21, alternately acquisition time stabs the frame of video and the audio frame of the video file after the smoothing processing; S22, with the alignment of said frame of video and said audio frame.
In the connection output intent of a kind of video file of the present invention; Said step S22 comprises: S221, when said audio frame for finishing audio frame; And said audio frame finishes than said frame of video in advance; Then after said audio frame finishes, alternately import quiet data and said frame of video to the frame of video that finishes frame of video; S222, when said audio frame for finishing audio frame, and said frame of video finishes than said audio frame in advance, then after said frame of video finishes, the audio frame when alternately importing said frame of video and finishing is to the audio frame and the said end frame of video of said end audio frame; When S223, end of output audio frame, when the timestamp of said end audio frame through duration of said end audio frame greater than the predetermined termination time, then abandon the partial data amount that said end audio frame surpasses said predetermined termination time; S224, when the timestamp of said end audio frame greater than the predetermined termination time, then abandon said end audio frame, the previous frame of said end audio frame is defined as new end audio frame, up to confirming to finish audio frame; When the timestamp of said end frame of video greater than the predetermined termination time, then abandon said end frame of video, the previous frame of said end frame of video is defined as new end frame of video, up to confirming to finish frame of video.
In the connection output intent of a kind of video file of the present invention, comprise step: S0 before the said step S1, at least two video files are carried out decoding processing.
The present invention also constructs a kind of connection output device of video file, comprising: timestamp smoothing processing module: be used for decoded at least two video files are carried out the timestamp smoothing processing; Registration process module: be used for said at least two video files after the timestamp smoothing processing are carried out registration process; And synthetic output module: be used for output is encoded, synthesized to said at least two video files after the registration process.
In the connection output device of a kind of video file of the present invention, said timestamp smoothing processing module comprises: the frame of video processing unit: be used for making said frame of video export by preset frame per second through the frame of video of decoded video file being carried out repeating frame or frame losing processing; And audio frame processing unit: be used for making said audio frame align by theoretical timestamp through mending quiet to the audio frame of decoded video file or abandoning corresponding voice data; Said registration process module comprises: superpositing unit alternately: be used for frame of video and audio frame that acquisition time alternately stabs the video file after the smoothing processing; And alignment unit: be used for said frame of video and the alignment of said audio frame; Said alignment unit comprises:
Device: be used for when said audio frame for finishing audio frame, and said audio frame finishes than said frame of video in advance, then after said audio frame finishes, alternately imports quiet data and said frame of video to the video data that finishes frame of video;
Device: be used for being the end audio frame when said audio frame; And said frame of video finishes than said audio frame in advance; Then after said frame of video finishes, the audio frame when alternately importing said frame of video and finishing is to the audio frame and the said end frame of video of said end audio frame;
Device: when being used for the end of output audio frame, when the timestamp of said end audio frame through duration of said end audio frame greater than the predetermined termination time, then abandon the partial data amount that said end audio frame surpasses said predetermined termination time;
Device: be used for when the timestamp of said end audio frame greater than the predetermined termination time, then abandon said end audio frame, the previous frame of said end audio frame is defined as new end audio frame, up to confirming to finish audio frame; When the timestamp of said end frame of video greater than the predetermined termination time, then abandon said end frame of video, the previous frame of said end frame of video is defined as new end frame of video, up to confirming to finish frame of video.
In the connection output device of a kind of video file of the present invention, the connection output device of said video file also comprises: decoder module: be used at least two video files are carried out decoding processing.
Adopt the connection output intent and the device of video file of the present invention, can the video file of a plurality of inputs be connected into a video file output, and can guarantee the playback rate and the synchronization extent of output video and output audio.
Through other timestamp smoothing processing of branch, make frame of video audio frame alignd according to theoretical timestamp by preset frame per second output to frame of video and audio frame.Alternately obtain frame of video and guaranteed that with said audio frame alignment frame of video is consistent with the audio frame broadcasting speed, dislocation can not occur with audio frame and with said frame of video.
Embodiment
In order to make the object of the invention, technical scheme and advantage clearer,, the present invention is further elaborated below in conjunction with accompanying drawing and embodiment.Should be appreciated that specific embodiment described herein only in order to explanation the present invention, and be not used in qualification the present invention.
As shown in Figure 1, in the schematic flow sheet of first preferred embodiment of the connection output intent of video file of the present invention, the connection output intent of said video file starts from step 100; Proceed to step 101 after the step 100, decoded at least two video files are carried out the timestamp smoothing processing; Subsequently, to next step 102, said at least two video files after the timestamp smoothing processing are carried out registration process; Subsequently, to next step 103, output is encoded, synthesized to said at least two video files after the registration process; This method ends at step 104 at last.The connection output intent of video file of the present invention carries out the processing respectively of frame of video and audio frame through the timestamp smoothing processing to decoded video file, reaches the effect that output needs; Make frame of video and the audio frame of video file align each other through registration process and be convenient to coding output, thereby realized the video file of a plurality of inputs is connected into a video file output.
As shown in Figure 2, in the schematic flow sheet of second preferred embodiment of the connection output intent of video file of the present invention, the connection output intent of said video file starts from step 200; Proceed to step 201 after the step 200, make said frame of video export by preset frame per second through the frame of video of decoded video file video file being carried out repeating frame or frame losing processing; Subsequently, to next step 202, make said audio frame align by theoretical timestamp through mending quiet to the audio frame of said decoded video file or abandoning corresponding voice data; Subsequently, to next step 203, said at least two video files after the timestamp smoothing processing are carried out registration process; Subsequently, to next step 204, output is encoded, synthesized to said at least two video files after the registration process; This method ends at step 205 at last.Frame of video is through repeating frame or frame losing, and audio frame is through mending quiet or frame losing reaches frame per second and the theoretical timestamp that output needs, and control is simple, is convenient to realize.
As shown in Figure 3, in the schematic flow sheet of the 3rd preferred embodiment of the connection output intent of video file of the present invention, the step S11 of the connection output intent of said video file starts from step 300; Proceed to step 301 after the step 300, obtain the theoretical timestamp of current video frame and said current video frame; Subsequently, to next step 302 and 303, in the step 302; The timestamp of current video frame is during less than the theoretical timestamp of said current video frame; Through an input video frame duration, turn back to step 301, in the step 303; The timestamp of current video frame is during more than or equal to the theoretical timestamp of said current video frame; Current video frame is set to current output video frame, and the output time of current video frame stabs and to be set to theoretical timestamp, after the step 303; To next step 304; The difference that current video frame and a last video frame time stab is more than or equal to the output video frame duration of twice, and a last frame of video is set to the output video frame between current video frame and the last frame of video, and the output time of going up a frame of video stab be set to the output video frame between a current video frame and the last frame of video theoretical timestamp with the assurance output frame rate; This method ends at step 305 at last.
The video flowing that decoding is come out from decoder device; Often not according to frame per second, but export, and the video flowing that code device need be imported to be imported by frame per second according to timestamp; And some user needs output file to satisfy specific frame per second; Therefore need handle frame of video, make it according to specific frame per second output, processing procedure is following:
1, calculates the theoretical timestamp=present frame sum/frame per second and calculating frame pitch=1/ frame per second of current video frame;
2, obtain current video frame;
If the timestamp of 3 current video frames is less than the theoretical timestamp of current video frame, so through an input video frame duration to obtain next frame, repeating step 2; Like the timestamp of current video frame theoretical timestamp, to step 4 more than or equal to current video frame;
4, the difference of the timestamp of a judgement current video frame and a last frame of video and the relation of 2 times of frame pitch;
If the difference of timestamp is greater than 2 times of frame pitch; Go up a frame of video so and be set to the output video frame between a current video frame and the last frame of video, and the output time of going up a frame of video stabs and to be set to its corresponding theory timestamp to guarantee that output frame rate be to preset frame per second; Current video frame is set to current output video frame simultaneously, and the output time of current video frame stabs the theoretical timestamp that is set to current video frame;
5, through the duration repeating step 1 of a frame pitch.
Whether need frame losing, the frame per second that for example need export to be 1 (also can be other numerals certainly, as 2,3 etc.) through the decision of step 302 and step 303; And the frame per second of input is 2; Promptly 1 second input 2 two field pictures, it is 0 second, 0.5 second, 1 second, 1.5 seconds, 2 seconds that the frame time of input video frame stabs sequence, in the time of 0 second; Obtain 0 second current frame of video; The timestamp of frame of video equals the theoretical timestamp of 0 second frame of video, and frame of video was set to current output video frame in 0 second, and the theory practice that the output time of frame of video is set to 0 second frame of video was stabbed 0 second; Through an input video frame duration, obtain 0.5 second current frame of video, the timestamp of the frame of video of this video is less than the theoretical timestamp of 1 second frame of video; Through returning a last step behind the input video frame duration; Obtain 1 second current frame of video, follow-up with the above, the frame per second that wants to export is 1; Just need abandon timestamp is 0.5 second, 1.5 seconds frame of video.Whether need repeating frame through step 304 decision, for example the frame per second of output is 1 (being to be 1 second the frame of video duration), if the timestamp (meaning of timestamp is to show this frame which second) of the frame of video of output is 1 second for the first time; So in theory; For the second time the timestamp of the frame of video of output is 2 seconds, is 4 like the timestamp of secondary frame of video of reality input, for by the frame per second output video frame; Repeated to export the frame of video of output for the first time at the 2nd, 3 second; Timestamp like secondary frame of video of reality input is 2.2, and the timestamp of revising secondary frame of video of actual input so was 2, exported this frame of video at the 2nd second.This processing method has well been carried out the timestamp smoothing processing to frame of video, makes that frame of video can be by preset frame per second output.
As shown in Figure 4, in the schematic flow sheet of the 4th preferred embodiment of the connection output intent of video file of the present invention, the step S12 of the connection output intent of said video file starts from step 400; Proceed to step 401 after the step 400, obtain the theoretical timestamp of current audio frame and said current audio frame; Subsequently, to next step 402; The timestamp of current audio frame is during less than the theoretical timestamp of said current audio frame; Then current audio frame abandons the data volume in time of difference of timestamp of theoretical timestamp and current audio frame of said current audio frame; Current audio frame is set to current output audio frame, and the output time of current audio frame stabs the theoretical timestamp that is set to said current audio frame; When the timestamp of current audio frame equaled the theoretical timestamp of said current audio frame, current audio frame was set to current output audio frame; When the timestamp of said current audio frame during greater than the theoretical timestamp of said current audio frame; Quiet data in the time of the difference of the timestamp of the additional said current audio frame of then said current audio frame and the theoretical timestamp of said current audio frame; Said current audio frame is set to current output audio frame, and the output time of said current audio frame stabs the theoretical timestamp that is set to said current audio frame.This method ends at step 403 at last.
The audio stream that decoding is come out from decoder device often not according to data volume, but is exported according to timestamp; And the video flowing that code device need be imported will be imported by data volume; And some user needs output file to satisfy specific frame per second, therefore need handle audio frame, makes it to export according to data volume; Handling principle is: the data volume=sample rate * channel number * sampled data output in 1 second of voice playing; Through losing data, mend quiet data, make the two continuous frames voice data satisfy the timestamp of duration (data volume in the data volume of first frame/1 second)=second frame that first frame time stabs the data volume of+the first frame.Processing procedure is following:
1, calculates the data volume in total amount of data/1 second of the theoretical timestamp of current audio frame=current input;
2, obtain current audio frame;
3, the relation of the theoretical timestamp of the timestamp of more current audio frame and current audio frame;
If the timestamp of current audio frame is less than the theoretical timestamp of current audio frame; Current audio frame abandons the data volume in time of difference of timestamp of theoretical timestamp and current audio frame of current audio frame; Current audio frame is set to current output audio frame, and the output time of current audio frame stabs the theoretical timestamp that is set to current audio frame;
If the timestamp of current audio frame equals the theoretical timestamp of current audio frame, current audio frame is set to current output audio frame;
If the timestamp of current audio frame is put into theoretical timestamp greater than current audio frame; Current audio frame replenishes the quiet data of the time of the timestamp of current audio frame and the difference that current audio frame is put into theoretical timestamp; Current audio frame is set to current output audio frame, and the output time of current audio frame stabs and to be set to current audio frame and to put into theoretical timestamp;
4, through repeating step 1 after the duration of current audio frame.
For example sample rate is 48000, and channel number is 2, and sampled data output 2 also with regard to saying that the data volume that voice playing needed in a second is 48000*2*2=192000, if the data total amount of current output is 192000, has just been exported 1 second data.In theory, the timestamp of the audio frame of next input is 1 second, if the timestamp of next frame voice data A is 0.7, will abandon 0.3 second data volume to voice data A so, i.e. the data of 0.3*192000, and alignment back voice data A was since 1 second.If the timestamp of next frame voice data A is 2, the quiet data that need mend so 1 second arrives the head of voice data A, makes A since 1 second, and promptly the head of audio frame A is mended the quiet data of 1*192000.Whether need mend quiet or abandon the operation of corresponding voice data through step 402 decision, make that audio frame can be by theoretical timestamp alignment output audio frame.
As shown in Figure 5, in the schematic flow sheet of the 5th preferred embodiment of the connection output intent of video file of the present invention, the connection output intent of said video file starts from step 500; Proceed to step 501 after the step 500, decoded at least two video files are carried out the timestamp smoothing processing; Subsequently, to next step 502; Alternately acquisition time stabs the frame of video and the audio frame of the video file after the smoothing processing, and with said frame of video and the alignment of said audio frame; Subsequently, to next step 503; Output is encoded, synthesized to said at least two video files after the registration process; This method ends at step 504 at last.Alignment has guaranteed that frame of video is consistent with the audio frame broadcasting speed with audio frame with audio frame and with frame of video alternately to obtain frame of video, dislocation can not occur.
As shown in Figure 6, in the schematic flow sheet of the 6th preferred embodiment of the connection output intent of video file of the present invention, the step S22 of the connection output intent of said video file starts from step 600; Proceed to step 601 after the step 600, when said audio frame for finishing audio frame, and said audio frame finishes than said frame of video in advance, then after said audio frame finishes, alternately imports quiet data and said frame of video to the frame of video that finishes frame of video; Subsequently, to next step 602; When said audio frame for finishing audio frame, and said frame of video finishes than said audio frame in advance, then after said frame of video finishes, the audio frame when alternately importing said frame of video and finishing is to the audio frame and the said end frame of video of said end audio frame; Subsequently; To next step 603; During the end of output audio frame, when the timestamp of said end audio frame through duration of said end audio frame greater than the predetermined termination time, then abandon the partial data amount that said end audio frame surpasses said predetermined termination time; Subsequently, to next step 604, when the timestamp of said end audio frame greater than the predetermined termination time, then abandon said end audio frame, the previous frame of said end audio frame is defined as the audio frame of new end, return step 603; When the timestamp of said end frame of video greater than the predetermined termination time, then abandon said end frame of video, the previous frame of said end frame of video is defined as the frame of video of new end; This method ends at step 605 at last.The registration process of this method is meant: when audio frame finishes in advance, in step 601, after audio frame finishes, alternately import quiet data and current video frame to the video data that finishes frame of video; When frame of video finishes in advance, in step 602, the audio frame when after frame of video finishes, replacing the input video frame end is to audio frame that finishes audio frame and end frame of video.Judge the audio frequency and video of output and the relation of the termination time of being scheduled to then; In step 603; The timestamp that finishes audio frame through duration of end audio frame greater than the predetermined termination time, then abandon the partial data amount that said end audio frame surpasses said predetermined termination time; In step 604, when the timestamp of the audio frame that finishes greater than the predetermined termination time, then abandon the audio frame of end, the previous frame of said end audio frame is defined as new end audio frame; When the timestamp that finishes frame of video greater than the predetermined termination time, then abandon said end frame of video, the previous frame of said end frame of video is defined as new end frame of video, finish audio frame and finish audio frame up to confirming.Such operation has guaranteed that well the broadcast of audio frequency and video is synchronous, the concluding time of the audio frequency and video of having alignd simultaneously and the time that needs to stop.
As shown in Figure 7, in the schematic flow sheet of the 7th preferred embodiment of the connection output intent of video file of the present invention, the connection output intent of said video file starts from step 700; Proceed to step 701 after the step 700, at least two video files are carried out decoding processing; Subsequently, to next step 702, decoded at least two video files are carried out the timestamp smoothing processing; Subsequently, to next step 703, said at least two video files after the timestamp smoothing processing are carried out registration process; Subsequently, to next step 704, output is encoded, synthesized to said at least two video files after the registration process; This method ends at step 705 at last.This method adds the process of decoding processing on original basis, be more convenient for the video file coding of a plurality of inputs to connect into a video file output.
The present invention also constructs a kind of connection output device of video file; As shown in Figure 8; In the structural representation of first preferred embodiment of the connection output device of video file of the present invention; The connection output device of said video file comprises timestamp smoothing processing module 1, registration process module 2 and synthetic output module 3; Timestamp smoothing processing module 1 is used for decoded at least two video files are carried out the timestamp smoothing processing; Registration process module 2 is used for said at least two video files after the timestamp smoothing processing are carried out registration process, and synthetic output module 3 is used for output is encoded, synthesized to said at least two video files after the registration process.The connection output device of video file of the present invention carries out the processing respectively of frame of video and audio frame through the timestamp smoothing processing of timestamp smoothing processing module 1 to decoded video file, reaches the effect that output needs; Registration process through registration process module 2 makes frame of video and the audio frame of video file align each other to be convenient to coding output, thereby has realized the video file of a plurality of inputs is connected into a video file output.
As shown in Figure 9, in the structural representation of second preferred embodiment of the connection output device of video file of the present invention, timestamp smoothing processing module 1 comprises frame of video processing unit 11 and audio frame processing unit 12; Registration process module 2 comprises alternately superpositing unit 21 and alignment unit 22.Frame of video processing unit 11 is used for making said frame of video export by preset frame per second through the frame of video of said video file being carried out repeating frame or frame losing processing; Audio frame processing unit 12 is used for making said audio frame align by theoretical timestamp through mending quiet to the audio frame of said video file or abandoning corresponding voice data; Alternately superpositing unit 21 is used for frame of video and the audio frame that acquisition time alternately stabs the video file after the smoothing processing, and alignment unit 22 is used for said frame of video and the alignment of said audio frame.Frame of video processing unit 11 is through the repeating frame or the frame losing of frame of video, and quiet or frame losing reaches frame per second and the theoretical timestamp that output needs to audio frame processing unit 12 through the benefit of audio frame, and control is simple, is convenient to realize.Alternately superpositing unit 21 alternately obtains frame of video and audio frame, and alignment has guaranteed that frame of video is consistent with the audio frame broadcasting speed to alignment unit 22 with audio frame with frame of video, dislocation can not occur.
Shown in figure 10; In the structural representation of the 3rd preferred embodiment of the connection output device of video file of the present invention; The connection output device of said video file also comprises decoder module 4, and decoder module 4 is used at least two video files are carried out decoding processing.This device adds the process of the decoding processing of decoder module 4 on original basis, be more convenient for the video file coding of a plurality of inputs to connect into a video file output.
The above is merely embodiments of the invention; Be not so limit claim of the present invention; Every equivalent structure transformation that utilizes specification of the present invention and accompanying drawing content to be done, or directly or indirectly be used in other relevant technical fields, all in like manner be included in the scope of patent protection of the present invention.