shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.39k stars 1.15k forks source link

OpenCVSharp VideoWriter Issue #1209

Closed DhananjayHuidrom closed 3 years ago

DhananjayHuidrom commented 3 years ago

Summary of your issue

Failed to create a video file from live ip camer. Please help.

Environment

C#, visual studio 2019, .net core 3.1, OpenCvSharp4 (4.5.1.20210208)

Issue / problem?

1) .mjpg: Video is created with size of 0 kb 2) .avi: Video is failed to create

Example code:

const string OutVideoFile = "E:\output.mjpg"; var url = "rtsp://user:pass@ipaddress:554/cam/realmonitor?channel=1&subtype=0"; OpenCvSharp.Size dsize = new OpenCvSharp.Size(640, 480); VideoCapture capture = new VideoCapture(url); using (VideoWriter writer = new VideoWriter(OutVideoFile, FourCC.MJPG, 25, dsize)) { if(writer.IsOpened() == false) { Console.WriteLine("Failed to open writer."); return; }

            Console.WriteLine("Converting each movie frames...");
            Mat frame = new Mat();
            while (true)
            {
                // Read image
                capture.Read(frame);
                if (frame.Empty() || capture.PosFrames > 100)
                {
                    writer.Release();
                    break;
                }
                //Cv2.ImShow("v", frame);
                Console.CursorLeft = 0;
                Console.Write("{0} / {1}", capture.PosFrames, capture.FrameCount); 
                writer.Write(frame);
                Cv2.WaitKey(50);
            }
            Console.WriteLine();
        }

Output:

OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 7 and format 'mjpeg / raw MJPEG video'

What did you intend to be?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.