I built opencv with cuda under ubuntu20.04, with NVIDIA Corporation GP104 [GeForce GTX 1070] Driver Version: 460.39 CUDA Version: 11.2 , configure result as follows:
– GUI:
– GTK+: YES (ver 2.24.32)
– GThread : YES (ver 2.64.6)
– GtkGlExt: YES (ver 1.2.0)
– OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so)
– VTK support: NO
– Media I/O:
– ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
– JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
– WEBP: build (ver encoder: 0x020f)
– PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
– TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
– JPEG 2000: build (ver 2.4.0)
– OpenEXR: build (ver 2.3.0)
– HDR: YES
– SUNRASTER: YES
– PXM: YES
– PFM: YES
– Video I/O:
– DC1394: YES (2.2.5)
– FFMPEG: YES
– avcodec: YES (58.136.101)
– avformat: YES (58.78.100)
– avutil: YES (56.72.100)
– swscale: YES (5.10.100)
– avresample: YES (4.0.0)
– GStreamer: YES (1.16.2)
– v4l/v4l2: YES (linux/videodev2.h)
– Parallel framework: TBB (ver 2020.1 interface 11101)
– Trace: YES (with Intel ITT)
– Other third-party libraries:
– Intel IPP: 2020.0.0 Gold [2020.0.0]
– at: /workspace/opencv/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
– Intel IPP IW: sources (2020.0.0)
– at: /workspace/opencv/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
– VA: YES
– Lapack: YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
– Eigen: YES (ver 3.3.7)
– Custom HAL: NO
– Protobuf: build (3.5.1)
– NVIDIA CUDA: YES (ver 11.0, CUFFT CUBLAS NVCUVID FAST_MATH)
– NVIDIA GPU arch: 35 37 50 52 60 61 70 75 80
– NVIDIA PTX archs:
– cuDNN: NO
– OpenCL: YES (INTELVA)
– Include path: /workspace/opencv/opencv/3rdparty/include/opencl/1.2
– Link libraries: Dynamic load
– Python 3:
– Interpreter: /usr/bin/python3 (ver 3.8.5)
– Libraries: /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.5)
– numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.17.4)
– install path: lib/python3.8/dist-packages/cv2/python-3.8
– Python (for build): /usr/bin/python3
ffmpeg with cuda support compiled first, ffmpeg with hardware acceleration test OK, tested with following command:
ffmpeg -hwaccel_output_format cuda -vcodec h264_cuvid -i 1.mp4 -vcodec h264_nvenc -gpu 0 -acodec copy -f mp4 -y output.mp4
hardware is NVIDIA Corporation GP104 [GeForce GTX 1070]. I checked that it support hard encode and decode
As head said, I checked that cv::cudacodec::createVideoReader work well, test code as follows:
#include
#include “opencv2/opencv_modules.hpp”
#include
#include
#include
#include
#include <opencv2/core.hpp>
#include <opencv2/core/opengl.hpp>
#include <opencv2/cudacodec.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/cudawarping.hpp>
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
return -1;
// cv::namedWindow(“GPU”, cv::WINDOW_OPENGL);
//cv::cuda::setGlDevice();
cv::cuda::GpuMat d_frame, o_frame;
cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(std::string(argv[1]));
cv::cudacodec::FormatInfo fmt = d_reader->format();
std::cout << "hello!" << std::endl;
cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
// cv::Ptr<cv::cudacodec::VideoWriter> d_writer = cv::cudacodec::createVideoWriter(
// std::string("tmp.avi"),
// cv::Size2i(fmt.width*2, fmt.height*2),
// 25.0,
// cv::cudacodec::SF_UYVY);
while (true)
{
std::cout << "hello, ";
if (!d_reader->nextFrame(d_frame))
break;
cv::cuda::resize(d_frame, o_frame, cv::Size2i(fmt.width*2, fmt.height*2));
// cv::Mat img;
// d_frame.download(img);
// cv::imwrite("out.jpg", img, {cv::ImwriteFlags::IMWRITE_JPEG_QUALITY} );
if (d_writer.empty()){
const cv::String outputFilename = "output_gpu.avi";
// d_writer = cv::cudacodec::createVideoWriter(outputFilename, o_frame.size(), 25.0);
}
// d_writer->write(o_frame);
std::cout << "world!" << std::endl;
}
return 0;
}
/*
g++ -o test test.cpp -I/usr/local/include/opencv4/ -lopencv_cudacodec -lopencv_videoio -lopencv_core -lopencv_cudev -lopencv_cudacodec -lopencv_cudawarping -lopencv_cudafilters -lopencv_highgui
*/
Questine: Error raised after uncommented “// d_writer = cv::cudacodec::createVideoWriter(outputFilename, o_frame.size(), 25.0);” , as follow:
OpenCV(4.5.2) Error: The function/feature is not implemented (The called functionality is disabled for current build or platform) in throw_no_cuda, file /workspace/opencv/opencv/modules/core/include/opencv2/core/private.cuda.hpp, line 112
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.5.2) /workspace/opencv/opencv/modules/core/include/opencv2/core/private.cuda.hpp:112: error: (-213:The function/feature is not implemented) The called functionality is disabled for current build or platform in function ‘throw_no_cuda’