[go: up one dir, main page]

CN101212679B - AV synchronization method and device for switching multi-channel audio stream during playing of AVI file - Google Patents

AV synchronization method and device for switching multi-channel audio stream during playing of AVI file Download PDF

Info

Publication number
CN101212679B
CN101212679B CN 200610172268 CN200610172268A CN101212679B CN 101212679 B CN101212679 B CN 101212679B CN 200610172268 CN200610172268 CN 200610172268 CN 200610172268 A CN200610172268 A CN 200610172268A CN 101212679 B CN101212679 B CN 101212679B
Authority
CN
China
Prior art keywords
audio
data
video
stream
frame
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN 200610172268
Other languages
Chinese (zh)
Other versions
CN101212679A (en
Inventor
石学会
刘勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
BEIJING SUNPLUS-EHUE TECHNOLOGY Co Ltd
Sunplus Technology Co Ltd
Original Assignee
Beijing Sunnorth Electronic Technology Co ltd
Sunplus Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Sunnorth Electronic Technology Co ltd, Sunplus Technology Co Ltd filed Critical Beijing Sunnorth Electronic Technology Co ltd
Priority to CN 200610172268 priority Critical patent/CN101212679B/en
Publication of CN101212679A publication Critical patent/CN101212679A/en
Application granted granted Critical
Publication of CN101212679B publication Critical patent/CN101212679B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Compression Or Coding Systems Of Tv Signals (AREA)
  • Television Signal Processing For Recording (AREA)

Abstract

An AV synchronization method for switching multi-channel audio stream when playing AVI file is applied to a system comprising a switching control unit, a data transmission unit, a data processing unit and a data decoding unit, wherein when playing AVI file such as user switching audio stream, the switching control unit sends switching instruction to the data processing unit and the data decoding unit; the data decoding unit returns the current decoded video frame number; the switching control unit calculates to obtain a retransmission position and a synchronous playing parameter according to the video frame number, the index information and the file header information, and respectively sends the retransmission position and the synchronous playing parameter to the data transmission unit and the data decoding unit; and after the data decoding unit completes the reinitialization of the audio and video decoding, the audio and video data which are retransmitted are decoded, and whether the decoded audio and video data are transmitted to the data display unit for synchronous playing is determined according to the synchronous playing parameters. The method can keep AV synchronization after switching the audio stream when playing the AVI file containing one path of Divx video coding data and multiple paths of audio data.

Description

AVI文件播放时切换多路音频流的AV同步方法及装置AV synchronization method and device for switching multiple audio streams during AVI file playback

技术领域 technical field

本发明主要涉及音视频播放领域,尤其涉及一种应用于嵌入式系统中保持含一路Divx视频编码数据、多路音频数据的AVI文件在切换播放的音频数据时音视频(AV)同步的方法和装置。The present invention mainly relates to the field of audio and video playback, and in particular to a method for keeping audio and video (AV) synchronization when switching audio data played by an AVI file containing one Divx video encoding data and multiple audio data in an embedded system and device.

背景技术 Background technique

先对文中出现的相关技术术语进行解释:First explain the relevant technical terms that appear in the text:

I帧:关键视频帧,无损压缩的视频图片,此文件中所有引用I帧的地方,指的都是视频帧;I frame: key video frame, lossless compressed video picture, all references to I frame in this file refer to video frame;

Divx:一种视频编码格式;Divx: a video encoding format;

AV:Audio and Video,音频和视频;AV: Audio and Video, audio and video;

CBR:固定码流;CBR: fixed code stream;

VBR:可变码流;VBR: variable bit stream;

SPHE1001N:Sunplus Home Entertainment 1001N;SPHE1001N: Sunplus Home Entertainment 1001N;

STB:全称为Set-Top-Box即机顶盒;STB: The full name is Set-Top-Box, which is the set-top box;

AVI:Audio Video Interleaved,音视频数据交叉存取。AVI: Audio Video Interleaved, audio and video data interleaved access.

AVI(Audio Video Interleaved(交叉存取))是最常用的一种媒体文件格式,多用于音视频捕捉、编辑、回放等应用程序中。通常情况下,一个AVI文件可以包含多个不同类型的媒体流。通常AVI文件包含的媒体流为含有一个视频流和一个音频流,但含有一个视频流和几个音频流的AVI文件也是合法的。AVI (Audio Video Interleaved (interleaved access)) is the most commonly used media file format, mostly used in audio and video capture, editing, playback and other applications. Usually, an AVI file can contain multiple media streams of different types. Usually the media stream contained in an AVI file is a video stream and an audio stream, but an AVI file containing a video stream and several audio streams is also legal.

如图1所示,AVI文件结构主要包括三部分:AVI文件头、音视频数据、索引信息。As shown in FIG. 1 , the AVI file structure mainly includes three parts: AVI file header, audio and video data, and index information.

其中从AVI文件头,可获得的信息包括:AVIMAINHEADER(AVI主文件头)信息、格式信息、音频流数、视频流时间尺度和速率指标、音视频数据开始位置Movie_Offset、音视频数据整体大小Movie_Size、VBR音频流的采样率或者CBR音频流的字节率等信息。其中,AVI文件中音频流通常为两种编码格式VBR音频或者CBR音频,故根据情况解析相应参数。Wherein from the AVI file header, the information that can be obtained includes: AVIMAINHEADER (AVI main file header) information, format information, audio stream number, video stream time scale and rate index, audio and video data start position Movie_Offset, audio and video data overall size Movie_Size, Information such as the sampling rate of the VBR audio stream or the byte rate of the CBR audio stream. Among them, the audio stream in the AVI file is usually two encoding formats, VBR audio or CBR audio, so the corresponding parameters are analyzed according to the situation.

其中音视频数据部分为以数据块为单位依次交叉存放各路音视频实际数据。如图2所示。Among them, the audio and video data part is to interleave and store the actual audio and video data of each channel sequentially in units of data blocks. as shown in picture 2.

其中INDEX由索引信息块列表组成,每个索引信息块对应AVI文件中每个音频或视频数据块,该索引信息块依照AVI文件中音、视频数据块交错排列形式依次排列形成列表,每个索引信息块包含:数据块标志(是视频数据块、音频数据块还是填充的空白数据块,对于音频数据块还包括属于哪一路音频流的标志)、是否是关键帧标志(即I帧的标志)、是组合数据块标志(即多个数据块组合为一个数据组合)或是单数据块(一个数据块,它可以是一个帧,或者多个帧)、偏移量dwOffset(索引每路中每音/视频数据块对应在文件中距离文件头或音视频数据头的偏移),以及对应音/视频数据块的字节数。Among them, INDEX is composed of a list of index information blocks. Each index information block corresponds to each audio or video data block in the AVI file. The information block includes: a data block mark (is it a video data block, an audio data block or a filled blank data block, and the audio data block also includes the mark of which audio stream it belongs to), whether it is a key frame mark (that is, the mark of the I frame) , is the combination data block flag (that is, multiple data blocks are combined into one data combination) or single data block (a data block, which can be a frame, or multiple frames), offset dwOffset (each The audio/video data block corresponds to the offset from the file header or the audio/video data header in the file), and the number of bytes corresponding to the audio/video data block.

对于视频数据一般情况下一个数据块对应一帧;对于VBR的音频数据来说,一个数据块对应一个音频帧,对于CBR的音频数据,数据块和音频帧之间没有绝对的对应关系。在AVI文件中会有少数的如下情况:几个音频数据块组合为一个组合数据块。For video data, one data block generally corresponds to one frame; for VBR audio data, one data block corresponds to one audio frame, and for CBR audio data, there is no absolute correspondence between data blocks and audio frames. There are a few cases in AVI files as follows: several audio data blocks are combined into one combined data block.

由于AVI视频文件不含有精确的、均匀分布的时间戳信息。对于非切换过程的AV同步,主要是在初始化解码器前,从音视频流头信息中读取每个流的时间尺度参数和速率参数,根据这两类参数分别初始化音视频解码器的解码速率,从而保持AV同步。而在播放含有一路Divx视频编码数据、多路音频数据的AVI文件,当切换播放的音频数据时,就需要重新计算出音频、视频播放的精确位置,以保证AV同步。Because AVI video files do not contain accurate, evenly distributed time stamp information. For AV synchronization in the non-switching process, it is mainly to read the time scale parameter and rate parameter of each stream from the audio and video stream header information before initializing the decoder, and initialize the decoding rate of the audio and video decoder according to these two types of parameters , thus maintaining AV synchronization. And when playing the AVI file containing one Divx video encoding data and multiple audio data, when switching the audio data to be played, it is necessary to recalculate the precise position of audio and video playback to ensure AV synchronization.

本发明是基于嵌入式系统,解码工作由硬件芯片完成,数据传输控制由软件完成,以降低嵌入式系统运行要求,加快解码速度。但采用硬件解码时,数据传输的位置信息及数据解码的位置信息等保持AV同步所需的信息需要在各个单元之间传递,工作的控制和协调较难实现,目前还没有这样的一种方法。The invention is based on the embedded system, the decoding work is completed by the hardware chip, and the data transmission control is completed by the software, so as to reduce the operating requirements of the embedded system and accelerate the decoding speed. However, when hardware decoding is used, the information required to maintain AV synchronization, such as the position information of data transmission and the position information of data decoding, needs to be transmitted between each unit, and the control and coordination of work is difficult to achieve. There is no such method at present. .

发明内容 Contents of the invention

本发明要解决的技术问题是提供一种AVI文件播放时切换多路音频流的AV同步方法及装置,在播放含有一路Divx视频编码数据、多路音频数据的AVI文件时,切换音频流后可保持AV同步。The technical problem to be solved by the present invention is to provide an AV synchronization method and device for switching multiple audio streams when an AVI file is played. Keep AV in sync.

为了解决上述技术问题,本发明提供了一种AVI文件播放时切换多路音频流的AV同步方法,应用于包括切换控制单元、数据传输单元、数据处理单元和数据解码单元的系统,在播放含有多路音频流的AVI文件时,先保存AVI文件头信息,当用户切换音频流后,执行以下步骤:In order to solve the above-mentioned technical problems, the present invention provides an AV synchronization method for switching multiple audio streams when an AVI file is played, which is applied to a system including a switching control unit, a data transmission unit, a data processing unit, and a data decoding unit. When the AVI file of multiple audio streams is used, the AVI file header information is saved first. After the user switches the audio stream, the following steps are performed:

(a)切换控制单元收到切换请求后,向数据处理单元和数据解码单元发送切换指令;(a) After receiving the switching request, the switching control unit sends switching instructions to the data processing unit and the data decoding unit;

(b)数据解码单元向切换控制单元回传当前解码的视频帧数;(b) the data decoding unit returns the currently decoded video frame number to the switching control unit;

(c)切换控制单元根据当前解码的视频帧数和保存的索引信息、文件头信息计算得到重传位置和同步播放参数,将重传位置发送到数据传输单元,将同步播放参数发送到数据解码单元,所述同步播放参数为计算出的音频跳过数目Skip_audio和视频跳过数目Skip_Frame;(c) The switching control unit calculates the retransmission position and synchronous playback parameters according to the number of currently decoded video frames and the saved index information and file header information, sends the retransmission position to the data transmission unit, and sends the synchronous playback parameters to the data decoder unit, the synchronous playback parameter is the calculated audio skip number Skip_audio and video skip number Skip_Frame;

(d)数据传输单元按指定重传位置重新传输AVI文件的音视频数据,数据处理单元接收到音视频数据后分离出视频流和应切换到的那路音频流;数据解码单元完成视频解码的重新初始化,并按要切换到的那路音频流的参数重新进行音频解码的初始化;(d) The data transmission unit retransmits the audio-video data of the AVI file by the specified retransmission position, and the data processing unit separates the video stream and the audio stream that should be switched to after receiving the audio-video data; the data decoding unit completes video decoding Re-initialize, and re-initialize the audio decoding according to the parameters of the audio stream to be switched to;

(e)数据解码单元接收到重新传输的音视频数据后,所述数据解码单元对重新传输的音视频流开始部分的Skip_audio个字节数或帧数以及Skip_Frame个视频帧,解码后不传输到数据显示单元,之后解码的音视频数据再传输到数据显示单元进行同步播放,其中对固定码流采用字节数,对可变码流采用帧数。(e) After the data decoding unit receives the retransmitted audio and video data, the data decoding unit does not transmit to the Skip_audio bytes or frame numbers and the Skip_Frame video frames of the retransmitted audio and video stream beginning part after decoding The data display unit, after which the decoded audio and video data is transmitted to the data display unit for synchronous playback, wherein the number of bytes is used for the fixed code stream, and the number of frames is used for the variable code stream.

进一步地,上述音视频同步方法还可具有以下特点:Further, the above audio and video synchronization method can also have the following characteristics:

所述数据解码单元在收到切换指令后,继续对缓存的视频数据进行解码,在收到参数Skip_audio和Skip_Frame后,再清空缓存的视频数据,进行视频解码的重新初始化。The data decoding unit continues to decode the buffered video data after receiving the switching instruction, and clears the buffered video data after receiving the parameters Skip_audio and Skip_Frame to re-initialize the video decoding.

进一步地,上述音视频同步方法还可具有以下特点:Further, the above audio and video synchronization method can also have the following characteristics:

所述系统为嵌入式系统,所述数据解码单元用硬件实现,切换控制单元、数据传输单元和数据处理单元则由CPU执行相应软件来实现。The system is an embedded system, the data decoding unit is realized by hardware, and the switching control unit, data transmission unit and data processing unit are realized by CPU executing corresponding software.

进一步地,上述音视频同步方法还可具有以下特点:所述步骤(c)切换控制单元进一步通过以下步骤完成计算:Further, the above audio and video synchronization method can also have the following characteristics: the step (c) switching control unit further completes the calculation through the following steps:

(c1)根据切换音频数据流时正在解码的帧数A加上设定的帧数B,得到本次切换的视频同步点VC的帧序号,且根据解析的音视频数据开始位置和其总大小,确定索引信息起始位置,读取索引信息并保存;(c1) Add the set frame number B to the frame number A being decoded when the audio data stream is switched to obtain the frame number of the video synchronization point V C for this switch, and according to the starting position of the audio and video data analyzed and its total Size, determine the starting position of the index information, read the index information and save it;

(c2)从音视频数据索引开始位置累计视频帧的数目,以累计的视频帧数最接近且小于VC帧序号的I帧为VC之前最近的I帧VI(c2) from audio-video data index start position accumulative number of video frame, with the video frame number of accumulative closest and the I frame that is less than V C frame sequence number is the nearest I frame VI before V C ;

(c3)从索引信息中找到VI对应的音频数据块AI,读取AI在AVI文件中的偏移位置,以该位置为重传位置;(c3) find the audio data block A I corresponding to V I from the index information, read the offset position of A I in the AVI file, and take this position as the retransmission position;

(c4)计算VC与VI之间的帧数差即视频跳过数目Skip_Frame,以及播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size与AI之前累加得到的音频字节数或帧数Audio_TotalN_AI的差值,即音频跳过数目Skip_audio。(c4) Calculate the frame number difference between VC and V I , that is, the video skip number Skip_Frame , and the number of audio bytes or frames Audio_accum_size and A I The difference between the previously accumulated audio bytes or frame numbers Audio_TotalN_AI is the number of audio skips Skip_audio.

进一步地,上述音视频同步方法还可具有以下特点:所述步骤(c3)中VI对应的音频数据块AI按以下方式来查找:Further, the above-mentioned audio-video synchronization method can also have the following characteristics: in the step (c3), the audio data block A1 corresponding to V1 is searched in the following manner:

(c31)计算播放VI之前要切换到的那路音频流应播过的音频字节数或帧数Audio_TotalN_I,公式为:(c31) calculate the number of audio bytes or the number of frames Audio_TotalN_I that will be switched to that way audio stream before playing VI , and the formula is:

对固定码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*CBR音频字节率To fixed stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate indicator)*CBR audio byte rate

对可变码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*VBR音频采样率/1152To variable bit stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate index)*VBR audio frequency sampling rate/1152

(c32)从音视频数据的起始位置,逐一累加要切换到的那路音频流数据块的字节数或帧数,将累加值与上面得到的Audio_TotalN_I进行比较,如果小于Audio_TotalN_I,再进行下一次累加,如于大于等于Audio_TotalN_I,执行下一步;(c32) From the starting position of the audio and video data, add up the byte number or frame number of the audio stream data block to be switched to one by one, compare the accumulated value with the Audio_TotalN_I obtained above, if it is less than Audio_TotalN_I, then proceed to the next step Once accumulated, if it is greater than or equal to Audio_TotalN_I, go to the next step;

(c33)如累加值等于Audio_TotalN_I,则该路音频流的下一音频数据块即为VI对应的音频数据块AI,如累加值大于Audio_TotalN_I,则该音频数据块即为VI对应的音频数据块AI,同时记录AI之前累加得到的音频字节数或帧数Audio_TotalN_AI(c33) If the accumulated value is equal to Audio_TotalN_I, then the next audio data block of this road audio stream is the audio data block A I corresponding to VI, and if the accumulated value is greater than Audio_TotalN_I, then this audio data block is the corresponding audio of VI Data block A I , while recording the number of audio bytes or frames Audio_TotalN_A I accumulated before A I ;

(c34)从音频数据块AI对应的索引信息块中找到偏移位置dwOffset,该位置即为重传位置。(c34) Find the offset position dwOffset from the index information block corresponding to the audio data block A1 , which is the retransmission position.

所述步骤(c4)中计算播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size时,只需将步骤(c31)公式中的VI的帧序号改成VC的帧序号即可。When calculating the number of audio bytes or the frame number Audio_accum_size of that road audio stream that will switch to when playing VC in the described step (c4), only need to change the frame sequence number of VI in the formula of step (c31) It can be converted into the frame number of VC .

进一步地,上述音视频同步方法还可具有以下特点:Further, the above audio and video synchronization method can also have the following characteristics:

所述帧数B取值范围为:6~12个帧。The value range of the number of frames B is: 6 to 12 frames.

进一步地,上述音视频同步方法还可具有以下特点:Further, the above audio and video synchronization method can also have the following characteristics:

步骤(a)中,切换控制单元收到切换请求后,还向所述数据传输单元发送切换指令,所述数据传输单元收到切换指令后,立即停止对原音视频流的传输;同时,如AVI文件中包含三路及以上的音频流数据,则切换控制单元发送到数据处理单元和数据解码单元的指令中,需要指示要切换到的是哪一路音频流。In step (a), after the switch control unit receives the switch request, it also sends a switch command to the data transmission unit, and after the data transmission unit receives the switch command, it immediately stops the transmission of the original audio and video stream; meanwhile, such as AVI If the file contains three or more audio streams, the switching control unit needs to indicate which audio stream to switch to in the instructions sent to the data processing unit and the data decoding unit.

本发明提供的AVI文件播放时切换多路音频流的AV同步装置包括:The AV synchronization device for switching multiple audio streams during AVI file playback provided by the invention comprises:

数据传输单元,用于读取AVI文件的音视频数据传输到数据处理单元,并在收到重传指令后按指定重传位置重新传输AVI文件的音视频数据;The data transmission unit is used to read the audio and video data of the AVI file and transmit it to the data processing unit, and retransmit the audio and video data of the AVI file by the designated retransmission position after receiving the retransmission instruction;

数据处理单元,用于对AVI文件头信息和索引信息进行解析和保存,完成音频流和视频流的分离并传输给数据解码单元,在收到切换指令后,从音视频数据中分离出视频流和应切换到的那路音频流;The data processing unit is used to analyze and save the header information and index information of the AVI file, complete the separation of the audio stream and the video stream and transmit them to the data decoding unit, and separate the video stream from the audio and video data after receiving the switching instruction and the audio stream that should be switched to;

切换控制单元,用于在收到切换请求后,向数据处理单元和数据解码单元发送切换指令,然后根据当前解码的视频帧数和保存的索引信息、文件头信息计算得到重传位置和同步播放参数,将重传位置发送到数据传输单元,将同步播放参数发送到数据解码单元,所述同步播放参数为计算出的音频跳过数目Skip_audio和视频跳过数目Skip_Frame;The switching control unit is used to send switching instructions to the data processing unit and the data decoding unit after receiving the switching request, and then calculate the retransmission position and synchronous playback according to the number of currently decoded video frames and the saved index information and file header information Parameter, the retransmission position is sent to the data transmission unit, and the synchronous playback parameter is sent to the data decoding unit, and the synchronous playback parameter is the calculated audio skipping number Skip_audio and video skipping number Skip_Frame;

数据解码单元,包括音频解码子单元和视频解码子单元;在收到切换指令后,向切换控制单元回传当前解码的视频帧数,并完成视频解码的重新初始化以及按要切换到的那路音频流的参数重新进行音频解码的初始化;根据接收的同步播放参数,所述数据解码单元对重新传输的音视频流开始部分的Skip_audio个字节数或帧数以及Skip_Frame个视频帧,解码后不传输到数据显示单元,之后解码的音视频数据再传输到数据显示单元进行同步播放,其中对固定码流采用字节数,对可变码流采用帧数。The data decoding unit includes an audio decoding subunit and a video decoding subunit; after receiving the switching instruction, it returns the number of currently decoded video frames to the switching control unit, and completes the reinitialization of video decoding and the channel to be switched to The parameters of the audio stream are re-initialized for audio decoding; according to the received synchronous playback parameters, the data decoding unit does not decode the Skip_audio bytes or frames and the Skip_Frame video frames at the beginning of the retransmitted audio and video stream. It is transmitted to the data display unit, and then the decoded audio and video data is transmitted to the data display unit for synchronous playback, wherein the number of bytes is used for the fixed code stream, and the number of frames is used for the variable code stream.

进一步地,上述音视频同步装置还可具有以下特点:所述切换控制单元进一步包括:Further, the above-mentioned audio-video synchronization device may also have the following characteristics: the switching control unit further includes:

接口子单元,用于完成切换控制单元与其它单元之间的通信;The interface subunit is used to complete the communication between the switching control unit and other units;

信息提取子单元,用于从数据处理单元获取AVI文件头信息和索引信息,供运算子单元使用。The information extraction subunit is used to obtain the AVI file header information and index information from the data processing unit for use by the operation subunit.

控制子单元,用于在收到用户接口单元的切换请求后,向数据解码单元、数据处理单元和数据解码单元发送切换指令,发送到数据处理单元和解码单元的指令应携带要切换到的音频流标识,从数据解码单元获取当前解码的视频帧序号传送到运算子单元;并在收到运算子单元的重传位置、音频跳过数目和视频跳过数目参数后,向数据传输单元发送重传指令,携带重传位置参数,以及将音频跳过数目和视频跳过数目参数传输到数据解码单元。The control subunit is used to send switching instructions to the data decoding unit, data processing unit and data decoding unit after receiving the switching request from the user interface unit, and the instructions sent to the data processing unit and decoding unit should carry the audio to be switched to Stream ID, obtain the current decoded video frame sequence number from the data decoding unit and send it to the operation subunit; and after receiving the parameters of the retransmission position, the number of audio skips and the number of video skips of the operation subunit, send a retransmission to the data transmission unit An instruction is transmitted, carrying a retransmission position parameter, and transmitting the parameters of the number of audio skips and the number of video skips to the data decoding unit.

运算子单元,用于根据当前解码的视频帧序号和AVI文件头信息和索引信息,计算出重传位置、音频跳过数目Skip_audio和视频跳过数目Skip_Frame,传送到控制子单元。The operation subunit is used to calculate the retransmission position, the number of audio skips Skip_audio and the number of video skips Skip_Frame according to the currently decoded video frame number and AVI file header information and index information, and transmit them to the control subunit.

进一步地,上述音视频同步装置还可具有以下特点:Further, the above-mentioned audio-video synchronization device can also have the following characteristics:

所述数据解码单元在收到切换指令后,继续对缓存的视频数据进行解码,在收到参数Skip_audio和Skip_Frame后,再清空缓存的视频数据,进行视频解码的重新初始化。The data decoding unit continues to decode the buffered video data after receiving the switching instruction, and clears the buffered video data after receiving the parameters Skip_audio and Skip_Frame to re-initialize the video decoding.

进一步地,上述音视频同步装置还可具有以下特点:所述运算子单元进一步包括以下部分:Further, the above-mentioned audio-video synchronization device may also have the following characteristics: the operation subunit further includes the following parts:

同步点计算及索引信息提取部分,根据切换音频数据流时正在解码的帧数A加上设定的帧数B,得到本次切换的视频同步点VC的帧序号,且根据解析的音视频数据开始位置和其总大小,确定索引信息起始位置,读取索引信息并保存;The synchronization point calculation and index information extraction part, according to the frame number A being decoded when switching the audio data stream plus the set frame number B, obtains the frame number of the video synchronization point V C of this switch, and according to the analyzed audio and video The starting position of the data and its total size, determine the starting position of the index information, read and save the index information;

I帧确定部分,从音视频数据索引开始位置累计视频帧的数目,以累计的视频帧数最接近且小于VC帧序号的I帧为VC之前最近的I帧VIThe I frame determines the part, from the audio and video data index start position to accumulate the number of video frames, the I frame closest to and less than the V C frame sequence number is the nearest I frame V I before the V C with the accumulated video frame number;

重传位置计算部分,从索引信息中找到VI对应的音频数据块AI,读取AI在AVI文件中的偏移位置,以该位置为重传位置;The retransmission position calculation part finds the audio data block A I corresponding to VI from the index information, reads the offset position of A I in the AVI file, and takes this position as the retransmission position;

跳过数目计算部分,计算VC与VI之间的帧数差即视频跳过数目Skip_Frame,以及播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size与AI之前累加得到的音频字节数或帧数Audio_TotalN_AI的差值,即音频跳过数目Skip_audio。Skip the number calculation part, calculate the frame number difference between VC and VI , that is, the video skip number Skip_Frame, and the number of audio bytes or frames Audio_accum_size that should be played by the audio stream to be switched to when playing VC The difference between the number of audio bytes or the number of frames Audio_TotalN_A I accumulated before AI , that is, the number of audio skips Skip_audio.

进一步地,上述音视频同步装置还可具有以下特点:Further, the above-mentioned audio-video synchronization device can also have the following characteristics:

所述重传位置计算部分查找VI对应的音频数据块AI时,先计算播放VI之前要切换到的那路音频流应播过的音频字节数或帧数Audio_TotalN_I,公式为:When the retransmission position calculation part searches for the corresponding audio data block A1 of V1 , it first calculates the number of audio bytes or the number of frames Audio_TotalN_I that should be played by the audio stream that will be switched to before playing V1 , and the formula is:

对固定码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*CBR音频字节率To fixed stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate indicator)*CBR audio byte rate

对可变码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*VBR音频采样率/1152To variable bit stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate index)*VBR audio frequency sampling rate/1152

再从音视频数据的起始位置,逐一累加要切换到的那路音频流数据块的字节数或帧数,将累加值与上面得到的Audio_TotalN_I进行比较,如果小于Audio_TotalN_I,再进行下一次累加,如累加值等于Audio_TotalN_I,则该路音频流的下一音频数据块即为VI对应的音频数据块AI,如累加值大于Audio_TotalN_I,则该音频数据块即为VI对应的音频数据块AI,同时记录AI之前累加得到的音频字节数或帧数Audio_TotalN_AIThen from the starting position of the audio and video data, add up the number of bytes or frames of the audio stream data block to be switched to one by one, compare the accumulated value with the Audio_TotalN_I obtained above, if it is less than Audio_TotalN_I, perform the next accumulation , if the accumulated value is equal to Audio_TotalN_I, then the next audio data block of this road audio stream is the corresponding audio data block A I of VI, if the accumulated value is greater than Audio_TotalN_I, then this audio data block is the corresponding audio data block of VI A I , while recording the number of audio bytes or frames Audio_TotalN_A I accumulated before A I ;

最后,从音频数据块AI对应的索引信息块中找到偏移位置dwOffset,该位置即为重传位置。Finally, the offset position dwOffset is found from the index information block corresponding to the audio data block A1 , and this position is the retransmission position.

所述跳过数目计算部分计算播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size时,只需将上述计算Audio_TotalN_I公式中的VI的帧序号改成VC的帧序号即可。When the said skip number calculation part calculates the number of audio bytes or the number of frames Audio_accum_size that the audio stream to be switched to when playing VC , only the frame sequence number of VI in the above-mentioned calculation Audio_TotalN_I formula needs to be changed into The frame number of VC is enough.

进一步地,上述音视频同步装置还可具有以下特点:Further, the above-mentioned audio-video synchronization device can also have the following characteristics:

所述切换控制单元还用于在收到切换请求后,向所述数据传输单元发送切换指令;所述数据传输单元收到切换指令后,立即停止对原音视频流的传输;所述切换控制单元在播放的AVI文件中包含三路及以上的音频流数据时,发送到数据处理单元和数据解码单元的指令中,需要指示要切换到的是哪一路音频流。The switching control unit is also used to send a switching instruction to the data transmission unit after receiving the switching request; after the data transmission unit receives the switching instruction, immediately stop the transmission of the original audio and video stream; the switching control unit When the played AVI file contains three or more audio stream data, it is necessary to indicate which audio stream to switch to in the instructions sent to the data processing unit and the data decoding unit.

进一步地,上述音视频同步装置还可具有以下特点:Further, the above-mentioned audio-video synchronization device can also have the following characteristics:

所述装置应用于嵌入式系统,所述数据解码单元用硬件实现,切换控制单元、数据传输单元和数据处理单元由CPU执行相应软件来实现。The device is applied to an embedded system, the data decoding unit is realized by hardware, and the switching control unit, data transmission unit and data processing unit are realized by CPU executing corresponding software.

本发明保证了播放含一路Divx视频编码数据、多路音频数据的AVI文件,在切换不同音频流数据时保持AV同步。进一步还可以尽可能维持视频播放的连续性。特别可用于嵌入式系统的低配置条件下,实现AVI文件音频数据切换时的AV同步,从而降低了对系统主频的要求,可实现Karaoke(卡拉OK)的原/伴唱切换等功能。The invention guarantees to play AVI files containing one channel of Divx video encoding data and multiple channels of audio data, and maintain AV synchronization when switching different audio stream data. Furthermore, the continuity of video playback can be maintained as much as possible. It can be used especially for embedded systems with low configuration conditions to realize AV synchronization during audio data switching of AVI files, thereby reducing the requirement for the main frequency of the system, and can realize original/accompaniment switching of Karaoke (Karaoke) and other functions.

附图说明 Description of drawings

图1是AVI文件结构的示意图。Figure 1 is a schematic diagram of the structure of an AVI file.

图2是图1中的音视频数据部分的结构示意图。FIG. 2 is a schematic structural diagram of the audio and video data part in FIG. 1 .

图3是本发明实施例系统的结构框图。Fig. 3 is a structural block diagram of the system of the embodiment of the present invention.

图4是本发明实施例方法在切换原伴唱时的处理流程图。Fig. 4 is a flow chart of processing when the original accompaniment is switched in the method of the embodiment of the present invention.

图5和图6分别是CBR音频流和VBR音频流的参数计算的示意图。FIG. 5 and FIG. 6 are schematic diagrams of calculating parameters of a CBR audio stream and a VBR audio stream, respectively.

具体实施方式 Detailed ways

本发明是播放含有一路Divx视频编码数据、多路音频数据的AVI文件过程中,切换音频数据时保持AV同步的方法和系统,以下以播放Karaoke系统时切换原伴唱为例,结合附图和实施例对本发明进行详细说明。The present invention is to play in the AVI file process that contains one Divx video encoding data, multi-channel audio data, the method and the system that keep AV synchronism when switching audio data, the original accompaniment singing is switched when playing Karaoke system as example below, in conjunction with accompanying drawing and implementation Examples illustrate the present invention in detail.

由于从得到切换指令到行使多路音频切换期间需要一段时间进行计算,为避免视频图像静止定格,视频会继续播放一段时间。在视频播放的情况下,为了保证切换后的音频与视频的同步,就要选择一个音视频同时播放的一个点,即视频同步点(即视频帧)C及其对应的音频数据块。该视频同步点应在切换时解码的视频帧后的某个位置。Since it takes a period of time to calculate between getting the switching instruction and executing the multi-channel audio switching, in order to avoid the video image from stilling, the video will continue to play for a period of time. In the case of video playback, in order to ensure the synchronization of audio and video after switching, a point where audio and video are played simultaneously is selected, i.e. video synchronization point (i.e. video frame) C and its corresponding audio data block. This video sync point should be somewhere after the video frame decoded at the time of switching.

另外根据解码的要求,视频的解码必须从I帧开始,音频可以从任何位置开始,如果直接从C点视频解码,则会出现马赛克现象。所以确定切换后重新解码的开始位置时,需找到视频同步点C(也用VC表示)之前最近的I帧(也用VI表示)所对应(指应同步播放)的音频数据块(以下用AI表示),从该音频数据块在AVI文件中的偏移位置Goto_offset重新传输和解码AVI文件数据。对于VC之前的视频帧以及VC对应的音频数据块(以下用AC表示)之前的音视频数据,只进行解码而不进行播放。In addition, according to the decoding requirements, the decoding of the video must start from the I frame, and the audio can start from any position. If the video is decoded directly from the C point, mosaic phenomenon will appear. Therefore, when determining the start position of re-decoding after switching, it is necessary to find the audio data block corresponding to (referring to synchronous playback) of the nearest I frame (also represented by VI) before the video synchronization point C (also represented by V C ) (following Represented by AI ), retransmit and decode the AVI file data from the offset position Goto_offset of the audio data block in the AVI file. For the video frame before VC and the audio-video data before the audio data block (hereinafter referred to as A C ) corresponding to VC, only decode but not play.

本文中的重新传输或重传,是指打破第一次传输次序,开始新的第二次传输,这次传输的起始位置不再是原来的文件头。The retransmission or retransmission in this article refers to breaking the order of the first transmission and starting a new second transmission. The starting position of this transmission is no longer the original file header.

图3是本发明实施例系统的结构框图,如图所示,包括数据传输单元、数据处理单元、切换控制单元、数据解码单元、数据显示单元和用户接口单元,其中:Fig. 3 is a structural block diagram of the system of the embodiment of the present invention, as shown in the figure, including a data transmission unit, a data processing unit, a switching control unit, a data decoding unit, a data display unit and a user interface unit, wherein:

数据传输单元用于将读取的AVI文件音视频数据传输到数据处理单元,且数据传输单元在收到切换控制单元的切换指令后停止数据传输,在收到该单元的重传指令后,按指令中指示的重转位置重新开始传输音视频数据。其中视频数据采用Divx3.11、Divx4.x、Divx5.x等编码格式,音频数据采用MP1、MP2、MP3等编码格式。The data transmission unit is used to transmit the audio and video data of the read AVI file to the data processing unit, and the data transmission unit stops data transmission after receiving the switching instruction of the switching control unit, and after receiving the retransmission instruction of the unit, press The restart position indicated in the command restarts the transmission of audio and video data. The video data adopts encoding formats such as Divx3.11, Divx4.x, Divx5.x, etc., and the audio data adopts encoding formats such as MP1, MP2, and MP3.

数据处理单元用于接收数据传输单元传输的音视频数据,对AVI文件头信息、Index信息、音视频格式信息进行解析后保存,分离出要播放的音视频数据并传输给数据解码单元,在收到切换指令后对重新传输的数据,需要从音视频数据中分离出视频流和应切换到的那路音频流;The data processing unit is used to receive the audio and video data transmitted by the data transmission unit, save after parsing the AVI file header information, Index information, and audio and video format information, and separate the audio and video data to be played and transmit it to the data decoding unit. For the retransmitted data after the switching command, it is necessary to separate the video stream and the audio stream to which it should be switched from the audio and video data;

切换控制单元进一步包括:The switching control unit further includes:

信息提取子单元,用于从数据处理单元获取保存的AVI文件头信息和Index信息,供运算子单元使用;The information extraction subunit is used to obtain the saved AVI file header information and Index information from the data processing unit for use by the operation subunit;

接口子单元,用于完成切换控制单元与其它单元之间的通信;The interface subunit is used to complete the communication between the switching control unit and other units;

控制子单元,用于在收到用户接口单元的切换请求后,向数据传输单元、数据处理单元和数据解码单元发送切换指令,发送到数据处理单元和解码单元的指令指示要切换到的是哪一路音频流(指示可以通过携带要切换到的音频流标识来实现,当然如果只有两路音频流也可以不指示),并从数据解码单元获取当前解码的视频帧数传送到运算子单元;以及在收到运算子单元的重传位置、音频跳过数目和视频跳过数目参数后,向数据传输单元发送重传指令,包含重传位置参数,并将音频跳过数目和视频跳过数目参数传输到数据解码单元;The control subunit is used to send switching instructions to the data transmission unit, data processing unit and data decoding unit after receiving the switching request from the user interface unit, and the instructions sent to the data processing unit and the decoding unit indicate which switch to switch to One audio stream (the indication can be realized by carrying the audio stream identifier to be switched to, of course, if there are only two audio streams, it can not be indicated), and the currently decoded video frame number is obtained from the data decoding unit and sent to the operation subunit; and After receiving the retransmission position, audio skip number and video skip number parameters of the operator unit, send a retransmission instruction to the data transmission unit, including the retransmission position parameter, and set the audio skip number and video skip number parameters transmitted to the data decoding unit;

运算子单元,用于根据当前解码的视频帧数和AVI文件头信息、Index信息,计算出重传位置、音频跳过数目和视频跳过数目,传送到控制子单元。该子单元可进行分为同步点计算及索引信息提取部分、I帧确定部分、重传位置计算部分和跳过数目计算部分,各个部分的功能将在下文再介绍。The operation subunit is used to calculate the retransmission position, the number of audio skips and the number of video skips according to the currently decoded video frame number and the AVI file header information and Index information, and transmit them to the control subunit. This subunit can be divided into synchronization point calculation and index information extraction part, I frame determination part, retransmission position calculation part and skip number calculation part, and the functions of each part will be introduced later.

数据解码单元,包括音频解码子单元和视频解码子单元,分别用于对数据处理单元传输的音视频数据分别进行解码,其中:The data decoding unit includes an audio decoding subunit and a video decoding subunit, which are respectively used to decode the audio and video data transmitted by the data processing unit, wherein:

视频解码子单元还用于在收到切换控制单元的切换指令后,向其回传当前视频解码的视频帧数,并继续解码缓存数据;在收到视频跳过数目后,清空缓存并重新初始化,对重新传输的视频流开始部分该数目的视频帧只解码,不传输到数据显示单元,之后的视频帧解码后输出到数据显示单元;The video decoding subunit is also used to return the video frame number of the current video decoding to it after receiving the switching instruction from the switching control unit, and continue to decode the cached data; after receiving the number of video skips, clear the cache and re-initialize , the number of video frames at the beginning of the retransmitted video stream is only decoded, and not transmitted to the data display unit, and the subsequent video frames are decoded and output to the data display unit;

音频解码子单元在收到切换控制单元的切换指令后停止对音频数据的解码,按要切换到的音频流参数进行重新初始化设置;在收到音频跳过数目后,对重新传输的音频流开始部分该数目的音频帧/字节数(“/”表示“或”关系,对CBR的音频数据为字节数,对VBR的音频数据为音频帧)只解码,不传输到数据显示单元,之后的音频数据解码后输出到数据显示单元。The audio decoding subunit stops decoding audio data after receiving the switching instruction from the switching control unit, and re-initializes the audio stream parameters to be switched to; after receiving the number of audio skips, it starts to retransmit the audio stream Part of the number of audio frames/bytes ("/" means "or" relationship, the audio data of CBR is the number of bytes, and the audio data of VBR is the audio frame) is only decoded, not transmitted to the data display unit, and then The audio data is decoded and output to the data display unit.

数据显示单元,用于把解码后的音视频数据进行显示、播放,视频可以在TV/VGA设备输出,音频在TV设备输出。The data display unit is used to display and play the decoded audio and video data, the video can be output on TV/VGA equipment, and the audio can be output on TV equipment.

用户接口单元是用户操作的接口,用户可通过该接口发送切换请求,其中该切换请求在有三路以上音频流时,要包含要切换到的音频流标识,即指示要切换到的是哪一路音频流。The user interface unit is an interface operated by the user, through which the user can send a switching request, wherein the switching request should include the audio stream identifier to be switched to when there are more than three audio streams, that is, indicate which audio stream to switch to flow.

没有切换原伴唱时执行的流程包括以下步骤:The process performed when the original accompaniment is not switched includes the following steps:

步骤一,STB加电,自动运行Karaoke播放系统,用户通过播放界面控制此系统;Step 1, STB is powered on, automatically runs the Karaoke playback system, and the user controls the system through the playback interface;

步骤二,用户选择播放AVI文件格式的歌曲时,从AVI文件中的文件头开始传输数据,如接收到的传输数据为AVI文件头,执行步骤三,若为音视频数据,执行步骤五;Step 2, when the user selects to play the song of the AVI file format, start to transmit data from the file header in the AVI file, as the transmission data received is the AVI file header, perform step 3, if it is audio and video data, perform step 5;

步骤三,解析AVI文件头,保存其中包含的信息;Step 3, parsing the AVI file header, saving the information contained therein;

其中解析且保存的AVI文件头信息包括:音视频流数,用以确认此文件中有几路音视频流;视频流时间尺度和视频流速率指标;VBR数据对齐值(固定值为1152,)、VBR音频流的采样率或者CBR音频流的字节率;音视频数据开始位置Movie_Offset及音视频数据整体大小Movie_Size;视频图象的宽、高,即图象分辨率;视频解码器类型;视频解码器调色板;视频解码器解码速率(通过视频流时间尺度和视频流速率指标这两个参数表示);每路音频流音频解码器类型;每路音频流音频解码器码流类型(固定码率或非固定码率);每路音频流音频解码器解码速率;音、视频解码器开始解码时间。The AVI file header information parsed and saved includes: number of audio and video streams to confirm how many audio and video streams there are in this file; video stream time scale and video stream rate index; VBR data alignment value (fixed value is 1152,) , the sampling rate of the VBR audio stream or the byte rate of the CBR audio stream; the starting position of the audio and video data Movie_Offset and the overall size of the audio and video data Movie_Size; the width and height of the video image, that is, the image resolution; the video decoder type; Decoder palette; video decoder decoding rate (represented by the two parameters of video stream time scale and video stream rate index); each audio stream audio decoder type; each audio stream audio decoder code stream type (fixed code rate or non-fixed code rate); the decoding rate of the audio decoder for each audio stream; the decoding start time of the audio and video decoders.

步骤四,根据从AVI文件头获取的信息进行解码的初始化设置操作;Step 4, carry out the initial setting operation of decoding according to the information that obtains from AVI file header;

主要包括以下操作:设置视频图象的宽、高,即图象分辨率;设置视频解码器类型;设置视频解码器调色板;设置视频解码器解码速率;设置音频解码器类型;设置音频解码器码流类型(固定码率或非固定码率);设置音频解码器解码速率;设置音、视频解码器开始解码时间。It mainly includes the following operations: set the width and height of the video image, that is, the image resolution; set the video decoder type; set the video decoder palette; set the video decoder decoding rate; set the audio decoder type; set the audio decoding Coder stream type (fixed code rate or non-fixed code rate); set the decoding rate of the audio decoder; set the decoding start time of the audio and video decoders.

其中AVI文件只含有一路视频数据,但可以含多路音频数据,所以初始化音频解码器时使用默认播放的音频流参数进行初始化操作。Among them, the AVI file only contains one channel of video data, but can contain multiple channels of audio data, so when initializing the audio decoder, use the default audio stream parameters to perform the initialization operation.

步骤五,分离需要播放的音视频数据流;Step 5, separating the audio and video data streams to be played;

步骤六,对分离的音视频数据进行解码,通过AV接口把解码后的数据输出到显示设备与扬声器进行播放。Step 6: Decode the separated audio and video data, and output the decoded data to a display device and a speaker through the AV interface for playback.

该流程只是常规的处理流程。The flow is just a normal processing flow.

如图4所示,在播放含有多路音频流的AVI文件的过程中,用户切换原伴唱的处理流程包括以下步骤:As shown in Figure 4, in the process of playing the AVI file that contains multiple audio streams, the processing flow for the user to switch the original accompaniment includes the following steps:

步骤110,用户切换原伴唱;Step 110, the user switches the original accompaniment;

步骤120,切换控制单元收到切换请求后,向数据传输单元、数据处理单元和数据解码单元发送切换指令,其中发送到数据处理单元和数据解码单元的指令需要携带要切换到的音频流标识;Step 120, after the switching control unit receives the switching request, it sends a switching instruction to the data transmission unit, the data processing unit, and the data decoding unit, wherein the instructions sent to the data processing unit and the data decoding unit need to carry the audio stream identifier to be switched to;

步骤130,数据传输单元停止对音视频流的传输,数据解码单元按要切换到的那路音频流的参数重新进行音频解码的初始化设置,向切换控制单元回传当前解码的视频帧数,同时继续对缓存的视频数据进行解码;Step 130, the data transmission unit stops the transmission of audio and video streams, and the data decoding unit re-performs the initialization setting of audio decoding according to the parameters of the audio stream to be switched to, returns the current decoded video frame number to the switching control unit, and at the same time Continue to decode the cached video data;

该步中的音频解码初始化设置包括:设置音频解码器类型;设置音频解码器码流类型(固定帧率或非固定帧率);设置音频解码器解码速率;设置音、视频解码器开始解码时间。进行这些设置所需的参数是原来从AVI文件头获取的。The audio decoding initialization setting in this step includes: setting the audio decoder type; setting the audio decoder code stream type (fixed frame rate or non-fixed frame rate); setting the audio decoder decoding rate; setting the audio and video decoder start decoding time . The parameters required for these settings are originally obtained from the AVI file header.

步骤140,切换控制单元根据当前解码的视频帧数和保存的INDEX信息、文件头信息,计算出重传位置、音频跳过数目Skip_audio和视频跳过数目Skip_Frame等参数,向数据传输单元发送重传指令并包括重传位置参数,并将参数Skip_audio和Skip_Frame传送到数据解码单元;Step 140, the switching control unit calculates parameters such as the retransmission position, the number of audio skips Skip_audio and the number of video skips Skip_Frame according to the number of currently decoded video frames and the stored INDEX information and file header information, and sends a retransmission to the data transmission unit The instruction includes a retransmission position parameter, and transmits the parameters Skip_audio and Skip_Frame to the data decoding unit;

步骤150,数据传输单元按指定重传位置重新传输AVI文件的音视频数据,由数据处理单元从音视频数据中分离出视频流和应切换到的那路音频流;数据解码单元先清空缓存的视频数据,重新初始化;Step 150, the data transmission unit retransmits the audio and video data of the AVI file according to the specified retransmission position, and the video stream and the audio stream that should be switched to are separated from the audio and video data by the data processing unit; the data decoding unit first clears the buffered Video data, reinitialized;

步骤160,数据解码单元对重新传输的音视频流开始部分的Skip_audio个音频字节数/帧数和Skip_Frame个视频帧,解码后不传输到数据显示单元,之后解码的音视频数据再传输到数据显示单元以同步播放。Step 160, the data decoding unit does not transmit to the data display unit after decoding the Skip_audio audio bytes/frames and the Skip_Frame video frames at the beginning of the retransmitted audio and video stream, and then transmits the decoded audio and video data to the data display unit display units to play in sync.

至此A/V同步过程完成。要说明的是,数据解码单元(中的音频解码子单元)也可以在收到切换指令后继续解码音频数据,在收到音频跳过数目后再停止解码、完成要切换到的音频流的初始化。So far the A/V synchronization process is completed. It should be noted that the data decoding unit (the audio decoding sub-unit in it) can also continue to decode the audio data after receiving the switching instruction, stop decoding after receiving the number of audio skips, and complete the initialization of the audio stream to be switched to .

下面将详细地说明在步骤140中如何进行计算,请同时参照图5和图6示出的CBR(固定码流)音频流和VBR(可变码流)音频流的参数计算的示意图。图中“a”或“v”对应一个数据块。该步骤进一步分为以下步骤:How to perform the calculation in step 140 will be described in detail below, please refer to the schematic diagrams of parameter calculation of the CBR (Constant Bit Stream) audio stream and the VBR (Variable Bit Stream) audio stream shown in FIG. 5 and FIG. 6 . "a" or "v" in the figure corresponds to a data block. This step is further divided into the following steps:

步骤1401,根据切换音频数据流时正在解码的视频帧数A加上设定的帧数B,得到本次切换的视频同步点VC的帧序号,同时根据解析的音视频数据开始位置和其总大小确定INDEX信息起始位置,读取INDEX信息并保存;Step 1401, according to the video frame number A being decoded when switching the audio data stream plus the set frame number B, obtain the frame sequence number of the video synchronization point V C of this switch, and simultaneously according to the starting position of the audio and video data analyzed and its The total size determines the starting position of the INDEX information, reads the INDEX information and saves it;

VC的帧序号即为从音视频数据开始位置到该帧累计得到的视频帧数目。帧数B为经验值或计算出来,B如果大了,播放会有跳跃现象,如果小了,就会有重复现象,较佳取值范围为:6~12个帧。该运算由运算子单元的同步点计算及索引信息提取部分完成。The frame number of VC is the number of video frames accumulated from the start position of audio and video data to this frame. The number of frames B is an empirical value or calculated. If B is too large, the playback will skip. If it is too small, there will be repetitions. The optimal value range is: 6 to 12 frames. This operation is completed by the synchronization point calculation and index information extraction part of the operation subunit.

步骤1402,先确定VC之前最近的I帧VI的帧序号;Step 1402, first determine the frame sequence number of the latest I frame V I before V C ;

本实施例是从音视频数据索引开始位置,分别累计视频帧的数目、所要切换到的音频数据流的每一音频数据块前所有本路音频数据块、字节数/帧数,以及每一路音频流的每一音频数据块在AVI文件中的偏移位置;这样可以一次得到每一个I帧的帧序号(即累计到该I帧的视频帧数),该I帧之前的各路音频流数据块数、字节数/帧数,该I帧对应的音频数据块在AVI文件中的偏移位置等的信息。那么帧序号最接近且小于VC帧序号的I帧即为VIIn this embodiment, from the starting position of the audio and video data index, respectively accumulate the number of video frames, all the audio data blocks of this channel before each audio data block of the audio data stream to be switched to, the number of bytes/frames, and the number of each channel The offset position of each audio data block of the audio stream in the AVI file; in this way, the frame number of each I frame (that is, the number of video frames accumulated to the I frame) can be obtained at one time, and each audio stream before the I frame Information such as the number of data blocks, the number of bytes/frames, the offset position of the audio data block corresponding to the I frame in the AVI file, etc. Then the I frame whose frame number is closest to and smaller than the V C frame number is V I .

由于在INDEX信息中并没有音频数据块或视频数据块的序号,因此可以从头开始累计视频帧的数目,等于VC的帧序号时即找到了VC,进而可确定其之前最近的I帧。或者,也可以在累计过程中建立起每一个I帧帧序号的集合,直接和VC的帧序号比较,其中帧序号最接近且小于等于VC的帧序号的I帧即为要找的I帧。另外,由于每个I帧之间间隔的帧数是固定的,只要知道第一个I帧的序号(如读取INDEX信息或为固定值),就可以直接计算出每一I帧的帧序号,按同样方法可比较得到VI的帧序号。Since there is no serial number of audio data block or video data block in the INDEX information, the number of video frames can be accumulated from the beginning, and when it is equal to the frame serial number of VC , VC is found, and then the latest I frame before it can be determined. Or, also can set up the collection of each I frame frame sequence number in the accumulation process, compare directly with the frame sequence number of VC , wherein the I frame of the frame sequence number closest to and less than or equal to the frame sequence number of VC is the I to be looked for frame. In addition, since the number of frames between each I frame is fixed, as long as the sequence number of the first I frame is known (such as reading INDEX information or a fixed value), the frame sequence number of each I frame can be directly calculated , by the same method can be compared to get the frame number of VI .

该运算由运算子单元的I帧确定部分完成。This operation is completed by the I frame determination part of the operation subunit.

步骤1403,从INDEX信息中找到VI对应的音频数据块AI,读取AI在AVI文件中的偏移位置,以该位置为重传位置Goto_offset;Step 1403, find the audio data block A I corresponding to V I from the INDEX information, read the offset position of A I in the AVI file, and take this position as the retransmission position Goto_offset;

在INDEX中,VI对应的音频数据块AI按以下方式来查找:In INDEX, the audio data block A I corresponding to V I is searched in the following way:

1)计算播放VI之前要切换到的那路音频流应播过的音频字节数或帧数Audio_TotalN_I,对CBR(固定码流)音频流计算的是音频数据字节数,对于VBR(可变码流)音频流计算的是音频数据帧数,公式为:1) Calculate the number of audio bytes or the number of frames Audio_TotalN_I that the audio stream that will be switched to before playing VI should be played, and what calculates for the CBR (fixed code stream) audio stream is the number of audio data bytes, for VBR (can be Transcode stream) audio stream calculates the number of audio data frames, the formula is:

对CBR:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*CBR音频字节率To CBR: Audio_TotalN_I= VI 's frame sequence number*(video stream time scale/video stream rate indicator)*CBR audio byte rate

对VBR:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*VBR音频采样率/1152To VBR: Audio_TotalN_I= VI 's frame sequence number*(video stream time scale/video stream rate index)*VBR audio frequency sampling rate/1152

应同步播放的音频数据块和视频数据块并不总是相邻,因此上面根据AVI文件头中的相关参数来计算。The audio data block and video data block that should be played synchronously are not always adjacent, so the calculation above is based on the relevant parameters in the AVI file header.

2)从音视频数据的起始位置,逐一累加要切换到的那路音频流数据块的字节数/帧数,将累加值与上面得到的Audio_TotalN_I进行比较,如果小于Audio_TotalN_I,再进行下一次累加,如于大于等于Audio_TotalN_I,执行下一步;2) From the starting position of the audio and video data, accumulate the number of bytes/frames of the audio stream data block to be switched to one by one, compare the accumulated value with the Audio_TotalN_I obtained above, if it is less than Audio_TotalN_I, proceed to the next time Accumulate, if it is greater than or equal to Audio_TotalN_I, go to the next step;

3)如累加值等于Audio_TotalN_I,则该路音频流的下一音频数据块即为VI对应的音频数据块AI,如累加值大于Audio_TotalN_I,则该音频数据块即为VI对应的音频数据块AI,同时记录AI之前累加得到的音频字节数/帧数Audio_TotalN_AI3) If the accumulated value is equal to Audio_TotalN_I, then the next audio data block of the audio stream is the corresponding audio data block A I of VI , and if the accumulated value is greater than Audio_TotalN_I, then the audio data block is the corresponding audio data of VI Block A I , record the number of audio bytes/frames Audio_TotalN_A I accumulated before A I at the same time;

4)从音频数据块AI对应的索引信息块中找到偏移位置dwOffset,该位置即为重传位置Goto_offset。4) Find the offset position dwOffset from the index information block corresponding to the audio data block A1 , which is the retransmission position Goto_offset.

在另一实施例中,也可以在读入INDEX信息后,先遍历INDEX信息,记录要切换到的那路音频流的每一音频数据块对应的字节数或帧数及其偏移位置,这样在计算出Audio_TotalN_I后,就可以直接比较得到重传位置Goto_offset。In another embodiment, after the INDEX information is read, the INDEX information can be traversed first, and the number of bytes or frames corresponding to each audio data block of the audio stream to be switched to and its offset position can be recorded. In this way, after calculating Audio_TotalN_I, the retransmission position Goto_offset can be directly compared.

该运算由运算子单元的重传位置计算部分完成。This operation is completed by the retransmission position calculation part of the operation subunit.

步骤1404,计算出VC与VI之间的帧数差即视频跳过数目Skip_Frame,以及播放VC时要切换到的那路音频流应播过的音频字节数/帧数Audio_accum_size与AI之前累加得到的音频字节数/帧数Audio_TotalN_AI的差值,即音频跳过数目Skip_audio;Step 1404, calculate the frame number difference between VC and VI , that is, the number of video skips Skip_Frame , and the number of audio bytes/frames Audio_accum_size and A The difference between the number of audio bytes/frames Audio_TotalN_A I accumulated before I , that is, the number of audio skips Skip_audio;

Skip_Frame就等于VC与VI的帧序号的差值。而Audio_accum_size的计算方法与Audio_TotalN_I相同,公式如下:Skip_Frame is equal to the difference between the frame numbers of VC and VI . The calculation method of Audio_accum_size is the same as that of Audio_TotalN_I, the formula is as follows:

对CBR:Audio_accum_size=VC的帧序号*(视频流时间尺度/视频流速率指标)*CBR音频字节率For CBR: Audio_accum_size=V C frame number*(video stream time scale/video stream rate index)*CBR audio byte rate

对VBR:Audio_accum_size=VC的帧序号*(视频流时间尺度/视频流速率指标)*VBR音频采样率/1152For VBR: Audio_accum_size=V C frame number*(video stream time scale/video stream rate index)*VBR audio sampling rate/1152

由于CBR音频流计算的是音频数据字节数,VBR音频流计算的是音频数据帧数,故Audio_accum_size在CBR的组合数据块或者一个数据块(CBR的音频数据块与音频帧是不对应关系)中可以是截至在一个帧中间,在VBR的组合数据块中是截至在帧帧之间。Since the CBR audio stream calculates the number of audio data bytes, the VBR audio stream calculates the number of audio data frames, so Audio_accum_size is in the combined data block or one data block of CBR (the audio data block of CBR does not correspond to the audio frame) In can be in the middle of a frame, in VBR combined data block is in between frames.

该运算由运算子单元的跳过数目计算部分完成。This operation is completed by the skip number calculation part of the operation subunit.

综上所述,本发明可采用软、硬件结合的方式,播放含一路Divx视频编码数据、多路音频数据的AVI文件,在切换不同音频流数据时保持AV同步。保证了在嵌入式系统中低配置条件下,对AVI文件音频数据切换时AV同步,从而降低了对系统主频的要求。To sum up, the present invention can use a combination of software and hardware to play an AVI file containing one Divx video encoding data and multiple audio data, and keep AV synchronization when switching between different audio stream data. It ensures the AV synchronization when switching the audio data of the AVI file under the condition of low configuration in the embedded system, thereby reducing the requirement for the main frequency of the system.

本发明的另一实施例中,如果只需要实现同步,不考虑播放的连续性问题,也可以省略与音频跳过数目和视频跳过数目相关的流程中的操作和装置中的单元。In another embodiment of the present invention, if it is only necessary to achieve synchronization without considering the continuity of playback, operations in the process and units in the device related to the number of audio skips and video skips can also be omitted.

Claims (14)

1.一种AVI文件播放时切换多路音频流的AV同步方法,应用于包括切换控制单元、数据传输单元、数据处理单元和数据解码单元的系统,在播放含有多路音频流的AVI文件时,先保存AVI文件头信息,当用户切换音频流后,其特征在于,执行以下步骤:1. an AV synchronous method for switching multiple audio streams during AVI file playback, applied to the system comprising switching control unit, data transmission unit, data processing unit and data decoding unit, when playing the AVI file containing multiple audio streams , first save the AVI file header information, when the user switches the audio stream, it is characterized in that the following steps are performed: (a)切换控制单元收到切换请求后,向数据处理单元和数据解码单元发送切换指令;(a) After receiving the switching request, the switching control unit sends switching instructions to the data processing unit and the data decoding unit; (b)数据解码单元向切换控制单元回传当前解码的视频帧数;(b) the data decoding unit returns the currently decoded video frame number to the switching control unit; (c)切换控制单元根据当前解码的视频帧数和保存的索引信息、文件头信息计算得到重传位置和同步播放参数,将重传位置发送到数据传输单元,将同步播放参数发送到数据解码单元,所述同步播放参数为计算出的音频跳过数目Skip_audio和视频跳过数目Skip_Frame;(c) The switching control unit calculates the retransmission position and synchronous playback parameters according to the number of currently decoded video frames and the saved index information and file header information, sends the retransmission position to the data transmission unit, and sends the synchronous playback parameters to the data decoder unit, the synchronous playback parameter is the calculated audio skip number Skip_audio and video skip number Skip_Frame; (d)数据传输单元按指定重传位置重新传输AVI文件的音视频数据,数据处理单元接收到音视频数据后分离出视频流和应切换到的那路音频流;数据解码单元完成视频解码的重新初始化,并按要切换到的那路音频流的参数重新进行音频解码的初始化;(d) The data transmission unit retransmits the audio-video data of the AVI file by the specified retransmission position, and the data processing unit separates the video stream and the audio stream that should be switched to after receiving the audio-video data; the data decoding unit completes video decoding Re-initialize, and re-initialize the audio decoding according to the parameters of the audio stream to be switched to; (e)数据解码单元接收到重新传输的音视频数据后,所述数据解码单元对重新传输的音视频流开始部分的Skip_audio个字节数或帧数以及Skip_Frame个视频帧,解码后不传输到数据显示单元,之后解码的音视频数据再传输到数据显示单元进行同步播放,其中对固定码流采用字节数,对可变码流采用帧数。(e) After the data decoding unit receives the retransmitted audio and video data, the data decoding unit does not transmit to the Skip_audio bytes or frame numbers and the Skip_Frame video frames of the retransmitted audio and video stream beginning part after decoding The data display unit, after which the decoded audio and video data is transmitted to the data display unit for synchronous playback, wherein the number of bytes is used for the fixed code stream, and the number of frames is used for the variable code stream. 2.如权利要求1所述的AV同步方法,其特征在于:2. AV synchronization method as claimed in claim 1, characterized in that: 所述数据解码单元在收到切换指令后,继续对缓存的视频数据进行解码,在收到参数Skip_audio和Skip_Frame后,再清空缓存的视频数据,进行视频解码的重新初始化。The data decoding unit continues to decode the buffered video data after receiving the switching instruction, and clears the buffered video data after receiving the parameters Skip_audio and Skip_Frame to re-initialize the video decoding. 3.如权利要求1所述的AV同步方法,其特征在于:3. AV synchronization method as claimed in claim 1, characterized in that: 所述系统为嵌入式系统,所述数据解码单元用硬件实现,切换控制单元、数据传输单元和数据处理单元则由CPU执行相应软件来实现。The system is an embedded system, the data decoding unit is realized by hardware, and the switching control unit, data transmission unit and data processing unit are realized by CPU executing corresponding software. 4.如权利要求1所述的AV同步方法,其特征在于:所述步骤(c)切换控制单元进一步通过以下步骤完成计算:4. AV synchronization method as claimed in claim 1, is characterized in that: described step (c) switching control unit further completes calculation by the following steps: (c1)根据切换音频数据流时正在解码的帧数A加上设定的帧数B,得到本次切换的视频同步点VC的帧序号,且根据解析的音视频数据开始位置和其总大小,确定索引信息起始位置,读取索引信息并保存;(c1) Add the set frame number B to the frame number A being decoded when the audio data stream is switched to obtain the frame number of the video synchronization point V C for this switch, and according to the starting position of the audio and video data analyzed and its total Size, determine the starting position of the index information, read the index information and save it; (c2)从音视频数据索引开始位置累计视频帧的数目,以累计的视频帧数最接近且小于VC帧序号的I帧为VC之前最近的I帧VI(c2) from audio-video data index start position accumulative number of video frame, with the video frame number of accumulative closest and the I frame that is less than V C frame sequence number is the nearest I frame VI before V C ; (c3)从索引信息中找到VI对应的音频数据块AI,读取AI在AVI文件中的偏移位置,以该位置为重传位置;(c3) find the audio data block A I corresponding to V I from the index information, read the offset position of A I in the AVI file, and take this position as the retransmission position; (c4)计算VC与VI之间的帧数差即视频跳过数目Skip_Frame,以及播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size与AI之前累加得到的音频字节数或帧数Audio_TotalN_AI的差值,即音频跳过数目Skip_audio。(c4) Calculate the frame number difference between VC and V I , that is, the video skip number Skip_Frame , and the number of audio bytes or frames Audio_accum_size and A I The difference between the previously accumulated audio bytes or frame numbers Audio_TotalN_AI is the number of audio skips Skip_audio. 5.如权利要求4所述的AV同步方法,其特征在于:所述步骤(c3)中VI对应的音频数据块AI按以下方式来查找:5. AV synchronous method as claimed in claim 4, is characterized in that: in described step (c3), the audio data block AI corresponding to VI is searched in the following manner: (c31)计算播放VI之前要切换到的那路音频流应播过的音频字节数或帧数Audio_TotalN_I,公式为:(c31) calculate the number of audio bytes or the number of frames Audio_TotalN_I that will be switched to that way audio stream before playing VI , and the formula is: 对固定码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*CBR音频字节率To fixed stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate indicator)*CBR audio byte rate 对可变码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*VBR音频采样率/1152To variable bit stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate index)*VBR audio frequency sampling rate/1152 (c32)从音视频数据的起始位置,逐一累加要切换到的那路音频流数据块的字节数或帧数,将累加值与上面得到的Audio_TotalN_I进行比较,如果小于Audio_TotalN_I,再进行下一次累加,如果大于等于Audio_TotalN_I,执行下一步;(c32) From the starting position of the audio and video data, add up the byte number or frame number of the audio stream data block to be switched to one by one, compare the accumulated value with the Audio_TotalN_I obtained above, if it is less than Audio_TotalN_I, then proceed to the next step Once accumulated, if it is greater than or equal to Audio_TotalN_I, go to the next step; (c33)如累加值等于Audio_TotalN_I,则该路音频流的下一音频数据块即为VI对应的音频数据块AI,如累加值大于Audio_TotalN_I,则该音频数据块即为VI对应的音频数据块AI,同时记录AI之前累加得到的音频字节数或帧数Audio_TotalN_AI(c33) If the accumulated value is equal to Audio_TotalN_I, then the next audio data block of this road audio stream is the audio data block A I corresponding to VI, and if the accumulated value is greater than Audio_TotalN_I, then this audio data block is the corresponding audio of VI Data block A I , while recording the number of audio bytes or frames Audio_TotalN_A I accumulated before A I ; (c34)从音频数据块AI对应的索引信息块中找到偏移位置dwOffset,该位置即为重传位置,(c34) find the offset position dwOffset from the index information block corresponding to the audio data block A1 , this position is the retransmission position, 所述步骤(c4)中计算播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size时,只需将步骤(c31)公式中的VI的帧序号改成VC的帧序号即可。When calculating the number of audio bytes or the frame number Audio_accum_size of that road audio stream that will switch to when playing VC in the described step (c4), only need to change the frame sequence number of VI in the formula of step (c31) It can be converted into the frame number of VC . 6.如权利要求3所述的AV同步方法,其特征在于:6. AV synchronization method as claimed in claim 3, characterized in that: 所述帧数B取值范围为:6~12个帧。The value range of the number of frames B is: 6 to 12 frames. 7.如权利要求1所述的AV同步方法,其特征在于:7. AV synchronization method as claimed in claim 1, characterized in that: 步骤(a)中,切换控制单元收到切换请求后,还向所述数据传输单元发送切换指令,所述数据传输单元收到切换指令后,立即停止对原音视频流的传输;同时,如AVI文件中包含三路及以上的音频流数据,则切换控制单元发送到数据处理单元和数据解码单元的指令中,需要指示要切换到的是哪一路音频流。In step (a), after the switch control unit receives the switch request, it also sends a switch command to the data transmission unit, and after the data transmission unit receives the switch command, it immediately stops the transmission of the original audio and video stream; meanwhile, such as AVI If the file contains three or more audio streams, the switching control unit needs to indicate which audio stream to switch to in the instructions sent to the data processing unit and the data decoding unit. 8.一种AVI文件播放时切换多路音频流的AV同步装置,其特征在于,包括:8. an AV synchronization device for switching multiple audio streams during AVI file playback, characterized in that, comprising: 数据传输单元,用于读取AVI文件的音视频数据传输到数据处理单元,并在收到重传指令后按指定重传位置重新传输AVI文件的音视频数据;The data transmission unit is used to read the audio and video data of the AVI file and transmit it to the data processing unit, and retransmit the audio and video data of the AVI file by the designated retransmission position after receiving the retransmission instruction; 数据处理单元,用于对AVI文件头信息和索引信息进行解析后保存,完成音频流和视频流的分离并传输给数据解码单元,在收到切换指令后,从音视频数据中分离出视频流和应切换到的那路音频流;The data processing unit is used to analyze and save the AVI file header information and index information, complete the separation of the audio stream and the video stream and transmit them to the data decoding unit, and separate the video stream from the audio and video data after receiving the switching instruction and the audio stream that should be switched to; 切换控制单元,用于在收到切换请求后,向数据处理单元和数据解码单元发送切换指令,然后根据当前解码的视频帧数和保存的索引信息、文件头信息计算得到重传位置和同步播放参数,将重传位置发送到数据传输单元,将同步播放参数发送到数据解码单元,所述同步播放参数为计算出的音频跳过数目Skip_audio和视频跳过数目Skip_Frame;The switching control unit is used to send switching instructions to the data processing unit and the data decoding unit after receiving the switching request, and then calculate the retransmission position and synchronous playback according to the number of currently decoded video frames and the saved index information and file header information Parameter, the retransmission position is sent to the data transmission unit, and the synchronous playback parameter is sent to the data decoding unit, and the synchronous playback parameter is the calculated audio skipping number Skip_audio and video skipping number Skip_Frame; 数据解码单元,包括音频解码子单元和视频解码子单元;在收到切换指令后,向切换控制单元回传当前解码的视频帧数,并完成视频解码的重新初始化以及按要切换到的那路音频流的参数重新进行音频解码的初始化;根据接收的同步播放参数,所述数据解码单元对重新传输的音视频流开始部分的Skip_audio个字节数或帧数以及Skip_Frame个视频帧,解码后不传输到数据显示单元,之后解码的音视频数据再传输到数据显示单元进行同步播放,其中对固定码流采用字节数,对可变码流采用帧数。The data decoding unit includes an audio decoding subunit and a video decoding subunit; after receiving the switching instruction, it returns the number of currently decoded video frames to the switching control unit, and completes the reinitialization of video decoding and the channel to be switched to The parameters of the audio stream are re-initialized for audio decoding; according to the received synchronous playback parameters, the data decoding unit does not decode the Skip_audio bytes or frames and the Skip_Frame video frames at the beginning of the retransmitted audio and video stream. It is transmitted to the data display unit, and then the decoded audio and video data is transmitted to the data display unit for synchronous playback, wherein the number of bytes is used for the fixed code stream, and the number of frames is used for the variable code stream. 9.如权利要求8所述的AV同步装置,其特征在于:所述切换控制单元进一步包括:9. The AV synchronization device according to claim 8, characterized in that: the switching control unit further comprises: 接口子单元,用于完成切换控制单元与其它单元之间的通信;The interface subunit is used to complete the communication between the switching control unit and other units; 信息提取子单元,用于从数据处理单元获取AVI文件头信息和索引信息,供运算子单元使用The information extraction subunit is used to obtain the AVI file header information and index information from the data processing unit for use by the operation subunit 控制子单元,用于在收到用户接口单元的切换请求后,向数据解码单元、数据处理单元和数据解码单元发送切换指令,发送到数据处理单元和解码单元的指令应携带要切换到的音频流标识,从数据解码单元获取当前解码的视频帧序号传送到运算子单元;并在收到运算子单元的重传位置、音频跳过数目和视频跳过数目参数后,向数据传输单元发送重传指令,携带重传位置参数,以及将音频跳过数目和视频跳过数目参数传输到数据解码单元;The control subunit is used to send switching instructions to the data decoding unit, data processing unit and data decoding unit after receiving the switching request from the user interface unit, and the instructions sent to the data processing unit and decoding unit should carry the audio to be switched to Stream ID, obtain the current decoded video frame sequence number from the data decoding unit and send it to the operation subunit; and after receiving the parameters of the retransmission position, the number of audio skips and the number of video skips of the operation subunit, send a retransmission to the data transmission unit Passing instructions, carrying retransmission position parameters, and transmitting the parameters of the number of audio skips and the number of video skips to the data decoding unit; 运算子单元,用于根据当前解码的视频帧序号和AVI文件头信息和索引信息,计算出重传位置、音频跳过数目Skip_audio和视频跳过数目Skip_Frame,传送到控制子单元。The operation subunit is used to calculate the retransmission position, the number of audio skips Skip_audio and the number of video skips Skip_Frame according to the currently decoded video frame number and AVI file header information and index information, and transmit them to the control subunit. 10.如权利要求8所述的AV同步装置,其特征在于:10. The AV synchronization device according to claim 8, characterized in that: 所述数据解码单元在收到切换指令后,继续对缓存的视频数据进行解码,在收到参数Skip_audio和Skip_Frame后,再清空缓存的视频数据,进行视频解码的重新初始化。The data decoding unit continues to decode the buffered video data after receiving the switching instruction, and clears the buffered video data after receiving the parameters Skip_audio and Skip_Frame to re-initialize the video decoding. 11.如权利要求9所述的AV同步装置,其特征在于:所述运算子单元进一步包括以下部分:11. The AV synchronization device according to claim 9, characterized in that: the operation subunit further comprises the following parts: 同步点计算及索引信息提取部分,根据切换音频数据流时正在解码的帧数A加上设定的帧数B,得到本次切换的视频同步点VC的帧序号,且根据解析的音视频数据开始位置和其总大小,确定索引信息起始位置,读取索引信息并保存;The synchronization point calculation and index information extraction part, according to the frame number A being decoded when switching the audio data stream plus the set frame number B, obtains the frame number of the video synchronization point V C of this switch, and according to the analyzed audio and video The starting position of the data and its total size, determine the starting position of the index information, read and save the index information; I帧确定部分,从音视频数据索引开始位置累计视频帧的数目,以累计的视频帧数最接近且小于VC帧序号的I帧为VC之前最近的I帧VIThe I frame determines the part, from the audio and video data index start position to accumulate the number of video frames, the I frame closest to and less than the V C frame sequence number is the nearest I frame V I before the V C with the accumulated video frame number; 重传位置计算部分,从索引信息中找到VI对应的音频数据块AI,读取AI在AVI文件中的偏移位置,以该位置为重传位置;The retransmission position calculation part finds the audio data block A I corresponding to VI from the index information, reads the offset position of A I in the AVI file, and takes this position as the retransmission position; 跳过数目计算部分,计算VC与VI之间的帧数差即视频跳过数目Skip_Frame,以及播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size与AI之前累加得到的音频字节数或帧数Audio_TotalN_AI的差值,即音频跳过数目Skip_audio。Skip the number calculation part, calculate the frame number difference between VC and VI , that is, the video skip number Skip_Frame, and the number of audio bytes or frames Audio_accum_size that should be played by the audio stream to be switched to when playing VC The difference between the number of audio bytes or the number of frames Audio_TotalN_A I accumulated before AI , that is, the number of audio skips Skip_audio. 12.如权利要求11所述的AV同步装置,其特征在于:12. The AV synchronization device according to claim 11, characterized in that: 所述重传位置计算部分查找VI对应的音频数据块AI时,先计算播放VI之前要切换到的那路音频流应播过的音频字节数或帧数Audio_TotalN_I,公式为:When the retransmission position calculation part searches for the corresponding audio data block A1 of V1 , it first calculates the number of audio bytes or the number of frames Audio_TotalN_I that should be played by the audio stream that will be switched to before playing V1 , and the formula is: 对固定码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*CBR音频字节率To fixed stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate indicator)*CBR audio byte rate 对可变码流:Audio_TotalN_I=VI的帧序号*(视频流时间尺度/视频流速率指标)*VBR音频采样率/1152To variable bit stream: Audio_TotalN_I= VI frame sequence number*(video stream time scale/video stream rate index)*VBR audio frequency sampling rate/1152 再从音视频数据的起始位置,逐一累加要切换到的那路音频流数据块的字节数或帧数,将累加值与上面得到的Audio_TotalN_I进行比较,如果小于Audio_TotalN_I,再进行下一次累加,如累加值等于Audio_TotalN_I,则该路音频流的下一音频数据块即为VI对应的音频数据块AI,如累加值大于Audio_TotalN_I,则该音频数据块即为VI对应的音频数据块AI,同时记录AI之前累加得到的音频字节数或帧数Audio_TotalN_AIThen from the starting position of the audio and video data, add up the number of bytes or frames of the audio stream data block to be switched to one by one, compare the accumulated value with the Audio_TotalN_I obtained above, if it is less than Audio_TotalN_I, perform the next accumulation , if the accumulated value is equal to Audio_TotalN_I, then the next audio data block of this road audio stream is the corresponding audio data block A I of VI, if the accumulated value is greater than Audio_TotalN_I, then this audio data block is the corresponding audio data block of VI A I , while recording the number of audio bytes or frames Audio_TotalN_A I accumulated before A I ; 最后,从音频数据块AI对应的索引信息块中找到偏移位置dwOffset,该位置即为重传位置,Finally, find the offset position dwOffset from the index information block corresponding to the audio data block A1 , which is the retransmission position, 所述跳过数目计算部分计算播放VC时要切换到的那路音频流应播过的音频字节数或帧数Audio_accum_size时,只需将上述计算Audio_TotalN_I公式中的VI的帧序号改成VC的帧序号即可。When the said skip number calculation part calculates the number of audio bytes or the number of frames Audio_accum_size that the audio stream to be switched to when playing VC , only the frame sequence number of VI in the above-mentioned calculation Audio_TotalN_I formula needs to be changed into The frame number of VC is enough. 13.如权利要求8所述的AV同步装置,其特征在于:13. The AV synchronization device according to claim 8, characterized in that: 所述切换控制单元还用于在收到切换请求后,向所述数据传输单元发送切换指令;所述数据传输单元收到切换指令后,立即停止对原音视频流的传输;所述切换控制单元在播放的AVI文件中包含三路及以上的音频流数据时,发送到数据处理单元和数据解码单元的指令中,需要指示要切换到的是哪一路音频流。The switching control unit is also used to send a switching instruction to the data transmission unit after receiving the switching request; after the data transmission unit receives the switching instruction, immediately stop the transmission of the original audio and video stream; the switching control unit When the played AVI file contains three or more audio stream data, it is necessary to indicate which audio stream to switch to in the instructions sent to the data processing unit and the data decoding unit. 14.如权利要求8所述的AV同步装置,其特征在于:14. The AV synchronization device according to claim 8, characterized in that: 所述装置应用于嵌入式系统,所述数据解码单元用硬件实现,切换控制单元、数据传输单元和数据处理单元由CPU执行相应软件来实现。The device is applied to an embedded system, the data decoding unit is realized by hardware, and the switching control unit, data transmission unit and data processing unit are realized by CPU executing corresponding software.
CN 200610172268 2006-12-30 2006-12-30 AV synchronization method and device for switching multi-channel audio stream during playing of AVI file Expired - Fee Related CN101212679B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200610172268 CN101212679B (en) 2006-12-30 2006-12-30 AV synchronization method and device for switching multi-channel audio stream during playing of AVI file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200610172268 CN101212679B (en) 2006-12-30 2006-12-30 AV synchronization method and device for switching multi-channel audio stream during playing of AVI file

Publications (2)

Publication Number Publication Date
CN101212679A CN101212679A (en) 2008-07-02
CN101212679B true CN101212679B (en) 2010-04-14

Family

ID=39612282

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200610172268 Expired - Fee Related CN101212679B (en) 2006-12-30 2006-12-30 AV synchronization method and device for switching multi-channel audio stream during playing of AVI file

Country Status (1)

Country Link
CN (1) CN101212679B (en)

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102098423B (en) * 2009-12-10 2013-03-27 北大方正集团有限公司 Seamless file collection method and system
CN102110459B (en) * 2009-12-24 2013-01-16 Tcl集团股份有限公司 Playing terminal and multimedia file playing method and device thereof
US8681786B2 (en) * 2010-02-08 2014-03-25 Via Telecom Co., Ltd. Centralized recording and processing of received packet parameters
CN102324097B (en) * 2011-08-17 2013-12-11 深圳锐取信息技术股份有限公司 Method for detecting image change
CN102547435B (en) * 2011-12-16 2014-06-25 Tcl集团股份有限公司 System and method for playing and processing multimedia file
CN102510541B (en) * 2011-12-30 2014-12-17 Tcl数码科技(深圳)有限责任公司 Multi-screen interaction video and audio content switching method and media player
CN102867525B (en) * 2012-09-07 2016-01-13 Tcl集团股份有限公司 A kind of multichannel voice frequency disposal route, audio-frequency playing terminal and apparatus for receiving audio
US11176111B2 (en) * 2013-03-15 2021-11-16 Nuodb, Inc. Distributed database management system with dynamically split B-tree indexes
KR101861941B1 (en) * 2014-02-10 2018-07-02 돌비 인터네셔널 에이비 Embedding encoded audio into transport stream for perfect splicing
CN104602115A (en) * 2015-01-13 2015-05-06 青岛海信宽带多媒体技术有限公司 Method and system for switching of network television channels
CN106411903B (en) * 2016-10-08 2019-08-23 Oppo广东移动通信有限公司 Play control method, device and terminal
US10873775B2 (en) * 2017-06-12 2020-12-22 Netflix, Inc. Staggered key frame video encoding
CN111063376B (en) * 2019-12-13 2021-05-14 厦门市美亚柏科信息股份有限公司 Method, terminal equipment and storage medium for audio and video synchronization in MP4 repairing
CN112532991B (en) * 2020-10-28 2023-04-14 惠州华阳通用电子有限公司 Hardware decoding method for RMFF format file

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6512884B1 (en) * 1998-10-15 2003-01-28 Nec Corporation Method and apparatus for synchronized play back of audio-video signals
FR2866729A1 (en) * 2004-02-25 2005-08-26 Opencube Multi-track audiovisual flow processing device, has administration module that synchronizes successive use of synchronized buffers by different active processes according to usage sequence determined by switching process
CN1728770A (en) * 2004-07-28 2006-02-01 乐金电子(惠州)有限公司 Device for synchronizing video and audio of Kara-OK system
CN1767601A (en) * 2005-10-21 2006-05-03 西安交通大学 A synchronous playback control method supporting multi-source streaming media

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6512884B1 (en) * 1998-10-15 2003-01-28 Nec Corporation Method and apparatus for synchronized play back of audio-video signals
FR2866729A1 (en) * 2004-02-25 2005-08-26 Opencube Multi-track audiovisual flow processing device, has administration module that synchronizes successive use of synchronized buffers by different active processes according to usage sequence determined by switching process
CN1728770A (en) * 2004-07-28 2006-02-01 乐金电子(惠州)有限公司 Device for synchronizing video and audio of Kara-OK system
CN1767601A (en) * 2005-10-21 2006-05-03 西安交通大学 A synchronous playback control method supporting multi-source streaming media

Also Published As

Publication number Publication date
CN101212679A (en) 2008-07-02

Similar Documents

Publication Publication Date Title
CN101212679B (en) AV synchronization method and device for switching multi-channel audio stream during playing of AVI file
US7412149B2 (en) Trick mode generation in video streaming
US6628890B1 (en) Digital recording/reproduction apparatus
US8301016B2 (en) Decoding and output of frames for video trick modes
JP4270379B2 (en) Efficient transmission and reproduction of digital information
JP3894572B2 (en) Method for transmitting and receiving compressed television signals
JP2001359072A (en) Data converter and method, data distributor and method, data distribution system
US20100166387A1 (en) Method and apparatus for playing video data of high bit rate format by a player capable of playing video data of low bit rate format
WO2004015550A2 (en) Data streaming system and method
US6754239B2 (en) Multiplexing apparatus and method, transmitting apparatus and method, and recording medium
US20090046994A1 (en) Digital television broadcast recording and reproduction apparatus and reproduction method thereof
KR100770908B1 (en) Variable playback apparatus and method for digital broadcast stream
CN100416689C (en) Reproducing apparatus and method, and recording medium
JP3558983B2 (en) Digital broadcast recording and playback device
JP2004153791A (en) Moving image/sound recording apparatus and moving image/sound recording method
JP3072971B2 (en) Video-on-demand system, video server device and terminal device constituting the system
TWI415432B (en) Data flow transfer method from data source to data filer and data file device and data source device used for performing the method
JP2001359071A (en) Data distributor and method, and data distribution system
JP4112350B2 (en) Moving image communication system, moving image reproduction terminal, moving image distribution apparatus, and moving image distribution method
JP2004153793A (en) Motion picture/sound recording apparatus and motion picture/sound reproducing apparatus
JP4484220B2 (en) Video distribution device
JPH099215A (en) Data multiplex method, data transmission method, multiplex data decoding method and multiplex data decoder
JP3773892B2 (en) Digital recording / reproducing device
JP2000187940A (en) Recording/reproducing device and recorder
JP2001086430A (en) Recording and reproducing device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
ASS Succession or assignment of patent right

Owner name: BEIJING SUNPLUS EHUE TECHNOLOGY CO., LTD.

Free format text: FORMER OWNER: BEIJING BEIYANG ELECTRONIC TECHNOLOGY CO., LTD.

Effective date: 20140314

C41 Transfer of patent application or patent right or utility model
TR01 Transfer of patent right

Effective date of registration: 20140314

Address after: Science and Industry Park, Taiwan, Hsinchu, China, No. 19

Patentee after: Lingyang Science and Technology Co., Ltd.

Patentee after: BEIJING SUNPLUS-EHUE TECHNOLOGY CO., LTD.

Address before: Science and Industry Park, Taiwan, Hsinchu, China, No. 19

Patentee before: Lingyang Science and Technology Co., Ltd.

Patentee before: Beijing Beiyang Electronic Technology Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20100414

Termination date: 20171230