I use javacv to decode the H264 video stream and generate the corresponding jpg image. I hope to use the GPU to improve the decoding speed, but javacv does not currently contain the h264_cuvid decoding package. How can I adjust my code? My code is roughly as follows:
private Frame frame = null;
private OpenCVFrameConverter.ToMat toMat = new OpenCVFrameConverter.ToMat();
private org.opencv.core.Mat mat = null;
FFmpegFrameGrabber grab = FFmpegFrameGrabber.createDefault("hello.ts");
grab.setOption("rtsp_transport", "udp");
grab.setOption("stimeout", "10000000");
grab.setOption("buffer_size", "40960000");
grab.setOption("hwaccel", "cuvid");
grab.setVideoCodecName("h264_cuvid");
frame = grab.grab()
mat = new Mat(toMat.convert(frame.clone()).mat.address());
MatOfByte mob = new MatOfByte();
String params = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 85);
Imgcodecs.imencode(".jpg", mat, mob, params);
byte[] image = mob.toArray();
That should work with JavaCV 1.4.4. What error messages do you get?
That should work with JavaCV 1.4.4. What error messages do you get?
I am using JavaCV 1.4.4, the pom file is like this:
But the runtime is reporting an error:
[h264_cuvid @ 0x7fc5d8a98ec0] Cannot load cuvidGetDecodeStatus
[h264_cuvid @ 0x7fc5d8a98ec0] Failed loading nvcuvid.
exception:avcodec_open2() error -1: Could not open video codec.
It looks like you'll need to update the version of your video driver:
https://stackoverflow.com/questions/51833519/compiling-ffmpeg-with-nvidia-cuda-failed-loading-nvcuvid
I'm assuming that updating your video driver worked, but please let me know if this isn't the case! Thanks
I'm assuming that updating your video driver worked, but please let me know if this isn't the case! Thanks
I am sorry, I will reply to you now. Because the environment for preparing ffmpeg4.1 (h264_cuvid) took a lot of time, just verified, the program can run normally and reach my expected goal. Here is my configuration information:
1.javacv1.4.4
2.ffmpeg4.1
3.cuda10.1.105_418.39
4.Video_Codec_SDK9.0.20
5.nv-codec-headers9.0.18.0
6.nivida driver418.39
Thank you very much!
The binaries that javacv-platform depends on should also work, do they?
The binaries that javacv-platform depends on should also work, do they?
Yes, the so files are valid and they can run on the GPU.
Most helpful comment
It looks like you'll need to update the version of your video driver:
https://stackoverflow.com/questions/51833519/compiling-ffmpeg-with-nvidia-cuda-failed-loading-nvcuvid