Ejemplo n.º 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;

            //
            // Doing all that video processing is too much for low-end phones like the Lumia 520
            // Pick-and-choose which piece should run
            //

            VideoPreview.MediaFailed += VideoPreview_MediaFailed;
            //var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/video.cvmpilj.mjpg"));
            //var stream = await file.OpenAsync(FileAccessMode.Read);
            //var source = await HttpMjpegCaptureSource.CreateFromStreamAsync(stream, "myboundary");
            var source = await HttpMjpegCaptureSource.CreateFromUriAsync("http://216.123.238.208/axis-cgi/mjpg/video.cgi?camera&resolution=640x480");

            VideoPreview.SetMediaStreamSource(source.Source);

            var settings = new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video
            };
            await settings.SelectVideoDeviceAsync(VideoDeviceSelection.BackOrFirst);

            _capture = new MediaCapture();
            await _capture.InitializeAsync(settings);

            var graphicsDevice = MediaGraphicsDevice.CreateFromMediaCapture(_capture);

            var previewProps = (VideoEncodingProperties)_capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);

            TextLog.Text += String.Format("Preview: {0} {1}x{2} {3}fps\n", previewProps.Subtype, previewProps.Width, previewProps.Height, previewProps.FrameRate.Numerator / (float)previewProps.FrameRate.Denominator);

            TextLog.Text += "Creating MediaSamplePresenter from SurfaceImageSource\n";

            var image = new SurfaceImageSource((int)previewProps.Width, (int)previewProps.Height);

            ImagePreview.Source = image;
            _imagePresenter     = ImagePresenter.CreateFromSurfaceImageSource(image, graphicsDevice, (int)previewProps.Width, (int)previewProps.Height);

            TextLog.Text += "Creating MediaSamplePresenter from SwapChainPanel\n";

            _swapChainPresenter = ImagePresenter.CreateFromSwapChainPanel(
                SwapChainPreview,
                graphicsDevice,
                (int)previewProps.Width,
                (int)previewProps.Height
                );

            TextLog.Text += "Creating MediaReader\n";

            _mediaReader = await MediaReader.CreateFromMediaCaptureAsync(_capture, AudioInitialization.Deselected, VideoInitialization.Bgra8);

            TextLog.Text += "Starting video loop\n";

            var ignore = Task.Run(() => VideoLoop());
        }
Ejemplo n.º 2
0
        public async Task CS_W_MediaReader_IpCam()
        {
            using (var source = await HttpMjpegCaptureSource.CreateFromUriAsync("http://216.123.238.208/axis-cgi/mjpg/video.cgi?camera&resolution=640x480"))
                using (var mediaReader = await MediaReader.CreateFromMediaSourceAsync(source.Source))
                    using (var result = await mediaReader.VideoStream.ReadAsync())
                    {
                        // Save the file
                        var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MediaCaptureReaderTests", CreationCollisionOption.OpenIfExists);

                        var file = await folder.CreateFileAsync("CS_W_MediaReader_IpCam.jpg", CreationCollisionOption.ReplaceExisting);

                        await((MediaSample2D)result.Sample).SaveToFileAsync(file, ImageCompression.Jpeg);
                        Logger.LogMessage("Saved {0}", file.Path);
                    }
        }
        async void Source_KeyUp(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key != VirtualKey.Enter)
            {
                return;
            }

            Log.Text += String.Format("Opening {0}\n", Source.Text);
            try
            {
                var client = await HttpMjpegCaptureSource.CreateFromUriAsync(Source.Text);

                Preview.SetMediaStreamSource(client.Source);
            }
            catch
            {
                Log.Text += " Failed to initiate MJPEG camera playback\n";
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // Start the camera and open a HTTP listener on port 31415
            m_server = await CameraServer.CreateAsync(31415);

            foreach (IPAddress ip in m_server.IPAddresses)
            {
                Log.Text += String.Format("Server IP address: {0} {1}\n", ip.Type.ToString(), ip.Name);
            }

            // Start an HTTP client, connect to port 31415, and display the video
            var client = await HttpMjpegCaptureSource.CreateFromUriAsync("http://localhost:31415/");

            Source.KeyUp += Source_KeyUp;

            // Log video playback events
            Preview.MediaFailed         += Preview_MediaFailed;
            Preview.MediaEnded          += Preview_MediaEnded;
            Preview.MediaOpened         += Preview_MediaOpened;
            Preview.CurrentStateChanged += Preview_CurrentStateChanged;

            // Start playback
            Preview.SetMediaStreamSource(client.Source);
        }