打开微信,使用扫一扫进入页面后,点击右上角菜单,
点击“发送给朋友”或“分享到朋友圈”完成分享
先上代码
//根据FFMPEG的AVStream生成cnvideoDecCreateInfo
bool BuildDecInfo(AVStream* _stream, cnvideoDecCreateInfo& _info) { memset(&_info, 0, sizeof(_info)); cncodecType codec_; switch (_stream->codecpar->codec_id) { case AV_CODEC_ID_H264: codec_ = CNCODEC_H264; break; case AV_CODEC_ID_HEVC: codec_ = CNCODEC_HEVC; break; case AV_CODEC_ID_VP8: codec_ = CNCODEC_VP8; break; case AV_CODEC_ID_VP9: codec_ = CNCODEC_VP9; break; default: return false; } _info.codec = codec_; _info.userContext = this; _info.pixelFmt = CNCODEC_PIX_FMT_NV12; _info.instance = CNVIDEODEC_INSTANCE_AUTO; _info.allocType = CNCODEC_BUF_ALLOC_LIB; _info.height = _stream->codecpar->height; _info.width = _stream->codecpar->width; _info.bitDepthMinus8 = 0; _info.suggestedLibAllocBitStrmBufSize = 0; _info.inputBufNum = 8; _info.inputBuf = nullptr; _info.outputBufNum = 8; _info.outputBuf = nullptr; _info.progressive = 1; _info.deviceId = 0; return true; }
//创建
if (cnvideoDecCreate(&handle, DecodeCallback, &dec_info) != 0) { return false; }
//回调函数
int DecodeCallback(cncodecCbEventType _type, void* _instance, void* _data) { auto decoder_ = (Decoder*)_instance; switch (_type) { case CNCODEC_CB_EVENT_NEW_ : decoder_->Enqueue((cnvideoDecOutput*)_data); break; case CNCODEC_CB_EVENT_SEQUENCE: decoder_->seq_info = *(cnvideoDecSequenceInfo*)_data; cnvideoDecStart(decoder_->handle, &decoder_->dec_info); break; default: break; } return 0; }
//解码 int Decode(AVPacket* _packet) { cnvideoDecInput input_ = {}; input_.streamBuf = _packet->data; input_.streamLength = _packet->size; input_.flags |= CNVIDEODEC_FLAG_END_OF_ ; if (_packet->size == 0) { return 0; } auto ret_ = cnvideoDecFeedData(handle, &input_, 10000); if (ret_ == -CNCODEC_TIMEOUT) { cnvideoDecAbort(handle); return -1; } else if (ret_ < 0) { return -1; } return 1; }
都是AV_CODEC_ID_H264,
使用这个测试地址可以正常解码:
rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4
使用这个测试地址回调函数一直没有被执行:
rtmp://ns8.indexforce.com/home/mystream
请教各位,这是什么原因?
热门帖子
精华帖子