ffmpeg的hevc slice多线程解码

本文详细探讨了ffmpeg在hevc解码过程中如何实现slice级别的多线程。通过`ff_thread_init`函数判断使用slice或frame并行,接着重点介绍了`ff_slice_thread_init`的流程,包括线程数量的确定和初始化过程。在slice级并行化中,`execute2`函数被`thread_execute2`调用,通过`avpriv_slicethread_execute`来协调工作线程。文章还补充了相关函数的源码细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ff_thread_init判断对slice并行或者frame并行进行初始化
int ff_thread_init(AVCodecContext *avctx)
71 {
72 validate_thread_parameters(avctx);
73
74 if (avctx->active_thread_type&FF_THREAD_SLICE)
75 return ff_slice_thread_init(avctx);
76 else if (avctx->active_thread_type&FF_THREAD_FRAME)
77 return ff_frame_thread_init(avctx);
78
79 return 0;
80 }

ff_slice_thread_init是帧级并行初始化
int ff_slice_thread_init(AVCodecContext *avctx)
130 {
131 SliceThreadContext *c;
132 int thread_count = avctx->thread_count;
133 static void (*mainfunc)(void *);
134
135 // We cannot do this in the encoder init as the threads are created before
136 if (av_codec_is_encoder(avctx->codec) &&
137 avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO &&
138 avctx->height > 2800)
139 thread_count = avctx->thread_count = 1;
140
141 if (!thread_count) {
142 int nb_cpus = av_cpu_count();
143 if (avctx->height)
144 nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);
145 // use number of cores + 1 as thread count if there is more than one
146 if (nb_cpus > 1)
147 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
148 else
149 thread_count = avctx->thread_count = 1;
150 }
151
152 if (thread_count <= 1) {
153 avctx->active_thread_type = 0;
154 re

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值