From 0a826b3d98469f7022f4074bc1970950b9665ed1 Mon Sep 17 00:00:00 2001 From: fiss <2657262686@qq.com> Date: Wed, 16 Nov 2022 16:13:24 +0800 Subject: [PATCH] 适应WSL的修改 --- src/FFNvDecoder.cpp | 2 +- src/Makefile | 7 ++++--- src/main.cpp | 76 ++++++++++++++++++++++++++++++++++++++-------------------------------------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/FFNvDecoder.cpp b/src/FFNvDecoder.cpp index d491a17..fe3d5c4 100644 --- a/src/FFNvDecoder.cpp +++ b/src/FFNvDecoder.cpp @@ -130,7 +130,7 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) // 打开解码器流 AVDictionary *op = nullptr; av_dict_set( &op, "gpu", gpuid, 0 ); - av_dict_set( &op, "surfaces", "3", 0 ); + // av_dict_set( &op, "surfaces", "3", 0 ); if (avcodec_open2(avctx, vcodec, &op) < 0) { cout << "Failed to open codec for stream" << stream_index; return false; diff --git a/src/Makefile b/src/Makefile index b3fe018..f21a11b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,11 +5,11 @@ NVCC = nvcc DEFS= -DPOST_USE_RABBITMQ -PROJECT_ROOT= /home/cmhu/FFNvDecoder +PROJECT_ROOT= /mnt/e/fiss/FFNvDecoder DEPEND_DIR = $(PROJECT_ROOT)/bin SRC_ROOT = $(PROJECT_ROOT)/src -CUDA_ROOT = /usr/local/cuda-11.7 +CUDA_ROOT = /usr/local/cuda TARGET= $(DEPEND_DIR)/lib/test @@ -21,7 +21,8 @@ INCLUDE= -I $(DEPEND_DIR)/include \ -I $(SRC_ROOT)\ LIBSPATH= -L $(DEPEND_DIR)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ - -L $(CUDA_ROOT)/lib64 -lcuda -lcudart -lnvcuvid -lcurand -lcublas -lnvjpeg \ + -L $(CUDA_ROOT)/lib64 -lcudart -lcurand -lcublas -lnvjpeg \ + -L /usr/lib/wsl/lib -lcuda -lnvcuvid\ CFLAGS= -g -fPIC -O0 $(DEFS) $(INCLUDE) -pthread -lrt -lz -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl # -DUNICODE -D_UNICODE diff --git a/src/main.cpp b/src/main.cpp index 3f4b14f..00a61d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ void postDecoded(const void * userPtr, AVFrame * gpuFrame){ return; } - string path = "/home/cmhu/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg"; + string path = "/mnt/f/fiss/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg"; saveJpeg(path.c_str(), pHwRgb[0], gpuFrame->width, gpuFrame->height, stream[0]); // 验证 CUDAToRGB } } else if (decoder->getName() == "dec2") @@ -79,7 +79,7 @@ void postDecoded(const void * userPtr, AVFrame * gpuFrame){ return; } - string path = "/home/cmhu/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg"; + string path = "/mnt/f/fiss/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg"; saveJpeg(path.c_str(), pHwRgb[1], gpuFrame->width, gpuFrame->height, stream[1]); // 验证 CUDAToRGB } } @@ -124,38 +124,38 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){ } count++; sum ++ ; - // if (count >= count_std) - // { - // // end_time = get_cur_time(); - // // long time_using = end_time - start_time; - // // double time_per_frame = double(time_using)/count_std ; - // // cout << count_std << "帧用时:" << time_using << "ms 每帧用时:" << time_per_frame << "ms" << endl; - // cout << "keyframe: " << gpuFrame->key_frame << " width: " << gpuFrame->width << " height: "<< gpuFrame->height << endl; - // cout << gpuFrame->pts << endl; - - // count_flag = false; - // } - // cout << "帧数:" << sum << endl; - - // if (gpuFrame->format == AV_PIX_FMT_CUDA) - // { - // cudaSetDevice(atoi(decoder->m_cfg.gpuid.c_str())); - // // cout << "gpu id : " << decoder->m_cfg.gpuid.c_str() << endl; - // cudaError_t cudaStatus; - // if(pHwData == nullptr){ - // cuda_common::setColorSpace2( ITU709, 0 ); - // cudaStatus = cudaMalloc((void **)&pHwData, 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char)); - // } - // cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); - // cudaDeviceSynchronize(); - // if (cudaStatus != cudaSuccess) { - // cout << "CUDAToBGR failed !!!" << endl; - // return; - // } - - // string path = "/home/cmhu/data/test/" + to_string(sum) + ".jpg"; - // saveJpeg(path.c_str(), pHwData, gpuFrame->width, gpuFrame->height, nullptr); // 验证 CUDAToRGB - // } + if (count >= count_std) + { + // end_time = get_cur_time(); + // long time_using = end_time - start_time; + // double time_per_frame = double(time_using)/count_std ; + // cout << count_std << "帧用时:" << time_using << "ms 每帧用时:" << time_per_frame << "ms" << endl; + cout << "keyframe: " << gpuFrame->key_frame << " width: " << gpuFrame->width << " height: "<< gpuFrame->height << endl; + cout << gpuFrame->pts << endl; + + count_flag = false; + } + cout << "帧数:" << sum << endl; + + if (gpuFrame->format == AV_PIX_FMT_CUDA) + { + cudaSetDevice(atoi(decoder->m_cfg.gpuid.c_str())); + // cout << "gpu id : " << decoder->m_cfg.gpuid.c_str() << endl; + cudaError_t cudaStatus; + if(pHwData == nullptr){ + cuda_common::setColorSpace2( ITU709, 0 ); + cudaStatus = cudaMalloc((void **)&pHwData, 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char)); + } + cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); + cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) { + cout << "CUDAToBGR failed !!!" << endl; + return; + } + + string path = "/mnt/f/fiss/data/" + to_string(sum) + ".jpg"; + saveJpeg(path.c_str(), pHwData, gpuFrame->width, gpuFrame->height, nullptr); // 验证 CUDAToRGB + } } } } @@ -164,7 +164,7 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){ // string test_uri = "/home/cmhu/data/output_800x480.mp4"; // string test_uri = "/home/cmhu/data/output_1920x1080.mp4"; // string test_uri = "rtsp://176.10.0.2:8554/stream"; -string test_uri = "/home/cmhu/data2/Street.uvf"; +string test_uri = "/mnt/f/fiss/test_data/h265.mp4"; void createDecode(int index){ FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance(); @@ -227,7 +227,7 @@ int CheckCUDAProperty( int devId ) int main(){ - CheckCUDAProperty(1); + CheckCUDAProperty(0); FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance(); @@ -242,14 +242,14 @@ int main(){ config.cfg.uri = test_uri; config.cfg.post_decoded_cbk = postDecoded0; config.cfg.force_tcp = true; - config.cfg.gpuid = "2"; + config.cfg.gpuid = "0"; FFNvDecoder* dec2 = pDecManager->createDecoder(config); if (!dec2) { return 1; } pDecManager->setUserPtr(config.name, dec2); - pDecManager->setDecKeyframe(config.name, true); + // pDecManager->setDecKeyframe(config.name, true); pDecManager->startDecodeByName(config.name); pthread_t m_decode_thread; -- libgit2 0.21.4