Commit 0a826b3d98469f7022f4074bc1970950b9665ed1

Authored by Hu Chunming
1 parent bc52e542

适应WSL的修改

src/FFNvDecoder.cpp
... ... @@ -130,7 +130,7 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp)
130 130 // 打开解码器流
131 131 AVDictionary *op = nullptr;
132 132 av_dict_set( &op, "gpu", gpuid, 0 );
133   - av_dict_set( &op, "surfaces", "3", 0 );
  133 + // av_dict_set( &op, "surfaces", "3", 0 );
134 134 if (avcodec_open2(avctx, vcodec, &op) < 0) {
135 135 cout << "Failed to open codec for stream" << stream_index;
136 136 return false;
... ...
src/Makefile
... ... @@ -5,11 +5,11 @@ NVCC = nvcc
5 5  
6 6 DEFS= -DPOST_USE_RABBITMQ
7 7  
8   -PROJECT_ROOT= /home/cmhu/FFNvDecoder
  8 +PROJECT_ROOT= /mnt/e/fiss/FFNvDecoder
9 9  
10 10 DEPEND_DIR = $(PROJECT_ROOT)/bin
11 11 SRC_ROOT = $(PROJECT_ROOT)/src
12   -CUDA_ROOT = /usr/local/cuda-11.7
  12 +CUDA_ROOT = /usr/local/cuda
13 13  
14 14 TARGET= $(DEPEND_DIR)/lib/test
15 15  
... ... @@ -21,7 +21,8 @@ INCLUDE= -I $(DEPEND_DIR)/include \
21 21 -I $(SRC_ROOT)\
22 22  
23 23 LIBSPATH= -L $(DEPEND_DIR)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \
24   - -L $(CUDA_ROOT)/lib64 -lcuda -lcudart -lnvcuvid -lcurand -lcublas -lnvjpeg \
  24 + -L $(CUDA_ROOT)/lib64 -lcudart -lcurand -lcublas -lnvjpeg \
  25 + -L /usr/lib/wsl/lib -lcuda -lnvcuvid\
25 26  
26 27 CFLAGS= -g -fPIC -O0 $(DEFS) $(INCLUDE) -pthread -lrt -lz -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl
27 28 # -DUNICODE -D_UNICODE
... ...
src/main.cpp
... ... @@ -54,7 +54,7 @@ void postDecoded(const void * userPtr, AVFrame * gpuFrame){
54 54 return;
55 55 }
56 56  
57   - string path = "/home/cmhu/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg";
  57 + string path = "/mnt/f/fiss/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg";
58 58 saveJpeg(path.c_str(), pHwRgb[0], gpuFrame->width, gpuFrame->height, stream[0]); // 验证 CUDAToRGB
59 59 }
60 60 } else if (decoder->getName() == "dec2")
... ... @@ -79,7 +79,7 @@ void postDecoded(const void * userPtr, AVFrame * gpuFrame){
79 79 return;
80 80 }
81 81  
82   - string path = "/home/cmhu/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg";
  82 + string path = "/mnt/f/fiss/data/" + decoder->getName() + "/" + to_string(sum) + ".jpg";
83 83 saveJpeg(path.c_str(), pHwRgb[1], gpuFrame->width, gpuFrame->height, stream[1]); // 验证 CUDAToRGB
84 84 }
85 85 }
... ... @@ -124,38 +124,38 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){
124 124 }
125 125 count++;
126 126 sum ++ ;
127   - // if (count >= count_std)
128   - // {
129   - // // end_time = get_cur_time();
130   - // // long time_using = end_time - start_time;
131   - // // double time_per_frame = double(time_using)/count_std ;
132   - // // cout << count_std << "帧用时:" << time_using << "ms 每帧用时:" << time_per_frame << "ms" << endl;
133   - // cout << "keyframe: " << gpuFrame->key_frame << " width: " << gpuFrame->width << " height: "<< gpuFrame->height << endl;
134   - // cout << gpuFrame->pts << endl;
135   -
136   - // count_flag = false;
137   - // }
138   - // cout << "帧数:" << sum << endl;
139   -
140   - // if (gpuFrame->format == AV_PIX_FMT_CUDA)
141   - // {
142   - // cudaSetDevice(atoi(decoder->m_cfg.gpuid.c_str()));
143   - // // cout << "gpu id : " << decoder->m_cfg.gpuid.c_str() << endl;
144   - // cudaError_t cudaStatus;
145   - // if(pHwData == nullptr){
146   - // cuda_common::setColorSpace2( ITU709, 0 );
147   - // cudaStatus = cudaMalloc((void **)&pHwData, 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char));
148   - // }
149   - // cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height);
150   - // cudaDeviceSynchronize();
151   - // if (cudaStatus != cudaSuccess) {
152   - // cout << "CUDAToBGR failed !!!" << endl;
153   - // return;
154   - // }
155   -
156   - // string path = "/home/cmhu/data/test/" + to_string(sum) + ".jpg";
157   - // saveJpeg(path.c_str(), pHwData, gpuFrame->width, gpuFrame->height, nullptr); // 验证 CUDAToRGB
158   - // }
  127 + if (count >= count_std)
  128 + {
  129 + // end_time = get_cur_time();
  130 + // long time_using = end_time - start_time;
  131 + // double time_per_frame = double(time_using)/count_std ;
  132 + // cout << count_std << "帧用时:" << time_using << "ms 每帧用时:" << time_per_frame << "ms" << endl;
  133 + cout << "keyframe: " << gpuFrame->key_frame << " width: " << gpuFrame->width << " height: "<< gpuFrame->height << endl;
  134 + cout << gpuFrame->pts << endl;
  135 +
  136 + count_flag = false;
  137 + }
  138 + cout << "帧数:" << sum << endl;
  139 +
  140 + if (gpuFrame->format == AV_PIX_FMT_CUDA)
  141 + {
  142 + cudaSetDevice(atoi(decoder->m_cfg.gpuid.c_str()));
  143 + // cout << "gpu id : " << decoder->m_cfg.gpuid.c_str() << endl;
  144 + cudaError_t cudaStatus;
  145 + if(pHwData == nullptr){
  146 + cuda_common::setColorSpace2( ITU709, 0 );
  147 + cudaStatus = cudaMalloc((void **)&pHwData, 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char));
  148 + }
  149 + cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height);
  150 + cudaDeviceSynchronize();
  151 + if (cudaStatus != cudaSuccess) {
  152 + cout << "CUDAToBGR failed !!!" << endl;
  153 + return;
  154 + }
  155 +
  156 + string path = "/mnt/f/fiss/data/" + to_string(sum) + ".jpg";
  157 + saveJpeg(path.c_str(), pHwData, gpuFrame->width, gpuFrame->height, nullptr); // 验证 CUDAToRGB
  158 + }
159 159 }
160 160 }
161 161 }
... ... @@ -164,7 +164,7 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){
164 164 // string test_uri = "/home/cmhu/data/output_800x480.mp4";
165 165 // string test_uri = "/home/cmhu/data/output_1920x1080.mp4";
166 166 // string test_uri = "rtsp://176.10.0.2:8554/stream";
167   -string test_uri = "/home/cmhu/data2/Street.uvf";
  167 +string test_uri = "/mnt/f/fiss/test_data/h265.mp4";
168 168  
169 169 void createDecode(int index){
170 170 FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance();
... ... @@ -227,7 +227,7 @@ int CheckCUDAProperty( int devId )
227 227  
228 228 int main(){
229 229  
230   - CheckCUDAProperty(1);
  230 + CheckCUDAProperty(0);
231 231  
232 232 FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance();
233 233  
... ... @@ -242,14 +242,14 @@ int main(){
242 242 config.cfg.uri = test_uri;
243 243 config.cfg.post_decoded_cbk = postDecoded0;
244 244 config.cfg.force_tcp = true;
245   - config.cfg.gpuid = "2";
  245 + config.cfg.gpuid = "0";
246 246 FFNvDecoder* dec2 = pDecManager->createDecoder(config);
247 247 if (!dec2)
248 248 {
249 249 return 1;
250 250 }
251 251 pDecManager->setUserPtr(config.name, dec2);
252   - pDecManager->setDecKeyframe(config.name, true);
  252 + // pDecManager->setDecKeyframe(config.name, true);
253 253 pDecManager->startDecodeByName(config.name);
254 254  
255 255 pthread_t m_decode_thread;
... ...