OpenCVForUnity icon indicating copy to clipboard operation
OpenCVForUnity copied to clipboard

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

Open YouMinJung opened this issue 2 years ago • 3 comments

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?

YouMinJung avatar Apr 01 '22 07:04 YouMinJung

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

EnoxSoftware avatar Apr 01 '22 09:04 EnoxSoftware

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

  • Unity Editor version: 2022.3.14f1
  • OpenCV for Unity version: 2.5.9
  • I put the file opencv_videoio_ffmpeg490_64.dll in Assets\OpenCVForUnity\Plugins\Windows\x86_64
  • Environment Variable
    • OPENCV_FFMPEG_CAPTURE_OPTIONS : rtsp_transport;udp
            _videoCapture = new VideoCapture(url); // url is rtsp://... and same url VideoCapture in python can receive.
            var ret = _videoCapture.isOpened();  // ret is false

masaruyoshimura avatar Apr 19 '24 05:04 masaruyoshimura

@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);

EnoxSoftware avatar Apr 20 '24 08:04 EnoxSoftware