ffmpeg # tbr & tbn & tbc
用ffmpeg处理文件时,刚开始会对输入文件的一些信息信息解析, 可能会打印如下的一下信息:
Input #0, flv, from '/Users/Private/sample.flv':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.20.100
Duration: 00:09:56.46, start: 0.000000, bitrate: 530 kb/s
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 424x240, 420 kb/s, 24 fps, 24 tbr, 1k tbn, 48 tbc
里边涉及的24 fps, 24 tbr, 1k tbn, 48 tbc都是什么含义呢?
tbn is the time base in AVStream that has come from the container, I
think. It is used for all AVStream time stamps.
tbc is the time base in AVCodecContext for the codec used for a
particular stream. It is used for all AVCodecContext and related time
stamps.
tbr is guessed from the video stream and is the value users want to see
when they look for the video frame rate, except sometimes it is twice
what one would expect because of field rate versus frame rate.
相关的代码如下:
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
int tbn = st->time_base.den && st->time_base.num;
int tbc = st->codec->time_base.den && st->codec->time_base.num;
if (fps || tbr || tbn || tbc)
av_log(NULL, AV_LOG_INFO, "%s", separator);
if (fps)
print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
if (tbr)
print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
if (tbn)
print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
if (tbc)
print_fps(1 / av_q2d(st->codec->time_base), "tbc");
}
- tbr
/**
* Real base framerate of the stream.
* This is the lowest framerate with which all timestamps can be
* represented accurately (it is the least common multiple of all
* framerates in the stream). Note, this value is just a guess!
* For example, if the time base is 1/90000 and all frames have either
* approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
*/
AVRational r_frame_rate;
实际帧率。也是一个估算值。当视频的码率为固定帧率时,FFmpeg显示tbr为正常的帧率值。当视频有变帧率时,FFmpeg打印的tbr为多个帧率的均值 (存疑? 需进一步验证 )
https://www.jianshu.com/p/5b78a91f1091
- tbn
tbn 就是封装层的time_base, 它是从文件容器中直接读取的,比如flv的视频和音频读取到的是1000,ts文件读取到的是90k,mp4文件视频比较变化多样,可能是24,1000等,mp4的音频一般是采样率。
24 fps, 24 tbr, 1k tbn, 48 tbc表明'/Users/Private/sample.flv':
帧率是24帧/秒
封装层的时间戳单位(也就是实际在文件中存储的时间戳)为{1, 1000}
编码层(解码时)的时间单位为{1, 48}。有的文章说这里之所以设置为帧率的2倍,可能是为了处于处理Interlaced类型隔场扫描类型的文件(平时的文件存储的数据都是逐行扫描的)。
References:
https://docs.edu-sharing.com/confluence/edp/de/installation-en/installation-of-the-edu-sharing-rendering-service/supported-video-formats
http://blog.chinaunix.net/uid-11344913-id-5750194.html
https://trac.ffmpeg.org/wiki/ChangingFrameRate
https://www.cnblogs.com/my_life/articles/6860439.html
https://www.jianshu.com/p/5b78a91f1091
https://www.jianshu.com/p/bfec3e6d3ec8