EnoxSoftware / OpenCVForUnity

OpenCV for Unity (Untiy Asset Plugin)
https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088
550 stars 172 forks source link

How to open video stream(stream/video.mjpeg) using OpenCVForUnity? #142

Open YouMinJung opened 2 years ago

YouMinJung commented 2 years ago

Hi. I want to get the image frame from the video stream URL. I wrote the code refer to "videoio example" and "https://forum.unity.com/threads/released-opencv-for-unity.277080/page-55#post-7427405". However, I failed to load video stream.

My log message is like these. How to solve this problem?? image

PS. Current, I opened the video stream using VLC code. However, when I open video using VLC, I should use "TextureToMat" but It uses performance too much. so, I want to get a video frame in the form of a Mat. Is there any way? Could you recommend to me?

EnoxSoftware commented 2 years ago

Could you try the following steps?

To play streaming file, ffmpeg.dll is required. 1)Download "OpenCV for Windows Version 4.5.5"(https://sourceforge.net/projects/opencvlibrary/). 2)Copy "opencv_videoio_ffmpeg455_64.dll" to "Assets/OpenCVForUntiy/Plugins/Windows/x86_64" folder.

ffmpeg_plugin

3)Edit User Variables. https://stackoverflow.com/questions...reply-when-cv2-videocapture-rtsp-onvif-camera

ffmepg_edit_user_variables

I succeeded in playing this file. BigBuckBunny_115k.mov seems to be a broken link. //capture.open(Utils.getFilePath(VIDEO_FILENAME)); capture.open("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4", Videoio.CAP_FFMPEG);

ffmpeg_plugin2

Unfortunately I have never used VLC, I would recommend using the AsyncGPUReadback class when converting from RenderTexture to Mat. https://github.com/EnoxSoftware/VideoPlayerWithOpenCVForUnityExample

masaruyoshimura commented 2 months ago

It just happned to me, too. OpenCV VideoCapture on python can receive rtsp, but OpenCVForUnity can't.

            _videoCapture = new VideoCapture(url); // url is rtsp://... and same url VideoCapture in python can receive.
            var ret = _videoCapture.isOpened();  // ret is false
EnoxSoftware commented 2 months ago

@masaruyoshimura For the open() method, it is necessary to update the backend to Videoio.CAP_FFMPEG. //capture.open(Utils.getFilePath(VIDEO_FILENAME)); capture.open("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4", Videoio.CAP_FFMPEG);