当前位置:网站首页>Audio and video synchronization knowledge points you must pay attention to:
Audio and video synchronization knowledge points you must pay attention to:
2022-06-21 09:22:00 【Caijing embedded】
========
# All knowledge of audio and video synchronization :
1、 Now that you are paying attention to audio and video synchronization , So suppose you have basic background knowledge , such as : Have computer knowledge ; Programming theory ( Know interrupt 、 cache 、 State machine 、 modular ); Know a programming language ; know MPEG ISO agreement ; know mp4、mkv、ts And so on ; know h264、hevc、mpeg2、mpeg4 And other video stream formats ; know mp3、aac And other audio stream formats ; know RGB、YUV、YCrCb、WAV And other display and playback formats ; Know the display driver audio driver ; Know the screen refresh rate vsync. If you don't know these, you need to search and learn relevant knowledge when you encounter them in practice .
2、 Unpacking ( from mp4 And other files to separate video stream and audio stream ) Get the video frame rate when ( Display time of each frame ); Video width and height parameters ; Of each frame of video dts、pts, And convert it to the relative time when the file starts playing ( Unit is ms); Audio frame dts; Audio sampling frequency 、 The channel number 、 Sampling depth ; A cache is required to store video frames and audio frames and transmit the cache to lower level modules , Each frame cache must carry the pts Time , If you use a fixed cache , Multiple frames or even incomplete frames are stored in the fixed cache at one time , Just send it directly to the decoding module , You need to carry the oldest in each cache pts, And after that, I can pts Perform a dead reckoning restore .
2.1、 When unpacking, you can directly stream the files as required , Read required length , You need to analyze how long you study , Even jump back and forth in the file to read non fixed length data , But this will reduce the burden on your system , Without the support of operating system file system, it will increase IO Number of reads , Increase the time consumption caused by reading files , At this time, you may need to pre cache a fixed length of file data each time when unpacking , Then parse the data in the cache , This is also a complicated logic , Various switching processes are required . In addition, the data frame length cached by the general audio and video playback module is different , You may need a cache of read data frames for both video and audio , They are still a long way from the address currently read in the file .
3、 Both audio and video decoding support frame input and random length input , It is best to input by frame , However, in order to save execution times and make better use of cache resources, you can also enter by cache length , Audio and video decoding requires that the first frame of the input pts And each frame after decoding pts correspond , The decoded data is usually of fixed length , It is also convenient to display and play fixed length data .
4、 The decoded data frames of the audio and video streams are sent to the audio and video synchronization module , The synchronization module sends the audio directly to the playback module for playback , However, it is necessary to record the current playback frame when sending pts、 The length and time of data currently being cached by the audio playback module during playback , Audio playback data is generally obtained through callback or interrupt , At this time, you need to record this information during callback , From this information, the audio time axis is calculated .( This is the mainstream method of video synchronization to audio , The method of synchronizing audio to video and audio and video to the main time axis is not introduced here )
4.1、 During video display, it is necessary to record the system time point and frame displayed in the current frame pts, Calculate the video timeline .
4.2、 Through the audio and video synchronization algorithm and the time base of the current audio and video, it is determined that the current video frame is displayed in advance 、 Whether the display is pushed back or the frame is lost . General video leading audio 100ms To fall behind 20ms Human ears can't feel it , Within this range, the video can be displayed at the original frame rate , Otherwise, the current frame will be displayed in advance or later .
4.3、 Generally, the input and output structures of video decoding have private parameters , This parameter allows you to match the input frame order with the output frame order , The private parameter data of the output frame after decoding is the content of the data of the previous frame . be based on I frame 、P frame 、B Frame bidirectional prediction encoding and decoding method , The video decoding sequence is different from the playback sequence , The decoding timestamp is dts, The display timestamp is dts, This mechanism of the video decoding module allows you not to calculate the frame time matching by yourself , Because the input and output of video decoding have frame caching mechanism , It is difficult to calculate the timestamp per frame pts. A video frame before decoding , It may decode several frames , This mechanism also requires you to deal with this situation artificially , Because the decoded video frames have the same private parameters ( That is to say pts Time stamp ).
5、 The video display module has a fixed vsync The refresh rate , Such as 60Hz, If the frame rate of the video stream is close to the frame rate of the display module, it needs to be set in vsync Refresh the contents of the video memory at the switched time point , Match the timing .
6、 The actual playback speed of the audio playback module may not be the speed of the audio stream standard , Such as 44100Hz, At this time, match the audio time axis .
6.1、 When playing at double speed , To ensure that the audio is not distorted , You also need to resample the audio frame data , Make sure that the frequency in the audio is also adjusted according to the multiple speed , This involves algorithms , Not covered here .
边栏推荐
- It is said that this year gold three silver four has become gold one silver two.
- Shortcut keys accumulated when using various software
- R language factor variable type: use factor function to convert string vector to factor vector, and use as The factor function converts a factor vector into a string vector and uses as The numeric fun
- Mobile applications introduce static Cordova according to different platforms
- 121. Redux detailed summary + effect drawing + Case
- 【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
- The R language plot function visualizes multiple lines in the same plot, and uses the BMP function to save the visualization image to the BMP format file in the specified directory
- 【实战】STM32 FreeRTOS移植系列教程2:FreeRTOS 互斥信号量
- leetcode:打印两个有序链表的公共部分
- Common shortcut keys for idea
猜你喜欢

TC软件概要设计文档(手机群控)

Full stack development

stm32mp1 Cortex M4开发篇8:扩展板LED灯控制实验

PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分

stm32mp1 Cortex M4开发篇9:扩展板空气温湿度传感器控制

Abstractqueuedsynchronizer (AQS) source code detailed analysis - condition queue process analysis

stm32mp1 Cortex M4开发篇12:扩展板震动马达控制

Observation on the salary data of the post-90s: poor, counselled and serious
![[Mgt] model Mgt for code interpretation](/img/4f/694e7b93626436007021b718ad69b5.png)
[Mgt] model Mgt for code interpretation
![[actual combat] STM32 FreeRTOS migration series tutorial 7: FreeRTOS event flag group](/img/1c/10add042271c11cd129ddfce66f719.jpg)
[actual combat] STM32 FreeRTOS migration series tutorial 7: FreeRTOS event flag group
随机推荐
Stm32mp1 cortex M4 Development Chapter 11: expansion board buzzer control
121. Redux detailed summary + effect drawing + Case
R language factor variable type: use factor function to convert string vector to factor vector, and use as The factor function converts a factor vector into a string vector and uses as The numeric fun
\Processing method of ufeff
AQS source code exploration_ 01 handwriting a simplified reentrantlock reentrant lock
Common basic functions of R language: LS function lists all data objects in the current workspace, RM function deletes the specified data objects in the current workspace
Jar package required for full stack development
111. solve the problem of prohibiting scripts from running on vs code. For more information, see error reporting
stm32mp1 Cortex M4开发篇10:扩展板数码管控制
ArCore支持的设备
如何选择嵌入式练手项目、嵌入式开源项目大全
远程办公市场调查报告
Prefix sum and difference
Retrofit extended reading
The R language uses the fix function to modify the name of the data variable through the editor. For example, use the fix function to modify the name of the dataframe data column
【实战】STM32 FreeRTOS移植系列教程2:FreeRTOS 互斥信号量
Mobile applications introduce static Cordova according to different platforms
The R language uses the sink function to export the string to the txt file in the specified directory. If no directory is specified, it will be output to the current working dir
R language uses as The date function converts a single character variable to date data and specifies the format of the data format conversion
R language through rprofile Site file, custom configuration of R language development environment startup parameters, shutdown parameters, configuration of R startup output custom text and system time