Http://tech.bobgo.net /? M = 201004
Because the recent work needs to extract some key frames from MP4 videos, You Need To Know HowTime PointConvert to the correspondingFrame numberFor this reason, I read some documents about video codec and time synchronization. Here is a summary.
The first is decoding. The information obtained by decoding with FFmpeg is usually as follows:
Metadata:
Major_brand: isom
Minor_version: 512
Compatible_brands: mp41
Title: Digital Tipping Point
Data: 2008
Encoder: lavf51.10.0
Comment: License: http://creativecommons.org/licenses/by-sa/3.0/
Duration: 00:03:44. 29, start: 0.000000, bitrate: 579 kb/s
Stream #0.0 (UND): Video: h264, yuv420p, 360 × 240 [par dar], 511kb/s, 29.97 FPS, 29.97 TBR, 2997 TBN, 59.94 TBC
Stream #0.1 (UND): Audio: AAC, 32000Hz, stereo, S16, 64 KB/s
Output #0, image2, '? ':
Stream #0.0: Video: MJPEG, yuvj420p, 360 × 240, q = 2-31,100 000 kb/s, 90 k tbn, 59.94 TBC
However, I only pay attention to some of the information, mainly related to frame rate and time synchronization.
1. Color encoding:Among them, yuv420 is the color encoding method commonly used in videos. y indicates the brightness, while U and V are related to the color, and 420 correspond to the ratio of the bits used to store the corresponding components. In fact, this encoding method is used to ensure better compatibility between early-time color TVs and black and white TVs. For more details, see the corresponding entries in Baidu encyclopedia.
2. Frame Rate information:
In the above example, parameters such as FPS, TBR, TBN, and TBC respectively indicate the meanings. If I want to complete the time point and frame number conversion, I need to find the appropriate parameters. Refer to a BBS and get the following information:
TBN is the time base in avstream that has come from thecontainer, I
Think. It is used for all avstream time stamps.
TBC is the time base in avcodeccontext for the codec used fora
Particle stream. It is used for all avcodeccontext and relatedtime
Stamps.
TBR is guessed from the video stream and is the value users wantto see
When they look for the video frame rate, when T sometimes it istwice
What one wowould expect CT because of field rate versus frame rate.
FPS is frame per second, which means frame rate.
Therefore, both TBN and TBC should be time units on the corresponding layer. For example, TBN = 2997 is equivalent to dividing 1 s of time into 2997 time units at the video stream layer, this fine granularity can better synchronize with other streams, such as audio streams. Corresponding to FPS = 29.97, there is a frame in every 100 time units.
3. Time synchronization mode:
The problem is: FPS = 29.97. This is a decimal number. If I use the formula frame number = time * FPS to get it, it is not an integer, and the frame number should be an integer.
First, how do we get the abnormal number of 29.97f/s? This originated from the early ntsc TV standard, while modern digital coding only follows its standard for compatibility. In fact, in the standard system, NTSC uses the Frame Rate of 30f/s, just to eliminate the photo stem produced by the color signal and sound signal, the bandwidth per second is increased from 30 seconds to 29.97 seconds, and the peak bandwidth is decreased from 15734.26Hz to Hz. For more information, see Wikipedia: link.
Then, how can we achieve the frame rate with a decimal point? Obviously, it is impossible to display the same number of frames per second. In fact, there is a time synchronization standard called smptenon-drop-frame and smptedrop-frame. That is to say, in some cases, the time synchronization will be done by dropping some frames.
For example, we can calculate the 29.97 Frame Rate: 29.97 F/sec = 1798.2 F/min = 107892f/hour;
For the Frame Rate of 30f/s, we can calculate: 30 F/S = 1800 F/S = 108000 F/hour;
In this way, if the video is collected at a speed of 30 frames per second and the video is played at a rate of 29.97f/s, 108 frames will be played less each hour, in this way, the playback time is slower than the actual time. In order to solve this problem, the SMPTE30Drop-Frame took the way to lose the 108 frames, the specific strategy is to lose two frames every 1 minute, if it is 10th minutes, then do not lose, therefore, the number of frames dropped per hour is: 2x60-2x6 = 108 frames. For more information, see link1 and link2.
Alas, How troublesome it is. If the collection and playback adopt 30f/s, it will not save much time, but the technology is always facing forward compatibility problems, just like the story of railway and horse ass!
Http://topic.csdn.net/u/20091225/09/0a7499ce-7015-40fb-9c9d-f8628d0fe275.html
25 TBR indicates the frame rate. 1200 k tbn indicates the time precision of the file layer (ST), that is, 1 S = 1200 K, which is related to duration. 50tbc indicates the video layer (St-> codec) the time precision, that is, 1 S = 50, is related to strem-> duration and timestamp.
TBR TBN TBC