ffplay支持mac/iOS硬解码实践

news/2024/9/24 12:20:38/

1. ffmpeg编译开启videotoolbox的支持。

./configure --enable-videotoolbox --enable-hwaccels

2. stream_component_open方法中开启硬件解码器。

int FSPlay::stream_component_open(VideoState *is, int stream_index)
{//...codec = avcodec_find_decoder(avctx->codec_id);if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {//通过videotoolbox找到对应的deviceType。enum AVHWDeviceType type = av_hwdevice_find_type_by_name("videotoolbox");//遍历编码器中的HWConfig,找到deviceType为videotoolbox的像素格式,保存到hw_pix_fmt中for (int i = 0;; i++) {const AVCodecHWConfig *config = avcodec_get_hw_config(codec, i);if (!config) {return -1;}if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&config->device_type == type) {hw_pix_fmt = config->pix_fmt;break;}}//设置编码器上下文avctx的get_format为get_hw_formatavctx->get_format = get_hw_format;//初始化硬件解码器ctx->hw_device_ctxif (hw_decoder_init(avctx, type) < 0)return -1;}switch(avctx->codec_type){case AVMEDIA_TYPE_AUDIO   : is->last_audio_stream    = stream_index; forced_codec_name =    audio_codec_name; break;case AVMEDIA_TYPE_SUBTITLE: is->last_subtitle_stream = stream_index; forced_codec_name = subtitle_codec_name; break;case AVMEDIA_TYPE_VIDEO   : is->last_video_stream    = stream_index; forced_codec_name =    video_codec_name; break;}//...
}

3. video_image_display方法中奖GPU data转换到CPU data,然后传入sws_getContext统一转换为RGB24格式传入OpenGLES显示。

void FSPlay::video_image_display(VideoState *is)
{//...AVFrame *tmpFrame = av_frame_alloc();if (vp->frame->format == hw_pix_fmt) {/* retrieve data from GPU to CPU */if ((av_hwframe_transfer_data(tmpFrame, vp->frame, 0)) < 0) {fprintf(stderr, "Error transferring the data to system memory\n");}} elsetmpFrame = vp->frame;//sws_getContext需要传入原像素格式(enum AVPixelFormat)tmpFrame->formatswsContext = sws_getContext(vp->width, vp->height, (enum AVPixelFormat)tmpFrame->format, vp->width, vp->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL);//...
}

4. 可以看到虽然硬解码是在GPU里进行解码,会降低CPU使用率,但是最终显示的时候还需要调用av_hwframe_transfer_data方法将数据拷贝到CPU中(NV12格式),拷贝后它的格式在转换为RGB24时也需要占用CPU资源,所以对CPU资源占用率的降低并不大,如果能将GPU数据直接传递到OpenGLES中显示应该可以降低CPU使用率。

5,后续有时间会继续优化,将av_hwframe_transfer_data改为av_hwframe_map,能优化1/3的CPU时间,然后不在CPU中做NV12到RGB24的转换,而是通过OpenGLES在片源着色器中进行转换,预计会大大降低CPU占用率。参考文章


http://www.ppmy.cn/news/1444836.html

相关文章

k8s负载均衡

在Kubernetes中&#xff0c;负载均衡通常由服务对象来实现。你可以使用Service资源来暴露一个容器&#xff08;或一组容器&#xff09;&#xff0c;并且提供负载均衡功能。 以下是一个简单的服务定义示例&#xff0c;它使用了Cluster内部负载均衡器实现&#xff08;也就是说&a…

Hadoop 伪分布式安装

Hadoop 伪分布式安装 准备 环境选择 系统&#xff1a; Ubuntu Desktop 2204JDK&#xff1a; 8Hadoop &#xff1a; 3.3.6 JDK 8 下载地址 https://mirrors.tuna.tsinghua.edu.cn/Adoptium/8/jdk/x64/linux/Hadoop 3.3.6 下载地址 https://mirrors.tuna.tsinghua.edu.cn/a…

visual studio code安装Clicknium

visual studio code下载安装 Download Visual Studio Code - Mac, Linux, Windows 安装python extend&#xff0c;需要把科学上网关了 clicknium 获取插件名 clicknium 录制教程 https://blog.51cto.com/u_16213624/7007362 实战教程&#xff1a; Python 自动化神器 Click…

hive使用hplsql进行etl或其它数据加工

参照 https://cwiki.apache.org/confluence/pages/viewpage.action?pageId59690156 http://www.hplsql.org/doc Hive HPL/SQL&#xff0c;即Hive Hybrid Procedural SQL一个开源工具&#xff0c;它为hive实现了过程性的SQL功能&#xff0c;类似Oracle的PLSQL。从hive 2.0.0开…

FPGA之zynq_DDR(1)

学习一下关于DDR的知识和vivado操作吧。 用PS控制DDR内存读写 【ZYNQ-7000开发之六】使用PS控制DDR3的读写_xil_in32读取ddr数据-CSDN博客 在新建block design时&#xff0c;选择DDR&#xff0c;选择UART&#xff08;为什么要用uart&#xff1f;&#xff09; 找到DDR的地址&a…

CSS 如何在长方形中间加一条横线

1、html <div class"arrow"><img src"~/assets/images/reportsModule/&#xff1e;&#xff1e;&#xff1e;.png" alt"" srcset"" class"yo" style"transform: rotateY(180deg);"></div> 代…

清理 Conda 和 pip 缓存

清理 Conda 缓存 查看 Conda 缓存的使用情况 conda clean --dry-run --all 删除不再使用的包和缓存 conda clean --all 清理 pip 缓存 Python缓存文件的默认位置&#xff1a; Windows 10&#xff1a;C:\Users\username\AppData\Local\pip\Cache macOS&#xff1a;/Users/…

Excel 批量创建sheet页

参考资料 最巧妙的Excel批量创建工作表方法 一. 需求 ⏹有如下模板&#xff0c;现想根据提供的姓名&#xff0c;批量创建sheet页&#xff0c;要求每个sheet页拥有相同的模板 二. 通过透视表&#xff0c;批量创建sheet页面 ⏹如下图所示的步骤&#xff0c;创建透视表后&#…