private async void GenerateStaticHeatmap(object sender, RoutedEventArgs e) { mediaPlayerElement.Source = null; saveCompositionButton.IsEnabled = false; mediaPlayerElement.AreTransportControlsEnabled = false; mediaPlayerElement.Width = 1200; mediaPlayerElement.Height = 600; ShowHeatmapGenerating(); SessionCollection sessionCollection = new SessionCollection(); sessionCollection.sessions = new List <Session>(); var listItems = heatmapSessionsListView.SelectedItems.ToList(); foreach (Session s in listItems) { sessionCollection.sessions.Add(s); } if (_forceFovFlag) { GetForcedFov(); } HeatmapGenerator generator = new HeatmapGenerator(); var result = await generator.GenerateHeatmap ( _scaleFovFlag, _scaleFovInPercentage, _forceFovFlag, _forcedFov, _horizonFlag, sessionCollection, _rect, videoBackgroundPicker.Color, heatmapOpacity.Value / 100, rangeSelector.RangeMin, rangeSelector.RangeMax, _video ); if (_mediaPlayer == null) { _mediaPlayer = new MediaPlayer(); } _mediaPlayer = mediaPlayerElement.MediaPlayer; mediaPlayerElement.Source = MediaSource.CreateFromMediaStreamSource(result); HideHeatmapGenerating(); }
private async void SaveVideo_Click(object sender, RoutedEventArgs e) { TokenSource.Dispose(); TokenSource = new CancellationTokenSource(); Token = TokenSource.Token; var temp = saveResolutionSelector.SelectedItem as Resolutions; var enc = _video.GetVideoEncodingProperties(); MediaEncodingProfile mediaEncoding = GetMediaEncoding(temp, enc); Debug.WriteLine("Vid type: " + enc.Type); Debug.WriteLine("Vid sub: " + enc.Subtype); Debug.WriteLine("Vid id: " + enc.ProfileId); var picker = new Windows.Storage.Pickers.FileSavePicker(); picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary; picker.FileTypeChoices.Add("MP4 files", new List <string>() { ".mp4" }); picker.SuggestedFileName = "RenderedVideo.mp4"; SaveProgressCallback saveProgress = ShowErrorMessage; Windows.Storage.StorageFile file = await picker.PickSaveFileAsync(); if (file != null) { _mediaPlayer.Pause(); ValuePairs.Remove("height"); ValuePairs.Remove("width"); ValuePairs.Add("height", temp.Resolution.Height); ValuePairs.Add("width", temp.Resolution.Width); if (_dotsFlag) { ValuePairs.Remove("dotsRadius"); ValuePairs.Add("dotsRadius", (float)temp.Resolution.Width / 4096 * 20); } if (_horizonFlag) { _composition.OverlayLayers[0] = await GenerateHorizonLayer((int)_video.TrimmedDuration.TotalSeconds, temp.Resolution.Height, temp.Resolution.Width); } //buttonLoadingStop.Visibility = Visibility.Visible; generateVideoButton.IsEnabled = false; saveCompositionButton.IsEnabled = false; HeatmapGenerator generator = new HeatmapGenerator(); generator.RenderCompositionToFile(file, _composition, saveProgress, Window.Current, mediaEncoding, Token, saveResolutionSelector.SelectedItem); } }
private async void VideoGenTest2(object sender, RoutedEventArgs e) { var ep = SetVideoPlayer(); saveCompositionButton.IsEnabled = false; _composition = new MediaComposition(); mediaPlayerElement.Source = null; SessionCollection sessionCollection = new SessionCollection(); sessionCollection.sessions = new List <Session>(); var listItems = heatmapSessionsListView.SelectedItems.ToList(); foreach (Session s in listItems) { sessionCollection.sessions.Add(s); } HeatmapGenerator generator = new HeatmapGenerator(); generator.CheckHistoryErrors(sessionCollection); FillEffectPropertySet(sessionCollection); if (_mediaPlayer == null) { _mediaPlayer = new MediaPlayer(); } var video = await MediaClip.CreateFromFileAsync(_videoFile); MediaOverlayLayer videoOverlayLayer = new MediaOverlayLayer(); TrimVideo(ref video); ValuePairs.Add("offset", video.TrimTimeFromStart.Ticks); var enc = video.GetVideoEncodingProperties(); ValuePairs.Add("frameLength", (1 / ((double)enc.FrameRate.Numerator / enc.FrameRate.Denominator)) * 1000); _composition.Clips.Add(video); if (_horizonFlag) { _composition.OverlayLayers.Add(await GenerateHorizonLayer((int)video.TrimmedDuration.TotalSeconds, ep.Video.Height, ep.Video.Width)); } var videoEffectDefinition = new VideoEffectDefinition("VideoEffectComponent.HeatmapAddVideoEffect", ValuePairs); video.VideoEffectDefinitions.Add(videoEffectDefinition); MediaStreamSource res; try { ValuePairs.Remove("height"); ValuePairs.Remove("width"); ValuePairs.Add("height", ep.Video.Height); ValuePairs.Add("width", ep.Video.Width); res = _composition.GenerateMediaStreamSource(ep); var md = MediaSource.CreateFromMediaStreamSource(res); mediaPlayerElement.Source = md; } catch (Exception f) { Debug.WriteLine(f.Message); } _mediaPlayer = mediaPlayerElement.MediaPlayer; mediaPlayerElement.AreTransportControlsEnabled = true; saveCompositionButton.IsEnabled = true; }