目录
1、认识AVRational,说白了就是个分数a/b,?
2、第二个是video_thread()的读帧的一段,每获取一个frame就打印一下log;看pts,
3、为什么这么做:
1、认识AVRational,说白了就是个分数a/b,?
下面是定义的结构体:
/**
* Rational number (pair of numerator and denominator).
*/
typedef struct AVRational{
int num; ///< Numerator
int den; ///< Denominator
} AVRational;
等下会用到这个结构体;
2、第二个是video_thread()的读帧的一段,每获取一个frame就打印一下log;看pts,
duration = (frame_rate.num && frame_rate.den ? av_q2d((AVRational){frame_rate.den, frame_rate.num}) : 0);
pts = (frame->pts == AV_NOPTS_VALUE) ? NAN : frame->pts * av_q2d(tb);
printf("lee pts1:%lf,frame->pts:%llu,tb:(%d,/ %d\n)", pts,frame->pts,tb.num,tb.den);
我们在拿到frame(由AVFrame生成的对象)里面有个变量pts,顾名思义:是渲染的时间,但是这个并不是时间为单位的数值,是可以转换成时间的数值,需要用 frame->pts * av_q2d(tb)得到,
什么意思?
答:frame->pts是有很大的数,类似于采样率一样的,1000;2000; 3000;4000...........100000;
按照这种递增的,每个帧都有这个pts,?
av_q2d(tb)的tb就是刚才的AVRational,av_q2d()就是分子除以分母得到的值,
static inline double av_q2d(AVRational a){
return a.num / (double) a.den;
}
换算成现实中的时间就是:frame->pts * av_q2d(tb);是以s为单位的。
3、为什么这么做:
我猜是防止直接用时间误差扩大,因为时间除不尽,如果一个帧误差0.00001s,10w帧就差不多1s就会造成音视频不同步;用这种防止误差。
看个log就比较明确了;
lee pts1:0.000000,frame->pts:0,tb:(1,/ 24000
lee pts1:0.041708,frame->pts:1001,tb:(1,/ 24000
lee pts1:0.083417,frame->pts:2002,tb:(1,/ 24000
lee pts1:0.125125,frame->pts:3003,tb:(1,/ 24000
lee pts1:0.166833,frame->pts:4004,tb:(1,/ 24000
lee pts1:0.208542,frame->pts:5005,tb:(1,/ 24000
lee pts1:0.250250,frame->pts:6006,tb:(1,/ 24000
lee pts1:0.291958,frame->pts:7007,tb:(1,/ 24000
lee pts1:0.333667,frame->pts:8008,tb:(1,/ 24000
lee pts1:0.375375,frame->pts:9009,tb:(1,/ 24000
lee pts1:0.417083,frame->pts:10010,tb:(1,/ 24000
lee pts1:0.458792,frame->pts:11011,tb:(1,/ 24000
lee pts1:0.500500,frame->pts:12012,tb:(1,/ 24000
lee pts1:0.542208,frame->pts:13013,tb:(1,/ 24000
lee pts1:0.583917,frame->pts:14014,tb:(1,/ 24000
lee pts1:0.625625,frame->pts:15015,tb:(1,/ 24000
lee pts1:0.667333,frame->pts:16016,tb:(1,/ 24000
lee pts1:0.709042,frame->pts:17017,tb:(1,/ 24000
lee pts1:0.750750,frame->pts:18018,tb:(1,/ 24000
lee pts1:0.792458,frame->pts:19019,tb:(1,/ 24000
lee pts1:0.834167,frame->pts:20020,tb:(1,/ 24000
lee pts1:0.875875,frame->pts:21021,tb:(1,/ 24000
lee pts1:0.917583,frame->pts:22022,tb:(1,/ 24000
lee pts1:0.959292,frame->pts:23023,tb:(1,/ 24000
lee pts1:1.001000,frame->pts:24024,tb:(1,/ 24000
lee pts1:1.042708,frame->pts:25025,tb:(1,/ 24000
lee pts1:1.084417,frame->pts:26026,tb:(1,/ 24000
lee pts1:1.126125,frame->pts:27027,tb:(1,/ 24000
lee pts1:1.167833,frame->pts:28028,tb:(1,/ 24000
lee pts1:1.209542,frame->pts:29029,tb:(1,/ 24000
lee pts1:1.251250,frame->pts:30030,tb:(1,/ 24000
lee pts1:1.292958,frame->pts:31031,tb:(1,/ 24000
lee pts1:1.334667,frame->pts:32032,tb:(1,/ 24000
lee pts1:1.376375,frame->pts:33033,tb:(1,/ 24000
lee pts1:1.418083,frame->pts:34034,tb:(1,/ 24000
lee pts1:1.459792,frame->pts:35035,tb:(1,/ 24000
lee pts1:1.501500,frame->pts:36036,tb:(1,/ 24000
lee pts1:1.543208,frame->pts:37037,tb:(1,/ 24000
lee pts1:1.584917,frame->pts:38038,tb:(1,/ 24000
lee pts1:1.626625,frame->pts:39039,tb:(1,/ 24000
lee pts1:1.668333,frame->pts:40040,tb:(1,/ 24000
lee pts1:1.710042,frame->pts:41041,tb:(1,/ 24000
lee pts1:1.751750,frame->pts:42042,tb:(1,/ 24000
lee pts1:1.793458,frame->pts:43043,tb:(1,/ 24000
lee pts1:1.835167,frame->pts:44044,tb:(1,/ 24000
lee pts1:1.876875,frame->pts:45045,tb:(1,/ 24000
lee pts1:1.918583,frame->pts:46046,tb:(1,/ 24000
lee pts1:1.960292,frame->pts:47047,tb:(1,/ 24000
lee pts1:2.002000,frame->pts:48048,tb:(1,/ 24000
lee pts1:2.043708,frame->pts:49049,tb:(1,/ 24000
lee pts1:2.085417,frame->pts:50050,tb:(1,/ 24000
lee pts1:2.168833,frame->pts:52052,tb:(1,/ 24000
|