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;
}

本文介绍了如何在ffmpeg中启用Videotoolbox硬件加速,以及如何在stream_component_open和video_image_display方法中利用GPU解码并优化数据传输。尽管GPU解码降低了CPU使用率,但数据拷贝和格式转换仍占用一定CPU资源。作者计划进一步优化,减少CPU占用。

4167

被折叠的 条评论
为什么被折叠?



