0

我正在使用 android NDK 和 FFmpeg 本机库开发解码器。我已经使用 Android 工具为项目提供了本机支持,并且我在 videodecoder.cpp 文件中有 C 代码。在文件中,以下函数给了我这个问题

JNIEXPORT jint Java_ssrp_android_ffmpegdecoder_H264Decoder_consumeNalUnitsFromDirectBuffer(
        JNIEnv* env, jobject thiz, jobject nal_units, jint num_bytes,
        jlong pkt_pts) {
    DecoderContext *ctx = get_ctx(env, thiz);

    void *buf = NULL;
    if (nal_units == NULL) {
        D("Received null buffer, sending empty packet to decoder");
    } else {
        buf = env->GetDirectBufferAddress(nal_units);
        if (buf == NULL) {
            D("Error getting direct buffer address");
            return -1;
        }
    }

    AVPacket packet = {.data = (uint8_t*) buf, .size = num_bytes, .pts = pkt_pts };

    int frameFinished = 0;
    int res = avcodec_decode_video2(ctx->codec_ctx, ctx->src_frame,&frameFinished, &packet);

    if (frameFinished)
        ctx->frame_ready = 1;

    return res;
}

在线上AVPacket packet = {.data = (uint8_t*) buf, .size = num_bytes, .pts = pkt_pts };

它说`Statement has no effect "AVPAcket" and

在线上int res = avcodec_decode_video2(ctx->codec_ctx, ctx->src_frame,&frameFinished, &packet);

它说Invalid arguments ' Candidates are: int avcodec_decode_video2(AVCodecContext *, AVFrame *, int *, const AVPacket *)'

4

1 回答 1

3

问题是

AVPacket packet = {.data = (uint8_t*) buf, .size = num_bytes, .pts = pkt_pts }

因为编译器不理解类型/初始化。这会导致无效参数错误。也许将行拆分为:

AVPacket packet;
packet.data = (uint8_t*) buf;
packet.size = num_bytes;
packet.pts = pkt_pts;

这应该得到更清晰的错误输出。

于 2013-10-24T21:24:42.267 回答