這是由於處理的機器性能低,導致播放流的速度大於解碼速度,
怎麼解決這種問題呢,就是提高解碼速度,採取的就是增加解碼的線程,
參考文章
FFmpeg 解碼 avcodec_find_decoder AVCodecContext
FFmpeg(8)-打開音視頻解碼器,配置解碼器上下文(avcodec_find_decoder()、avcodec_alloc_context3())
具體來說
int avcodec_open2(AVCodecContext *avctx, const AVCodec
*codec, AVDictionary **options) 打開 options動態設置 多線程解碼設置
• /libavcodec/options_table.h
• int thread_count CPU數量設置
• time_base 時間基數
中可以設置CPU數量,那麼應該怎麼做呢
設置調用的CPU線程數量
// 註冊解碼器
avcodec_register_all();
AVCodec *vc = avcodec_find_decoder(ic->streams[videoStream]->codecpar->codec_id); // 軟解
// vc = avcodec_find_decoder_by_name("h264_mediacodec"); // 硬解
if (!vc) {
LOGE("avcodec_find_decoder[videoStream] failure");
return env->NewStringUTF(hello.c_str());
}
// 配置解碼器
AVCodecContext *vct = avcodec_alloc_context3(vc);
avcodec_parameters_to_context(vct, ic->streams[videoStream]->codecpar);
vct->thread_count = 1;//設置CPU線程數量
// 打開解碼器
int re = avcodec_open2(vct, vc, 0);
if (re != 0) {
LOGE("avcodec_open2 failure");
return env->NewStringUTF(hello.c_str());
}