FFmpeg XAVC实现/x264实现 应用设置接口参数
(相关资料图)
思路
上一篇文章提到了XAVC的一些背景,以及非每帧固定码率的实现方法。然而如果要实现XAVC中的CBG模式(Constrained Bytes per GOP)就必须修改x264源码固定每帧码率。
x264中对松下 AVC Intra Class 有支持,AVC Intra Class 100/200是定义在HD下的与XAVC类似的标准。因此可以通过扩展这部分的代码功能来实现4K XAVC Intra Class 300/480。
应用设置接口参数 avcintra-class=300 avcintra-flavor=sony进行编码标准的设置。
代码
diff --git a/encoder/encoder.c b/encoder/encoder.cindex 074c4a5c..5fb84fcd 100644--- a/encoder/encoder.c+++ b/encoder/encoder.c@@ -678,9 +678,13 @@ static int validate_parameters( x264_t *h, int b_open ) return -1; } - int type = h->param.i_avcintra_class == 200 ? 2 :+ int type = h->param.i_avcintra_class == 480 ? 4 :+ h->param.i_avcintra_class == 300 ? 3 :+ h->param.i_avcintra_class == 200 ? 2 : h->param.i_avcintra_class == 100 ? 1 : h->param.i_avcintra_class == 50 ? 0 : -1;+ int xavc = (h->param.i_avcintra_flavor == X264_AVCINTRA_FLAVOR_SONY);+ if( type < 0 ) { x264_log( h, X264_LOG_ERROR, "Invalid AVC-Intra class\n" );@@ -733,21 +737,101 @@ static int validate_parameters( x264_t *h, int b_open ) { 24000, 1001, 0, 7444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}} }; - int res = -1;- if( i_csp >= X264_CSP_I420 && i_csp < X264_CSP_I422 && !type )+ /* [50/100/200/300/480][720p/1440x1080/1080p/2048x1080/4K][fps] */+ static const struct {- if( h->param.i_width == 1440 && h->param.i_height == 1080 ) res = 1;- else if( h->param.i_width == 960 && h->param.i_height == 720 ) res = 0;- }- else if( i_csp >= X264_CSP_I422 && i_csp < X264_CSP_I444 && type )+ uint16_t fps_num;+ uint16_t fps_den;+ uint8_t interlaced;+ uint16_t frame_size;+ const uint8_t *cqm_4ic;+ const uint8_t *cqm_8iy;+ } xavcintra_lut[5][5][7] = {- if( h->param.i_width == 1920 && h->param.i_height == 1080 ) res = 1;- else if( h->param.i_width == 1280 && h->param.i_height == 720 ) res = 0;- }- else+ {{{}},+ {{ 50, 1, 1, 2120, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },+ { 60000, 1001, 1, 1744, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },+ { 24000, 1001, 0, 1744, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },+ { 25, 1, 0, 2120, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },+ { 30000, 1001, 0, 1744, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy }}},+ {{{ 60000, 1001, 0, 1804, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },+ { 50, 1, 0, 2180, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy }},+ {{}},+ {{ 50, 1, 1, 4368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },+ { 60000, 1001, 1, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },+ { 24000, 1001, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 25, 1, 0, 4368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 30000, 1001, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 50, 1, 0, 4368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 60000, 1001, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }},+ {{ 24000, 1001, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 24, 1, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 25, 1, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 30000, 1001, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 50, 1, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 60000, 1001, 0, 3616, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},+ {{{}},+ {{}},+ {{ 50, 1, 1, 8864, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },+ { 60000, 1001, 1, 7368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },+ { 24000, 1001, 0, 7368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 25, 1, 0, 8864, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 30000, 1001, 0, 7368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 50, 1, 0, 8864, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 60000, 1001, 0, 7368, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},+ {{{}},+ {{}},+ {{}},+ {{}},+ {{ 24000, 1001, 0, 9768, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 25, 1, 0, 9768, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 30000, 1001, 0, 9768, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 50, 1, 0, 9768, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 60000, 1001, 0, 9768, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},+ {{{}},+ {{}},+ {{}},+ {{}},+ {{ 24000, 1001, 0,15624, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 25, 1, 0,15624, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 30000, 1001, 0,15624, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 50, 1, 0,15624, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },+ { 60000, 1001, 0,15624, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},+ };++ int res = -1;+ if(xavc) {- x264_log( h, X264_LOG_ERROR, "Invalid colorspace for AVC-Intra %d\n", h->param.i_avcintra_class );- return -1;+ if( i_csp >= X264_CSP_I422 && i_csp < X264_CSP_I444 && type )+ {+ if( h->param.i_width == 1280 && h->param.i_height == 720 ) res = 0;+ else if(h->param.i_width == 1440 && h->param.i_height == 1080 ) res = 1;+ else if(h->param.i_width == 1920 && h->param.i_height == 1080 ) res = 2;+ else if(h->param.i_width == 2048 && h->param.i_height == 1080 ) res = 3;+ else if(h->param.i_width == 3840 && h->param.i_height == 2160 ) res = 4;+ else if(h->param.i_width == 4096 && h->param.i_height == 2160 ) res = 4;+ }+ else+ {+ x264_log( h, X264_LOG_ERROR, "Invalid colorspace for XAVC-Intra %d\n", h->param.i_avcintra_class );+ return -1;+ }+ } else {+ if( i_csp >= X264_CSP_I420 && i_csp < X264_CSP_I422 && !type )+ {+ if( h->param.i_width == 1440 && h->param.i_height == 1080 ) res = 1;+ else if( h->param.i_width == 960 && h->param.i_height == 720 ) res = 0;+ }+ else if( i_csp >= X264_CSP_I422 && i_csp < X264_CSP_I444 && type )+ {+ if( h->param.i_width == 1920 && h->param.i_height == 1080 ) res = 1;+ else if( h->param.i_width == 1280 && h->param.i_height == 720 ) res = 0;+ }+ else+ {+ x264_log( h, X264_LOG_ERROR, "Invalid colorspace for AVC-Intra %d\n", h->param.i_avcintra_class );+ return -1;+ } } if( res < 0 )@@ -774,11 +858,20 @@ static int validate_parameters( x264_t *h, int b_open ) x264_reduce_fraction( &fps_num, &fps_den ); for( i = 0; i < 7; i++ ) {- if( avcintra_lut[type][res][i].fps_num == fps_num &&- avcintra_lut[type][res][i].fps_den == fps_den &&- avcintra_lut[type][res][i].interlaced == PARAM_INTERLACED )- {- break;+ if (xavc) {+ if( xavcintra_lut[type][res][i].fps_num == fps_num &&+ xavcintra_lut[type][res][i].fps_den == fps_den &&+ xavcintra_lut[type][res][i].interlaced == PARAM_INTERLACED )+ {+ break;+ }+ } else {+ if( avcintra_lut[type][res][i].fps_num == fps_num &&+ avcintra_lut[type][res][i].fps_den == fps_den &&+ avcintra_lut[type][res][i].interlaced == PARAM_INTERLACED )+ {+ break;+ } } } if( i == 7 )@@ -806,7 +899,7 @@ static int validate_parameters( x264_t *h, int b_open ) h->param.analyse.intra = X264_ANALYSE_I8x8; h->param.analyse.i_chroma_qp_offset = res && type ? 3 : 4; h->param.b_cabac = !type;- h->param.rc.i_vbv_buffer_size = avcintra_lut[type][res][i].frame_size;+ h->param.rc.i_vbv_buffer_size = xavc ? xavcintra_lut[type][res][i].frame_size : avcintra_lut[type][res][i].frame_size; h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate = h->param.rc.i_vbv_buffer_size * fps_num / fps_den; h->param.rc.i_rc_method = X264_RC_ABR;@@ -814,8 +907,13 @@ static int validate_parameters( x264_t *h, int b_open ) h->param.rc.b_filler = 1; h->param.i_cqm_preset = X264_CQM_CUSTOM; memcpy( h->param.cqm_4iy, x264_cqm_jvt4i, sizeof(h->param.cqm_4iy) );- memcpy( h->param.cqm_4ic, avcintra_lut[type][res][i].cqm_4ic, sizeof(h->param.cqm_4ic) );- memcpy( h->param.cqm_8iy, avcintra_lut[type][res][i].cqm_8iy, sizeof(h->param.cqm_8iy) );+ if (xavc) {+ memcpy( h->param.cqm_4ic, xavcintra_lut[type][res][i].cqm_4ic, sizeof(h->param.cqm_4ic) );+ memcpy( h->param.cqm_8iy, xavcintra_lut[type][res][i].cqm_8iy, sizeof(h->param.cqm_8iy) );+ } else {+ memcpy( h->param.cqm_4ic, avcintra_lut[type][res][i].cqm_4ic, sizeof(h->param.cqm_4ic) );+ memcpy( h->param.cqm_8iy, avcintra_lut[type][res][i].cqm_8iy, sizeof(h->param.cqm_8iy) );+ } /* Sony XAVC flavor much more simple */ if( h->param.i_avcintra_flavor == X264_AVCINTRA_FLAVOR_SONY )
运行
./ffmpeg -i "/home/lyh/4K/Customer/Sobey/2018080927test_video/10M_SR012CA3.mp4" -r 50 -pix_fmt yuv422p10le -c:v libx264 -avcintra-class 300 -x264opts avcintra-class=300 -x264opts avcintra-flavor=sony 1.mxf
标签:
相关推荐:
最新新闻:
- 毕业生想做猎头前景如何?猎头前景分析_全球快讯
- 数藏行业首现“傍名牌” 百度搜“十八数藏”首页第一条是ibox广告
- Linux下chmod 777 修改权限怎么设置?设置方法
- oki打印机设置参数 OKI帮你找到最适合办公打印机
- 做火车随机一坐是自己位置的概率为多少?必须掌握的疯子找座问题
- 电脑ip地址怎么查看?查看ip地址最简单方法
- 手机投屏到电视上怎么操作?手机投屏到电视的方法
- 怎样清除手机病毒的教程?手机中病毒的解决办法
- 剪贴板在哪里找?Windows 10系统剪切板位置
- 在哪看电脑配置是什么?查看电脑配置的实用方法
- 微软msvcrtd.dll文件修复教程(附下载)_焦点要闻
- u盘文件夹exe病毒解决方法有哪些?清除exe病毒文件的技巧
- 两台电脑如何共享文件?文件共享的方法步骤图解
- 【全球快播报】谁说上网本已经死了?华硕正式推出基于MeeGo的超薄本
- “3.6亿”事件引发国人持续热议 事情的背后究竟有何隐情?_每日视点
- 【干货】CoreTime框架中的时间类型
- 关于QQ的相关代码收集整理 WEB版在线聊天技巧-天天热点
- tf卡写保护无法格式化怎么办?u盘被写保护最简单解除方法
- 版主联盟是什么?版主联盟推广法 天天热消息
- 全球今头条!2019年笔记本电脑性价比排行榜 前10名都有哪些?
- FFmpeg XAVC实现/x264实现 应用设置接口参数
- 安卓手机如何刷机?安卓手机刷机教程
- 世界看热讯:yy电影频道是多少?如何使用yy看在线电影?
- 网页自动刷新怎么设置?网页实现自动刷新步骤
- 车载导航品牌哪个好?汽车导航品牌推荐
- 索泰显卡怎么样?索泰RTX 4090 AMP EXTREME AIRO显卡评测
- 华为MateBook14怎么样?华为MateBook14值不值得买?|每日速递
- 无法连接到iTunes Store怎么办?无法连接到iTunes Store的解决方法
- 如何快速输入特殊符号?特殊符号怎么打出来?
- 热消息:客户呼叫中心系统结构及应用服务器
- 电脑温度多少度正常?看看你的电脑温度多少?
- 计算机指纹识别的原理是什么?指纹识别原理和过程_天天快播
- 显卡检测工具有哪些?显卡用什么软件去检测?
- 不干胶打印机哪种好?不干胶打印机推荐
- 当前快报:如何使用手机可视电话?可视电话使用方法
- win7网络连接不可用是怎么回事?电脑连接不可用解决方法
- 手机地图哪个好?老虎地图详情介绍
- visio序列号有哪些?visio序列号大全
- 内存条价格上涨的原因是什么?内存条价格上涨的原因介绍
- 为什么百度云网盘登录不了?网页版、pc版 都登陆不进去的解决方法
- 手机电子签名怎么弄?电子签名制作步骤
- 网页制作入门级软件推荐——FrontPage-焦点快看
- epson630k打印机怎么换色带?针式打印机色带安装方法
- 非负数正则怎么表示?非负数正则表达式
- 今日看点:MIUI是什么?MIUI的主要特色
- 天天短讯!RFC4144中的Abstract 你了解多少?
- 天天新动态:html代码怎么在空间应用?HTML制帖空间的代码
- 环球新消息丨热管换热器工作原理是什么?热管换热器工作原理及特点介绍
- 擦掉照片上的衣服app 去掉照片上衣服操作步骤
- 花样直播是什么?花样直播的详细介绍|今日看点
- qq炫舞测试服务器怎么维护?QQ炫舞体验服新界面安装操作方法
- 视讯!单变量积分的知识可参考 二重积分的意义
- 计算机指纹识别的原理是什么?指纹识别原理和过程_天天快播
- 环球讯息:扇形计算公式是怎么得来的?扇形计算公式介绍
- 宝塔面板教程 基于云服务器搭建学生机最全详解
- 全球观焦点:CSDN社区简介: 全球最大的IT技术社区 日访问用户数达100万
- 网络小黑揭秘系列之黑产江湖黑吃黑—厨房切菜之利器
- 金山打字通五笔怎么使用?金山打字通五笔介绍及讲解
- 安卓手机如何刷机?安卓手机刷机教程
- 网页自动刷新怎么设置?网页实现自动刷新步骤
- 索泰显卡怎么样?索泰RTX 4090 AMP EXTREME AIRO显卡评测
- 如何快速输入特殊符号?特殊符号怎么打出来?
- 电脑温度多少度正常?看看你的电脑温度多少?
- 显卡检测工具有哪些?显卡用什么软件去检测?
- win7网络连接不可用是怎么回事?电脑连接不可用解决方法
- 内存条价格上涨的原因是什么?内存条价格上涨的原因介绍
- 手机电子签名怎么弄?电子签名制作步骤
- 专家狠批算法推荐 看短视频频率影响未成年人价值取向
- Steam年度游戏数据回顾 今年玩了多少款游戏?
- epson630k打印机怎么换色带?针式打印机色带安装方法
- 擦掉照片上的衣服app 去掉照片上衣服操作步骤
- 讯息:《巫师:血源》翻车 成烂番茄观众评分最差网飞剧集
- 《蜡笔小新 我与博士的暑假》Steam国区售价永降 全区最低
- MAGES.发表2022财年财报 共损失6.13亿日元
- Falcom公开《伊苏10》新概念图 游戏将于2023年发售