Summary of the invention
The technical problem to be solved in the present invention provides the method and system that a kind of multimedia file audio-visual synchronization is play, and this method or system stab when not required, under the not real-time situation of decoding, also can realize synchronously, and adapt to the platform of nonidentity operation ability automatically; In addition, little to taking of hardware resource, software complexity is also very low; Can effectively reduce cost.
In order to address the above problem, the invention provides a kind of multimedia file audio-visual synchronization playing system, comprising:
The video-audio signal dividing cell is used for multi-medium data is divided into voice data and video data and output;
Audio treatment unit is used for the voice data of described video-audio signal dividing cell output is decoded and play;
Video processing unit is used for the video data of described video-audio signal dividing cell output is decoded and play;
Also comprise:
Audio-visual synchronous control unit, be used to detect the playing progress rate of described audio treatment unit, and itself and a predetermined value compared, when playing progress rate during greater than this predetermined value, send the Synchronization Control instruction to described video-audio signal dividing cell, indication video-audio signal dividing cell reads the video data of respective frame and exports broadcast.
Further, described audio-visual synchronous control unit comprises voice playing detecting module and order sending module, wherein,
The playing progress rate that described voice playing detecting module is used to the to detect described audio treatment unit sound intermediate frequency playing module line item of going forward side by side, described voice playing detecting module compares playing progress rate and described predetermined value, when playing progress rate during greater than this predetermined value, send control information to described order sending module, the playing progress rate that is write down is deducted described predetermined value and on this difference basis, continue the recording played progress;
Described order sending module is used for after receiving described control information sending described Synchronization Control and instructs video data read module to described video-audio signal dividing cell;
Described video data read module, the feedback information that is used for will whether responding the Synchronization Control instruction after receiving the instruction of described Synchronization Control sends to described order sending module;
Described order sending module also is used for determining according to this feedback information the frame number of next bar Synchronization Control instruction needs reading video data.
Further, described voice playing detecting module comprises the coincidence counter and first comparator, described coincidence counter be used for when audio playing module when an audio frequency buffer module reads a voice data of playing unit, counting is once; Described first comparator is used for the count value and the described predetermined value of comparison coincidence counter,, sends control information to described order sending module, and count value is deducted described predetermined value during greater than predetermined value at synchronometer numerical value.
Further, the counting step-length step of described coincidence counter is obtained by following formula:
step=rate*Length;
Described predetermined value gate obtains by following formula:
gate=scale*Fs;
In the formula, Length is the size of voice playing buffer, and Fs is the audio data samples rate, and scale is the time scale of video flowing, and rate is the time scale of video flowing and the ratio of every frame video data reproduction time.
Further, described order sending module comprises a command counter, and this command counter is used for after the control information that receives the transmission of voice playing detecting module, sends Synchronization Control and instructs to the video data read module, and its counting is added 1; Described video data read module receives the count value N+1 of described Synchronization Control instruction back according to command counter, reads the following N+1 video data and the output frequently of present frame and plays; And the feedback information that described command counter receives the transmission of video data read module is when responding the Synchronization Control instruction, its counting of zero clearing.
Further, described order sending module comprises second command counter, response count device and second comparator, wherein,
Described second command counter adds 1 with its count value after being used to receive the control information that the voice playing detecting module sends;
Described response count device is used to receive feedback information that the video data read module sends and its count value is added 1 after for the instruction of response Synchronization Control;
Described second comparator is used for the value of more described second command counter and response count device, when described response count device does not have count value, sends the Synchronization Control that reads the next frame video data and instructs to the video data read module; When described second command counter during than the big M of value of response count device, the Synchronization Control that sends the following M frame video data that reads present frame is instructed to the video data read module; After the video data read module sends the feedback information of response Synchronization Control instruction to described second comparator, the second comparator zero clearing, second command counter and response count device.
Further, this system also comprises a timer, is used for when described multi-medium data does not have voice data, carries out timing according to the reproduction time of the every frame video data in the described multi-medium data, every when reaching regularly, one-frame video data is also play in the decoding of notice video data processing unit.
The method that the present invention also provides a kind of multimedia file audio-visual synchronization to play may further comprise the steps:
Calculate the playing progress rate parameter and the predetermined value of voice data according to the multi-medium data of playing;
Multi-medium data is divided into voice data and video data, decodes and show the first frame video data, enter the Audio Processing flow process simultaneously, decoding and playing audio-fequency data;
Detect the playing progress rate of voice data and the playing progress rate of audio data and whether reach described predetermined value, if reach, the control of video processing unit enters the Video processing flow process, the video data of decoding and demonstration respective frame.
Further, the method whether playing progress rate of described audio data reaches described predetermined value is: when the voice data of unit is play in one of every broadcast, counting once, count value and described predetermined value are compared, if count value is greater than predetermined value, then playing progress rate reaches predetermined value, and the playing progress rate that is write down is deducted described predetermined value, and continues the recording played progress on this difference basis.
Further, described control of video processing unit enters the step of Video processing flow process and is finished by an order sending module, when playing progress rate reaches predetermined value, the order sending module adds 1 with the counting of a command counter, and the transmission Synchronization Control is instructed to the video data read module, described video data read module receives the count value N+1 of described Synchronization Control instruction back according to command counter, reads the following N+1 video data and the output frequently of present frame and plays; And the feedback information that described command counter receives the transmission of video data read module is when responding the Synchronization Control instruction, its counting of zero clearing.
Further, the method that described control of video processing unit enters the Video processing flow process is: when playing progress rate reaches predetermined value, one second command counter is added 1; After the feedback information that the video data read module that receives sends instructs for the response Synchronization Control, one response count device is added 1, the value that compares second command counter and response count device with one second comparator, when described response count device does not have count value, send the Synchronization Control that reads the next frame video data and instruct to the video data read module; When described second command counter during than the big M of value of response count device, the Synchronization Control that sends the following M frame video data that reads present frame is instructed to the video data read module; Described second comparator is after the feedback information that the video data read module that receives sends instructs for the response Synchronization Control, with the count value zero clearing of described command counter and response count device.
The beneficial effect that the present invention produced is, by the playing progress rate that detects audio frequency come that control of video plays synchronously, do not need to comprise in the multi-medium data timestamp, can effectively alleviate the burden of encoder and decoder; Synchronization Control process operand is little, is applicable to the platform that operational capability is relatively poor, the audio-visual synchronization in the time of therefore can being widely used in the portable mobile apparatus play multimedia data; The present invention is very low to the requirement of hardware platform, and hardware platform is simple in structure, and cost is low.
Embodiment
The invention will be further described below in conjunction with the drawings and specific embodiments, can be implemented so that those skilled in the art can better understand the present invention also, but illustrated embodiment is not as a limitation of the invention.
The system of multimedia audio-video synchronous playing of the present invention comprises as shown in Figure 1:
Video-audio signal dividing cell 11, the multi-medium data that is used for being stored in file is divided into independently voice data and video data, and video-audio signal dividing cell 11 comprises voice data read module 111 and video data read module 112 again;
Voice data processing unit 12, be used for voice data is handled, comprise audio decoder module 121, audio frequency buffer module 122 and audio playing module 123 again, wherein, audio decoder module 121, be used for the output of voice data read module 111 is decoded, the result leaves in the audio frequency buffer module 122; Audio playing module 123 is responsible for the data in the audio plays buffer module 122;
Video data processing unit 13, be used for video data is handled, comprise video decode module 131, video buffer module 132 and video playback module 133 again, wherein, video decode module 131, be used for the output of video data read module 112 is decoded, the result leaves in the video buffer module 132; Video playback module 133 is used for the data of video buffer module 132 are play.
The internal structure of the above-mentioned functions unit module all internal structure with the corresponding functional unit that is adopted in the existing audio-visual synchronization treatment technology is identical, no longer the processing procedure and the internal structure of each functional unit and module are further set forth at this, and the division of above-mentioned functions module is only for describing the present invention, still can adopt other Module Division method that possesses above-mentioned functions to constitute the present invention, all can adopt same buffer module as audio frequency buffer module 122 and video buffer module 132.The present invention also comprises on the basis of existing technology:
Audio-visual synchronous control unit 14, it comprises a voice playing detecting module 141 and an order sending module 142, voice playing detecting module 141 detects the playing progress rate of audio playing module 123 and playing progress rate is carried out record, voice playing detecting module 141 compares the voice playing progress and a predetermined value of record, when playing progress rate during greater than predetermined value, voice playing detecting module 141 sends control information to order sending module 142, and continues counting after making the playing progress rate value of storing deduct predetermined value; After order sending module 142 receives control information, send the video playback Synchronization Control and instruct the video data that reads respective frame to video data read module 112, the feedback information whether video data read module 112 will respond the Synchronization Control instruction sends to order sending module 142, and order sending module 142 is determined the frame number of next bar video playback Synchronization Control instruction needs reading video data according to feedback information.
Wherein, as shown in Figure 2, voice playing detecting module 141 comprises a coincidence counter 1411 and first comparator 1412, when audio playing module 123 reads the data of a broadcast unit from audio frequency buffer module 122, coincidence counter 1411 is just counted once, and step-length is step; First comparator 1412 is the value and the threshold value gate (being predetermined value) of coincidence counter 1411 relatively, when synchronometer numerical value during greater than threshold value gate, just send control information to order sending module 142, coincidence counter 1411 count values deduct threshold value gate and continue counting.Voice playing detecting module 141 relatively judges whether to send control information to order sending module 142 according to voice data broadcast situation of counting in the coincidence counter 1411 and threshold value, thereby the broadcast of control of video data so just can realize coming by the voice playing progress purpose of synchronization video playing progress rate.
Wherein, as shown in Figure 2, order sending module 142 comprises a command counter 1421, after the control information that receives 141 transmissions of voice playing detecting module, just send the video playback Synchronization Control and instruct to video data read module 112, the count value of command counter 1421 adds 1 simultaneously, if the feedback information that the video data read module that receives 112 sends is the instruction of response Synchronization Control, then the zero clearing command counter 1421, otherwise do not carry out clear operation.If video data read module 112 receives all not responses of the subsynchronous control command of N, after then receiving the Synchronization Control commanded response once more, video data read module 112 is skipped the video data that the N frame reads down the N+1 frame according to the count value N+1 of command counter 1421 from present frame.The command counter 1421 of order in the sending module 142 counted according to the control information and the responsive feedback information that receive, thereby obtains the frame number (the following N+1 frame of present frame) of the video data that next Synchronization Control instruction need read.And then take place when asynchronous at audio, video data, directly read the video data of respective frame according to the playing progress rate of voice data.
In addition, as shown in Figure 3, order sending module 142 can also adopt following manner to constitute: comprise one second command counter 1422 and a response count device 1423, and one second comparator 1424, its count value just adds 1 after the control information that second command counter, 1422 reception voice playing detecting modules 141 send, the feedback information that the video data read module 112 that response count device 1423 receives sends just adds 1 for its count value of response Synchronization Control instruction back, second comparator 1424 compares the count value of second command counter 1422 and response count device 1423, when response count device 1423 no count values, just send the video playback Synchronization Control that reads the next frame video image and instruct to video data read module 112.If the count value of second command counter 1422 than the big M of count value of response count device 1423, is instructed to video data read module 112 just send the Synchronization Control of the following M frame video image that reads present frame.After video data read module 112 feeds back to second comparator, 1424 response Synchronization Control command informations, two counters of second comparator, 1424 zero clearings.
Wherein, voice data read module 111 is that unit reads audio compression data continuously with piece (Block) from source file.
Wherein, 123 of audio frequency buffer module 122 and audio playing module are carried out transfer of data with less broadcast unit (for example 32 sampled points).The reproduction time of supposing a unit data of broadcast is Ta, and the maximum synchronous error of establishing permission is Emax, and then Ta<Emax gets final product.
Wherein, control command and parameter that video data read module 112 provides according to audio-visual synchronous control unit 14 are that unit reads to the video compression data in the source file with frame (Frame).
Make audio playing module 123 play a time T a who plays the unit voice data, much smaller than the demonstration time T v of video data one frame.Because the demonstration time T v of every frame video data fixes, the artificial setting when playing a time T a who plays the unit voice data and then being playing audio-fequency data.Because this method, the counting that can make coincidence counter just sends control information to order sending module 142 during greater than threshold value gate, and coincidence counter 1411 count values deduct gate.And the count value that coincidence counter 1411 count values deduct behind the gate is counted once more, and therefore counting is on the basis of difference once more, therefore can produce error.Because this error, the frame of video interval error of this method is positive and negative replacing in theory, thus synchronous error can not accumulate, all the time less than Ta.Test shows, when the broadcast unit of voice data hour (for example 32 sampled points), human eye is discovered less than the error less than Ta.In order further to reduce error, artificial setting audio playing module 123 is play a time T a who plays the unit voice data, much smaller than the demonstration time T v of video data one frame.
When concrete calculating,
Ta=Length/Fs (1),
In the formula, Length is the size of play-out buffer, and Fs is the audio data samples rate.
Tv has different expression formulas to different multimedia data formats, for example to AVI (AudioVideo Interleaved) file,
Tv=scale/rate (2),
In the formula, scale is the time scale of video flowing, and this parameter of rate does not have clear and definite meaning.Illustrate: the frame frequency of archives is 29.96fps, Tv=1/29.96 so, and this is a decimal, because the restriction of machine word length, can loss of accuracy when calculating.If write as Tv=100/2996, when calculating, just do not have decimal and scale=100 in this example, rate=2996 occur.Certainly, also can be write as scale=200, rate=5992, its meaning is the same.This only is the agreement of this form of AVI.Can draw according to above-mentioned formula (1) and formula (2):
Tv/Ta=(scale*Fs)/(rate*Length) (3);
Parameter in the formula preferably all is an integer, so that calculate.
Make step=rate*Length, gate=scale*Fs can obtain the step value step of coincidence counter and threshold value (predetermined value) gate.
For there not being voice data, have only the file of video data, can press default setting by audio treatment unit and play quiet data, come the broadcast of control of video data; For the file of voice playing total time less than video playback total time, after voice playing finishes, also can play quietly, finish up to video playback.In addition, a timer also can be set, when the voice data read module is judged received video-audio signal and is not had voice data, do not start the Audio Processing flow process, and start this timer, this timer connects video data read module, carries out timing according to the frame period of video, and the broadcast of video is controlled.
As shown in Figure 4, the method for multimedia file audio-visual synchronization broadcast of the present invention comprises the steps:
Step 41, system initialization is according to the audio, video data calculation of parameter voice playing progress parameter and the predetermined value that show and play;
Step 42 enters the Video processing flow process, decodes and shows the first frame video data, enters the Audio Processing flow process, decodes and plays the voice data that first plays unit;
Step 43 enters audio-visual Synchronization Control flow process, judges whether to send the instruction of video playback Synchronization Control according to voice playing progress situation, if send the instruction of video playback Synchronization Control, execution in step 44; If do not send the instruction of video playback Synchronization Control, execution in step 47;
Step 44 judges whether the Video processing flow process responds this video playback Synchronization Control instruction, if the Video processing flow process responds this video playback Synchronization Control instruction, execution in step 45; If the Video processing flow process does not respond this video playback Synchronization Control instruction, execution in step 46;
Step 45 enters the Video processing flow process, the video data of decoding and demonstration respective frame;
Step 46 is still play the video data of present frame;
Step 47 is hung up the Video processing flow process, no longer carries out the Video processing of next frame.
In step 42, the step of Audio Processing flow process is as shown in Figure 5: voice data read module 111 is that unit reads audio compression data (step 4211) continuously with piece (Block) from multimedia source files, deliver to audio decoder module 121 decode (step 4212), decoded data are stored in audio frequency buffer module 122, and the data in 123 pairs of audio frequency buffer modules 122 of audio playing module are play (step 4213).During broadcast, 123 of audio frequency buffer module 122 and audio playing module are carried out transfer of data with less broadcast unit (for example 32 sampled points).
In step 42, the step of Video processing flow process is as shown in Figure 6: instruction of video playback Synchronization Control and parameter that video data read module 112 provides according to audio-visual synchronous control unit 14, is that unit reads (step 4221) to the video compression data in the multi-medium data source file with frame (Frame), deliver to video decode module 131 decode (step 4222), the result is stored in the video buffer module 132 (step 4223), and the data in 133 pairs of video buffer modules 132 of video playback module are play (step 4224).
In step 43, audio-visual Synchronization Control flow process is as shown in Figure 7: detect the playing progress rate of audio playing module 123 and playing progress rate is write down (step 431), the voice playing progress and a predetermined value of record are compared (step 432), when playing progress rate during greater than predetermined value, the playing progress rate value of order storage deducts predetermined value, and send the video playback Synchronization Control and instruct the video data (step 433) that reads respective frame to video data read module 112, the feedback information whether video data read module 112 will respond the Synchronization Control instruction sends, and determines the frame number (step 434) of next bar Synchronization Control instruction needs reading video data according to this feedback information.
In the above-mentioned steps 43, the audio frequency detecting can be finished by a voice playing detecting module 141.As shown in Figure 8, voice playing detecting module 141 carries out the audio frequency detecting and comprises the steps: when audio playing module 123 reads the voice data of a broadcast unit from audio frequency buffer module 122, one coincidence counter 1411 is just counted once, step-length is playing progress rate parameter s tep (step 81), first comparator 1412 is the count value and the threshold value (being above-mentioned predetermined value) (step 82) of coincidence counter 1411 relatively, when the count value of coincidence counter 1411 during greater than threshold value gate, just send control information to an order sending module 142, coincidence counter 1411 count values deduct gate (step 83) and continue counting.Voice playing detecting module 141 according to the voice data of counting in the coincidence counter 1411 play situation and threshold value relatively judge whether to send control information to ordering sending module, thereby the broadcast of control of video data.So just, can realize coming the purpose of synchronization video playing progress rate by the voice playing progress.
As shown in Figure 9, the step of order sending module 142 transmission video playback Synchronization Control instructions comprises:
Step 91: judge whether order sending module 142 receives the control information that voice playing detecting module 141 sends, if receive, execution in step 92; If do not receive, wait for that voice playing detecting module 141 sends control information;
Step 92: send the video playback Synchronization Control and instruct to video data read module 112, command counter 1421 adds 1 simultaneously;
Step 93: whether the feedback information of judging video data read module 112 transmissions of receiving is the instruction of response Synchronization Control, if, execution in step 94; If not, execution in step 95;
Step 94: video data read module 112 is skipped the video data that the N frame reads down the N+1 frame according to the count value N+1 of command counter 1421 from present frame, zero clearing command counter 1421;
Step 95: command counter 1421 is not carried out clear operation and returns step 91.
In the step 94, if video data read module 112 receives all not responses of the subsynchronous control command of N, after then receiving the Synchronization Control commanded response once more, this moment, the count value of command counter was N+1, and video data read module 112 is skipped the video data that the N frame reads down the N+1 frame according to the counting of command counter 1421 from present frame.The command counter 1421 of order in the sending module 142 counted according to the control information and the responsive feedback information that receive, thereby obtains the frame number (the following N+1 frame of present frame) of the video data that next Synchronization Control instruction need read.And then take place when asynchronous at audio, video data, directly read the video data of respective frame according to the playing progress rate of voice data.
As shown in figure 10, order sending module 142 transmitting control commands can also adopt another kind of scheme, and this scheme comprises the steps:
Step 101: second command counter 1422 judges whether to receive the control information that voice playing detecting module 141 sends, if receive, and execution in step 102; If do not receive, continue to wait for that voice playing detecting module 141 sends control information;
Step 102: the value of second command counter 1422 adds 1;
Step 103: response count device 1423 judges whether the feedback information of video data read module 112 transmissions that receive is the instruction of response Synchronization Control, if, execution in step 104; If not, the feedback information of the response Synchronization Control instruction that video data read module 112 sends is waited in continuation;
Step 104: the value of response count device 1423 adds 1;
Step 105: second comparator 1424 compares the count value of second command counter 1422 and response count device 1423, when response count device 1423 no count values, just send the video playback Synchronization Control that reads the next frame video data and instruct to video data read module 112; If the counting of second command counter 1422 than the big M of counting of response count device 1423, instructs to video data read module 112 just send the video playback Synchronization Control of the following M frame video data that reads present frame;
Step 106: second comparator 1424 judges whether the feedback information of video data read module 112 transmissions that receive is the instruction of response Synchronization Control, if carry out step 107 down; If not, the feedback information of the response Synchronization Control instruction that video data read module 112 sends is waited in continuation;
Step 107: second comparator 1424 zero clearings, second command counter 1422 and the response count device 1423.
The present invention is when play multimedia files, and the principle of audio, video data synchronous playing is as follows:
Audio playing module 123 is play a time T a who plays the unit voice data, much smaller than the demonstration time T v of video data one frame.Because this method, the counting that can make coincidence counter just sends control information to order sending module 142 during greater than threshold value gate, and coincidence counter 1411 count values deduct gate.And the count value that coincidence counter 1411 count values deduct behind the gate is counted once more, and therefore counting is on the basis of difference once more, therefore can produce error.Because this error, the frame of video interval error of this method is positive and negative replacing in theory, so synchronous error can not accumulated, all the time less than Ta, test shows, when the broadcast unit of voice data hour (for example 32 sampled points), human eye is discovered less than the error less than Ta.
During concrete calculating, Ta=Length/Fs, Length are the size of play-out buffer, and Fs is the audio data samples rate; Tv has different expression formulas to different multimedia data formats, and for example to avi file, Tv=scale/rate, scale are the time scale of video flowing, Tv/Ta=(scale*Fs)/(rate*Length).Parameter in the formula all is an integer preferably, is convenient to calculate.Make step=rate*Length; Gate=scale*Fs.
Among the present invention, under the real-time situation of video decode, second command counter 1422 has only 0,1 two kind of value.Under the not real-time situation of video decode, the Video processing flow process does not also respond a synch command, new order has produced again, second command counter 1422 will constantly be counted, till the response of Video processing flow process, if at this moment the value of second command counter 1422 is N, then can pass to video data read module 112 to N, the video data read module is when reading video data from source file, can directly read the following N frame of present frame, send into Video Decoder and decode, thereby realize audio-visual synchronization.
For there not being voice data, have only the file of video data, the Audio Processing flow process can be play quiet data by default setting, comes the broadcast of control of video data; For the file of voice playing total time less than video playback total time, after voice playing finishes, also can play quietly, finish up to video playback.In addition, also can set the time by a timer, when whenever reaching setting-up time, just send Synchronization Control and instruct to the video data read module, order video data read module reads the one-frame video data broadcast of decoding.The time of this setting is generally the demonstration time of every frame video data in the video data.
The above embodiment is the preferred embodiment that proves absolutely that the present invention lifts, and protection scope of the present invention is not limited thereto.Being equal to that those skilled in the art are done on basis of the present invention substitutes or conversion, all within protection scope of the present invention.Protection scope of the present invention is as the criterion with claims.