cocos 集成ffmpeg JS调用C++ 代码 引发了异常: 读取访问权限冲突。 this->pFormatCtx 是 nullptr。

那位大佬 cocos 集成ffmpeg ,JS 第二次调用C++ 对象里面的属性 引发了异常: 读取访问权限冲突。 this->pFormatCtx 是 nullptr。

WinPlayer是c++里面的类,通过JSB自动绑定后,在win平台JS可以访问
JS端:
@property
_player: any = null

start() {
this._player = WinPlayer.create(path,1920,1080);
this._player.playVideo();
}

C++端
WinPlayer* WinPlayer::create(const char* path, int width, int height)
{
WinPlayer* video = new (std::nothrow)WinPlayer();
if (video&&video->init(path, width, height)) {
//video->autorelease();
return video;
}
delete video;
video = nullptr;
return nullptr;
}
bool WinPlayer::init(const char* path, int width, int height)
{
//打开视频
m_filePath = cocos2d::FileUtils::getInstance()->fullPathForFilename(path);
if (avformat_open_input(&pFormatCtx, m_filePath.c_str(), NULL, NULL) != 0) {
return false;
}
//获取视频流
videoStream = -1;
for (int i = 0; i < pFormatCtx->nb_streams; i++) {
if (videoStream == -1 && pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
videoStream = i;
}
}
pCodecCtx = pFormatCtx->streams[videoStream]->codec;
// 第一次调用pFormatCtx,这里访问不报错
AVRational timeBase = pFormatCtx->streams[videoStream]->time_base;

}

void WinPlayer::playVideo()
{
//第二次访问pFormatCtx属性 引发了异常: 读取访问权限冲突,调试看了pFormatCtx变量值是0x00000000
AVRational timeBase = pFormatCtx->streams[videoStream]->time_base;
int64_t targetFrame = (int64_t)((double)timeBase.den / timeBase.num * 0);
avformat_seek_file(pFormatCtx, videoStream, targetFrame, targetFrame, targetFrame, AVSEEK_FLAG_FRAME);
avcodec_flush_buffers(pCodecCtx);
}

问题已经找到,打扰了。。。