private void Axis_VideoPlay() { Task.Factory.StartNew(() => { // Create AXIS Media Parser and AXIS Media Viewer components parser = new AxisMediaParser(); viewer = new AxisMediaViewer(); }).Wait(); //事件注册 parser.OnVideoSample += OnVideoSample; parser.OnAudioSample += OnAudioSample; parser.OnMetaDataSample += OnMetaDataSample; parser.OnError += OnError; //流媒体参数 parser.ShowLoginDialog = true; StringBuilder sbUrl = new StringBuilder(); sbUrl.Append("axrtsphttp://"); sbUrl.Append(CurrentVideoInfo.DVSAddress); sbUrl.Append("/axis-media/media.amp?videocodec=JPEG"); sbUrl.Append("&camera=" + CurrentCameraInfo.Channel); string strUrl = sbUrl.ToString(); parser.MediaURL = strUrl; parser.MediaUsername = CurrentVideoInfo.UserName; parser.MediaPassword = CurrentVideoInfo.Password; //设置页面参数 viewer.VideoRenderer = (int)AMV_RENDER_OPTIONS.AMV_VIDEO_RENDERER_EVR; //视频解码器,注意回放视频是要同一 //图片回调 //viewer.EnableOnDecodedImage = true; //viewer.OnDecodedImage += OnDecodedImage; //viewer.ColorSpace = (short)AMV_COLOR_SPACE.AMV_CS_RGB24; viewer.EnableOnDecodedImage = false; viewer.ColorSpace = (short)AMV_COLOR_SPACE.AMV_CS_YUY2; viewer.LiveMode = true; //实时模式 int cookieID; int numberOfStreams; object objmediaTypeBuffer; parser.Connect(out cookieID, out numberOfStreams, out objmediaTypeBuffer); //连接 viewer.Init(0, objmediaTypeBuffer, intptrPlayMain.ToInt64()); //初始化 viewer.SetVideoPosition(0, 0, VideoplayWindowWidth, VideoplayWindowHeight); if (CurrentVideoPlaySet.VideoRecordEnable) { lstVideoRecord = new List <byte>(); byte[] bytsMediaType = (byte[])objmediaTypeBuffer; lstVideoRecord.AddRange(BitConverter.GetBytes(bytsMediaType.Length)); lstVideoRecord.AddRange(bytsMediaType); VideoRecordStatus = true; } viewer.Start(); parser.Start(); VideoPlayState = Enum_VideoPlayState.Connecting; }
static void Main(string[] args) { // Look at our arguments for (int i = 0; i < args.Length; i++) { // Check if we are recieving the name of an argument if (args[i].Substring(0, 2) == "--") { // We got a real argument! switch (args[i]) { case "--data-path": dataPath = args[++i]; break; case "--camera-ip": camIP = args[++i]; break; case "--record-for-seconds": recordingDuration = Convert.ToInt32(args[++i]); break; default: Console.WriteLine("Unknown Command: " + args[i] + " With argument: " + args[++i]); break; } } else { // We did not get a real argument! Console.WriteLine("Malformed Command: " + args[i] + ",\n Arguments must be preceded by -- and succeeded by their argument"); } } // Create the AXIS Media Parser object and set connection properties AxisMediaParser parser = new AxisMediaParser(); parser.MediaURL = "axmphttp://" + camIP + "/mjpg/1/video.mjpg"; parser.MediaUsername = "******"; parser.MediaPassword = "******"; // Register for OnVideoSample events parser.OnVideoSample += OnVideoSample; try { using (FileStream outFileStream = new FileStream(dataPath, FileMode.Create)) using (outFile = new BinaryWriter(outFileStream)) { Console.WriteLine("Connecting to {0}", parser.MediaURL); int cookieID; int numberOfStreams; object mediaBuffer; parser.Connect(out cookieID, out numberOfStreams, out mediaBuffer); // Write media type information to file (buffer is an array of bytes) byte[] mediaTypeBuffer = (byte[])mediaBuffer; outFile.Write(mediaTypeBuffer.Length); outFile.Write(mediaTypeBuffer, 0, mediaTypeBuffer.Length); // Start parser, OnVideoSample() will be called for each parsed frame parser.Start(); // Sleep while OnVideoSample() System.Threading.Thread.Sleep(recordingDuration * 1000); // Stop the stream, the file C:\Axis\video.bin contains the 5 seconds video parser.Stop(); Console.WriteLine("Stream stopped"); } } catch (COMException e) { Console.WriteLine("Exception from URL: {0}, Error: {1}", parser.MediaURL, e.Message); } }
static void Main(string[] args) { // Look at our arguments for (int i = 0; i < args.Length; i++) { // Check if we are recieving the name of an argument if (args[i].Substring(0, 2) == "--") { // We got a real argument! switch (args[i]) { case "--data-path": dataPath = args[++i]; break; case "--cam-ip": camIP = args[++i]; break; case "--record-for-seconds": recordingDuration = Convert.ToInt32(args[++i]); break; case "--cam-username": camUsername = args[++i]; break; case "--cam-password": camPassword = args[++i]; break; default: Console.WriteLine("Unknown Command: " + args[i] + " With argument: " + args[++i]); break; } } else { // We did not get a real argument! Console.WriteLine("Malformed Command: " + args[i] + ",\n Arguments must be preceded by -- and succeeded by their argument. ignoring this argument..."); } } // Check for missing arguments if (dataPath == "") { Console.WriteLine("--data-path argument not found. You must specify a data path including the file name of the form /../../fileName.bin exiting..."); Environment.Exit(1); } if (camIP == "") { Console.WriteLine("--cam-ip argument not found. You must specify a camera ip address that can be found on the network exiting..."); Environment.Exit(1); } if (recordingDuration == -1) { Console.WriteLine("--record-for-seconds argument not found. You must specify a recording duration greater than 0 in seconds. Defaulting to 60 seconds"); recordingDuration = 60; } if (camUsername == "") { Console.WriteLine("--cam-username argument not found. You must specify a username to access the camera video stream. defaulting to 'root'"); camUsername = "******"; } if (camPassword == "") { Console.WriteLine("--cam-password argument not found. You must specify a password to access the camera video stream. defaulting to 'pass'"); camUsername = "******"; } // Create the AXIS Media Parser object and set connection properties AxisMediaParser parser = new AxisMediaParser(); parser.MediaURL = "axmphttp://" + camIP + "/mjpg/1/video.mjpg"; parser.MediaUsername = camUsername; parser.MediaPassword = camPassword; // Register for OnVideoSample events parser.OnVideoSample += OnVideoSample; try { using (FileStream outFileStream = new FileStream(dataPath, FileMode.Create)) using (outFile = new BinaryWriter(outFileStream)) { Console.WriteLine("Connecting to {0}", parser.MediaURL); int cookieID; int numberOfStreams; object mediaBuffer; parser.Connect(out cookieID, out numberOfStreams, out mediaBuffer); Console.WriteLine("Connected to {0}", parser.MediaURL); // Write media type information to file (buffer is an array of bytes) byte[] mediaTypeBuffer = (byte[])mediaBuffer; outFile.Write(mediaTypeBuffer.Length); outFile.Write(mediaTypeBuffer, 0, mediaTypeBuffer.Length); // Start parser, OnVideoSample() will be called for each parsed frame parser.Start(); // Sleep while OnVideoSample() System.Threading.Thread.Sleep(recordingDuration * 1000); // Stop the stream, the file C:\Axis\video.bin contains the 5 seconds video parser.Stop(); Console.WriteLine("Stream stopped"); Environment.Exit(0); } } catch (COMException e) { Console.WriteLine("Exception from URL: {0}, Error: {1}", parser.MediaURL, e.Message); Environment.Exit(1); } }