nyanmisaka / ffmpeg-rockchip

FFmpeg with async and zero-copy Rockchip MPP & RGA support
Other
325 stars 47 forks source link

RTSP使用h264_rkmpp无法使用 #31

Closed szaipcljl closed 4 months ago

szaipcljl commented 4 months ago

使用的fixup! lavf/rkrga: add force_{yuv,chroma} options for vpp filter这版FFmepg rkmpp使用的是https://github.com/HermanChen/mpp/commit/fdeb8c378b79d4b4ef80457e4431815de89dc417

现在出现问题如下,请问这个是什么原因呢? [tcp @ 0x2cbc850] No default whitelist set [tcp @ 0x2cbc850] Original list of addresses: [tcp @ 0x2cbc850] Address 192.168.11.65 port 554 [tcp @ 0x2cbc850] Interleaved list of addresses: [tcp @ 0x2cbc850] Address 192.168.11.65 port 554 [tcp @ 0x2cbc850] Starting connection attempt to 192.168.11.65 port 554 [tcp @ 0x2cbc850] Successfully connected to 192.168.11.65 port 554 [rtsp @ 0x2ce0500] SDP: v=0 o=- 1709553511739851 1709553511739851 IN IP4 192.168.11.65 s=Media Presentation e=NONE b=AS:5050 t=0 0 a=control:rtsp://192.168.11.65:554/Streaming/Channels/101/ m=video 0 RTP/AVP 96 b=AS:5000 a=control:rtsp://192.168.11.65:554/Streaming/Channels/101/trackID=1 a=rtpmap:96 H264/90000 a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=Z0IAKpY1QPAET8s3AQEBQAABwgAAV+Qh,aM4xsg== a=Media_header:MEDIAINFO=494D4B48010100000400000100000000000000000000000000000000000000000000000000000000; a=appversion:1.0

[rtsp @ 0x2ce0500] video codec set to: h264 [rtsp @ 0x2ce0500] RTP Profile IDC: 42 Profile IOP: 0 Level: 29 [rtsp @ 0x2ce0500] RTP Packetization Mode: 1 [rtsp @ 0x2ce0500] Extradata set to 0x2ce13d0 (size: 36) [rtsp @ 0x2ce0500] setting jitter buffer size to 0 [rtsp @ 0x2ce0500] hello state=0 mVideoIndex = 0, width = 0, height = 0, codecId = 27 pixfmt: 0, width: 0, height: 0 [h264_mp4toannexb @ 0x2cda170] The input looks like it is Annex B already [h264_rkmpp @ 0x2cd67c0] Format nv12 chosen by get_format(). [h264_rkmpp @ 0x2cd67c0] Failed to init MPP context: -1 open codec failed, return: -542398533, errstr: Generic error in an external library

szaipcljl commented 4 months ago

下面是初始化解码器的代码 int DRtspDecoder::initDecoder() { const AVCodec *codec;

if (mFmtCtx->streams[mVideoIndex]->codecpar->codec_id == AV_CODEC_ID_H264) {
    // codec = avcodec_find_decoder(AV_CODEC_ID_H264);
    codec = avcodec_find_decoder_by_name("h264_rkmpp");
} else if (mFmtCtx->streams[mVideoIndex]->codecpar->codec_id == AV_CODEC_ID_HEVC) {
    codec = avcodec_find_decoder(AV_CODEC_ID_HEVC);
    // codec = avcodec_find_decoder_by_name("hevc_rkmpp");
} else {
    std::cerr << "find decoder failed" << std::endl;
    return -1;
}

mCodecCtx = avcodec_alloc_context3(codec);
if (mCodecCtx == NULL) {
    std::cerr << "alloc codec context failed" << std::endl;
    return -2;
}

// 设置时间基
mCodecCtx->time_base = (AVRational){1, 1000};
mCodecCtx->pix_fmt = mDecodeFramePixFmt == PIX_FMT_BGR24 ? AV_PIX_FMT_BGR24 : AV_PIX_FMT_YUV420P;

std::cout << "pixfmt: " << mFmtCtx->streams[mVideoIndex]->codecpar->format 
          << ", width: " << mFmtCtx->streams[mVideoIndex]->codecpar->width
          << ", height: " << mFmtCtx->streams[mVideoIndex]->codecpar->height
          << std::endl;

int ret = avcodec_parameters_to_context(mCodecCtx, mFmtCtx->streams[mVideoIndex]->codecpar);
if (ret < 0) {
    std::cerr << "copy codec parameters to context failed: " << av_err2str(ret) << std::endl;
}

AVDictionary *opt = NULL;
av_dict_set(&opt, "hwaccel", "rkmpp", 0);

ret = avcodec_open2(mCodecCtx, codec, &opt);
if (ret < 0) {
    std::cerr << "open codec failed, return: " << ret << ", errstr: " << av_err2str(ret) << std::endl;
    avcodec_free_context(&mCodecCtx);
    av_dict_free(&opt);
    mCodecCtx = NULL;
    return -3;
}

av_dict_free(&opt);
return 0;

}