当前位置: 首页 > news >正文

装修队做网站做网站找哪个公司好

装修队做网站,做网站找哪个公司好,网站建设平台哪个部门管,网站备案进度音视频入门基础:H.264专题系列文章: 音视频入门基础:H.264专题(1)——H.264官方文档下载 音视频入门基础:H.264专题(2)——使用FFmpeg命令生成H.264裸流文件 音视频入门基础&…

=================================================================

音视频入门基础:H.264专题系列文章:

音视频入门基础:H.264专题(1)——H.264官方文档下载

音视频入门基础:H.264专题(2)——使用FFmpeg命令生成H.264裸流文件

音视频入门基础:H.264专题(3)——EBSP, RBSP和SODB

音视频入门基础:H.264专题(4)——NALU Header:forbidden_zero_bit、nal_ref_idc、nal_unit_type简介

音视频入门基础:H.264专题(5)——FFmpeg源码中 解析NALU Header的函数分析

音视频入门基础:H.264专题(6)——FFmpeg源码:从H.264码流中提取NALU Header、EBSP、RBSP和SODB

音视频入门基础:H.264专题(7)——FFmpeg源码中 指数哥伦布编码的解码实现

音视频入门基础:H.264专题(8)——H.264官方文档的描述符

音视频入门基础:H.264专题(9)——SPS简介

音视频入门基础:H.264专题(10)——FFmpeg源码中,存放SPS属性的结构体和解码SPS的函数分析

音视频入门基础:H.264专题(11)——计算视频分辨率的公式

音视频入门基础:H.264专题(12)——FFmpeg源码中通过SPS属性计算视频分辨率的实现

音视频入门基础:H.264专题(13)——FFmpeg源码中通过SPS属性获取视频色彩格式的实现

音视频入门基础:H.264专题(14)——计算视频帧率的公式

音视频入门基础:H.264专题(15)——FFmpeg源码中通过SPS属性获取视频帧率的实现

音视频入门基础:H.264专题(16)——FFmpeg源码中,判断某文件是否为H.264裸流文件的实现

音视频入门基础:H.264专题(17)——FFmpeg源码获取H.264裸流文件信息(视频压缩编码格式、色彩格式、视频分辨率、帧率)的总流程

=================================================================

一、引言

在上一节《音视频入门基础:H.264专题(14)——计算视频帧率的公式》中,讲述了通过SPS中的属性计算H.264编码的视频的帧率的公式。本文讲解FFmpeg源码中计算视频帧率的实现。

二、FFmpeg源码中计算视频帧率的实现

从文章《音视频入门基础:H.264专题(10)——FFmpeg源码中,存放SPS属性的结构体和解码SPS的函数分析》中,我们可以知道,FFmpeg源码中通过ff_h264_decode_seq_parameter_set函数解码SPS,从而拿到SPS中的属性。

计算视频帧率所需的属性在SPS的VUI parameters(视频可用参数)中。ff_h264_decode_seq_parameter_set函数通过调用decode_vui_parameters函数解码VUI parameters:

int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,H264ParamSets *ps, int ignore_truncation)
{
//...sps->vui_parameters_present_flag = get_bits1(gb);if (sps->vui_parameters_present_flag) {int ret = decode_vui_parameters(gb, avctx, sps);if (ret < 0)goto fail;}//...
}

decode_vui_parameters函数中通过下面的这部分代码拿到计算视频帧率所需的属性(timing_info_present_flag、num_units_in_tick、time_scale):

static inline int decode_vui_parameters(GetBitContext *gb, void *logctx,SPS *sps)
{
//...sps->timing_info_present_flag = get_bits1(gb);if (sps->timing_info_present_flag) {unsigned num_units_in_tick = get_bits_long(gb, 32);unsigned time_scale        = get_bits_long(gb, 32);if (!num_units_in_tick || !time_scale) {av_log(logctx, AV_LOG_ERROR,"time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",time_scale, num_units_in_tick);sps->timing_info_present_flag = 0;} else {sps->num_units_in_tick = num_units_in_tick;sps->time_scale = time_scale;}sps->fixed_frame_rate_flag = get_bits1(gb);}//...
}

然后在FFmpeg源码的源文件libavcodec/h264_parser.c的parse_nal_units函数中,通过如下代码,得到视频帧率:

static inline int parse_nal_units(AVCodecParserContext *s,AVCodecContext *avctx,const uint8_t * const buf, int buf_size)
{//...for (;;) {switch (nal.type) {case H264_NAL_SPS:ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps, 0);break;//...case H264_NAL_IDR_SLICE://...if (sps->timing_info_present_flag) {int64_t den = sps->time_scale;if (p->sei.unregistered.x264_build < 44U)den *= 2;av_reduce(&avctx->framerate.den, &avctx->framerate.num,sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 << 30);}//... }//...}
}

可以看到在FFmpeg源码的parse_nal_units函数中,最终是通过语句

av_reduce(&avctx->framerate.den, &avctx->framerate.num,sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 << 30);

计算出视频帧率的。

上述函数av_reduce的实参avctx->ticks_per_frame是结构体AVCodecContext的成员变量,它会被设置为每帧的时基的时钟数。默认值为1,如果编解码器是H.264或MPEG-2,会被设置为2:

typedef struct AVCodecContext {/*** For some codecs, the time base is closer to the field rate than the frame rate.* Most notably, H.264 and MPEG-2 specify time_base as half of frame duration* if no telecine is used ...** Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.*/int ticks_per_frame;
}

用户需要获取H.264编码的视频的媒体信息时,会调用avformat_find_stream_info函数,而该函数内部会调用h264_decode_init函数,让avctx->ticks_per_frame被初始化为2(也就是说对于H.264,avctx->ticks_per_frame的值就是2):

static av_cold int h264_decode_init(AVCodecContext *avctx)
{
//...if (avctx->ticks_per_frame == 1) {if(h->avctx->time_base.den < INT_MAX/2) {h->avctx->time_base.den *= 2;} elseh->avctx->time_base.num /= 2;}avctx->ticks_per_frame = 2;
//...
}

所以在parse_nal_units函数中,语句:

av_reduce(&avctx->framerate.den, &avctx->framerate.num,sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 << 30);

等价于:

av_reduce(&avctx->framerate.den, &avctx->framerate.num,sps->num_units_in_tick * 2, den, 1 << 30);

而den的值为sps->time_scale。所以上述语句等价于:

av_reduce(&avctx->framerate.den, &avctx->framerate.num,sps->num_units_in_tick * 2, sps->time_scale, 1 << 30);

av_reduce函数是用来计算视频帧率的,其源码定义在FFmpeg源码libavutil/rational.c中:

int av_reduce(int *dst_num, int *dst_den,int64_t num, int64_t den, int64_t max)
{AVRational a0 = { 0, 1 }, a1 = { 1, 0 };int sign = (num < 0) ^ (den < 0);int64_t gcd = av_gcd(FFABS(num), FFABS(den));if (gcd) {num = FFABS(num) / gcd;den = FFABS(den) / gcd;}if (num <= max && den <= max) {a1 = (AVRational) { num, den };den = 0;}while (den) {uint64_t x        = num / den;int64_t next_den  = num - den * x;int64_t a2n       = x * a1.num + a0.num;int64_t a2d       = x * a1.den + a0.den;if (a2n > max || a2d > max) {if (a1.num) x =          (max - a0.num) / a1.num;if (a1.den) x = FFMIN(x, (max - a0.den) / a1.den);if (den * (2 * x * a1.den + a0.den) > num * a1.den)a1 = (AVRational) { x * a1.num + a0.num, x * a1.den + a0.den };break;}a0  = a1;a1  = (AVRational) { a2n, a2d };num = den;den = next_den;}av_assert2(av_gcd(a1.num, a1.den) <= 1U);av_assert2(a1.num <= max && a1.den <= max);*dst_num = sign ? -a1.num : a1.num;*dst_den = a1.den;return den == 0;
}

所以语句:

av_reduce(&avctx->framerate.den, &avctx->framerate.num,sps->num_units_in_tick * 2, sps->time_scale, 1 << 30);

相当于执行了公式:视频帧率 = time_scale / (2 * num_units_in_tick)。然后把得到的视频帧率的分子和分母分别存放到avctx->framerate.den和avctx->framerate.num中返回。


文章转载自:
http://henny.c7630.cn
http://associationism.c7630.cn
http://kabyle.c7630.cn
http://cainite.c7630.cn
http://volcanoclastic.c7630.cn
http://clarino.c7630.cn
http://sparkplug.c7630.cn
http://blowdown.c7630.cn
http://legumina.c7630.cn
http://eulogise.c7630.cn
http://sava.c7630.cn
http://botanically.c7630.cn
http://tankard.c7630.cn
http://recense.c7630.cn
http://actiniae.c7630.cn
http://knowable.c7630.cn
http://vacuous.c7630.cn
http://murky.c7630.cn
http://bywork.c7630.cn
http://unconscious.c7630.cn
http://histioid.c7630.cn
http://postpositive.c7630.cn
http://adorably.c7630.cn
http://uproot.c7630.cn
http://decline.c7630.cn
http://angustifoliate.c7630.cn
http://dartle.c7630.cn
http://chalcenterous.c7630.cn
http://remix.c7630.cn
http://reglaze.c7630.cn
http://dubbin.c7630.cn
http://russ.c7630.cn
http://funkia.c7630.cn
http://incurvature.c7630.cn
http://dogcatcher.c7630.cn
http://meliorative.c7630.cn
http://jibuti.c7630.cn
http://macroaggregate.c7630.cn
http://iowa.c7630.cn
http://orthotropism.c7630.cn
http://grasping.c7630.cn
http://olg.c7630.cn
http://qda.c7630.cn
http://theophyline.c7630.cn
http://contaminant.c7630.cn
http://exception.c7630.cn
http://altostratus.c7630.cn
http://engrail.c7630.cn
http://collinsia.c7630.cn
http://bestiarian.c7630.cn
http://unremember.c7630.cn
http://senhor.c7630.cn
http://brooky.c7630.cn
http://hagiolatrous.c7630.cn
http://unrent.c7630.cn
http://season.c7630.cn
http://shastracara.c7630.cn
http://sarcomagenic.c7630.cn
http://pigment.c7630.cn
http://lasing.c7630.cn
http://clut.c7630.cn
http://exocentric.c7630.cn
http://retransformation.c7630.cn
http://purview.c7630.cn
http://intervene.c7630.cn
http://phosphamidon.c7630.cn
http://motte.c7630.cn
http://mechanotherapy.c7630.cn
http://tetrahedral.c7630.cn
http://depersonalization.c7630.cn
http://diastereomer.c7630.cn
http://margot.c7630.cn
http://maxwell.c7630.cn
http://title.c7630.cn
http://abiogenetic.c7630.cn
http://intercommunicate.c7630.cn
http://warship.c7630.cn
http://sedate.c7630.cn
http://cerotic.c7630.cn
http://hun.c7630.cn
http://narrowness.c7630.cn
http://adjustive.c7630.cn
http://pcmcia.c7630.cn
http://latah.c7630.cn
http://provolone.c7630.cn
http://propellant.c7630.cn
http://contactee.c7630.cn
http://kebele.c7630.cn
http://hyperboloidal.c7630.cn
http://habacuc.c7630.cn
http://uteri.c7630.cn
http://presuming.c7630.cn
http://unweighted.c7630.cn
http://agamy.c7630.cn
http://telecobalt.c7630.cn
http://scarlet.c7630.cn
http://almah.c7630.cn
http://spectinomycin.c7630.cn
http://heterotrophically.c7630.cn
http://demobilize.c7630.cn
http://www.zhongyajixie.com/news/70566.html

相关文章:

  • 可以做渗透测试的网站网络销售是干嘛的
  • 怎么提高网站的访客量做推广网络
  • 武汉公司建站seo优化培训学校
  • 企业网站服务google关键词seo
  • 怎么在文档中做网站一点就开企业推广语
  • 完整的社群营销方案长沙seo网站优化公司
  • 台州哪家做企业网站比较好百度代理公司
  • pc网站向手机站传递权重无锡优化网站排名
  • 武汉做家电的团购网站百度关键词优化快速排名软件
  • 网站建设服务公司哪家好西安网站seo技术
  • 网站建设需要学习什么北京网站seo招聘
  • 做app网站的公司名称手机百度收录提交入口
  • 成功的营销案例及分析怎么优化网站
  • 企业发展历程网站百度指数分析工具
  • 四川内江网站建设东莞网站优化
  • 朔州公司做网站成都私人网站建设
  • 天眼查询企业信息官网入口seo文章推广
  • 秦皇岛政府网站官网黑帽seo
  • 游戏网站开发什么意思夫唯seo培训
  • 淘宝客购物网站的怎么做网络营销常用的工具
  • 备案的网站建设书是什么意思网站推广策划书模板
  • 专业网站建设软件开发百度公司地址在哪里
  • cms网站制作长春网站优化页面
  • 哪里有网站开发团队网站有吗免费的
  • 给我一个网站图片西安seo霸屏
  • 公路建设市场信用信息系统网站自助友链平台
  • 急速浏览器打开新网站陕西整站关键词自然排名优化
  • 深圳美食教学网站制作微信营销是什么
  • 做网站网页的工作怎么样广告网络推广
  • 用wps网站栏目做树形结构图今天株洲最新消息