fan-chao / nvjmi

封装Jetson Multimedia API的编解码库,基于https://github.com/jocover/jetson-ffmpeg基础进行的修改,未集成于ffmpeg,可单独使用。
MIT License
31 stars 12 forks source link

NvEGLImageFromFd: No EGLDisplay to create EGLImage Error while mapping dmabuf fd (1210) to EGLImage #7

Closed zjhellofss closed 2 years ago

zjhellofss commented 2 years ago

我用的是一个没有显示器的jetson,用ssh的方式连接的。然后在编译运行以下的代码后出现了如题的问题:

NvEGLImageFromFd: No EGLDisplay to create EGLImage
Error while mapping dmabuf fd (1210) to EGLImage
NvEGLImageFromFd: No EGLDisplay to create EGLImage
Error while mapping dmabuf fd (1210) to EGLImage
NvEGLImageFromFd: No EGLDisplay to create EGLImage
Error while mapping dmabuf fd (1210) to EGLImage
NvEGLImageFromFd: No EGLDisplay to create EGLImage
#include <string>
#include "nvjmi.h"

#define __STDC_CONSTANT_MACROS

#ifdef _WIN32
//Windows
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
};
#else
//Linux...
#ifdef __cplusplus
extern "C"
{
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#ifdef __cplusplus
};
#endif
#endif

int main() {
    AVFormatContext *pFormatCtx;
    AVPacket *packet;

    av_register_all();
    avformat_network_init();
    pFormatCtx = avformat_alloc_context();
    int height = 512;
    int width = 512;
    const char *filepath = "/tmp/tmp.R2FKolG3xe/data/sample_outdoor_car_1080p_10fps.h264";
    if (avformat_open_input(&pFormatCtx, filepath, NULL, NULL) != 0) {
        printf("Couldn't open input stream.\n");
        return -1;
    }
    if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
        printf("Couldn't find stream information.\n");
    }

    packet = (AVPacket *) av_malloc(sizeof(AVPacket));
    av_dump_format(pFormatCtx, 0, filepath, 0);

    jmi::nvJmiCtxParam jmi_ctx_param;
    if (width > 0 && height > 0) {
        jmi_ctx_param.resize_width = width;
        jmi_ctx_param.resize_height = height;
    }

    jmi_ctx_param.coding_type = jmi::NV_VIDEO_CodingH264;
    std::string dec_name = "test_dec";
    jmi::nvJmiCtx *jmi_ctx_ = jmi::nvjmi_create_decoder(dec_name.data(), &jmi_ctx_param);
    jmi::nvPacket  nvpacket;
    while (av_read_frame(pFormatCtx, packet) >= 0) {
        nvpacket.payload_size = packet->size;
        nvpacket.payload = packet->data;
        int ret;
        ret = jmi::nvjmi_decoder_put_packet(jmi_ctx_, &nvpacket);
        if(ret == jmi::NVJMI_ERROR_STOP) {
            printf("nvjmi decode error, frame callback EOF!\n");
        }

    }
    if (packet != nullptr) {
        av_free(packet);
    }
    printf("Exit success\n");
    return 0;
}
fan-chao commented 2 years ago

参考 https://github.com/fan-chao/nvjmi/issues/2