private static async void TranscodeVideo(string kdvrFile, string videoFile) { string tempPath = Path.GetTempPath() + Guid.NewGuid(); try { Directory.CreateDirectory(tempPath); using (Stream kdvrStream = File.Open(kdvrFile, FileMode.Open, FileAccess.Read)) { if (kdvrStream == null) { Console.Error.WriteLine("Error opening file {0}", kdvrFile); return; } using (KinectReplay replay = new KinectReplay(kdvrStream)) { if (replay == null || !replay.HasColorFrames) { Console.Error.WriteLine("Error with KDVR file (does it have color frames?)"); return; } Console.WriteLine("Converting {0} to {1}", kdvrFile, videoFile); Console.WriteLine("EXPORTING JPEG IMAGES FROM {0}...", kdvrFile); await replay.ExportColorFramesAsync(tempPath); Console.WriteLine("ENCODING {0}...", videoFile); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = false; startInfo.FileName = "ffmpeg.exe"; startInfo.Arguments = "-framerate 30 -i \"" + tempPath + "\\%06d.jpeg\" \"" + videoFile + "\""; using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit(); } Console.WriteLine("SUCCESS!!!"); } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } finally { Directory.Delete(tempPath, true); } }
async void OpenButton_Click(object sender, RoutedEventArgs e) { if (_replay != null) { if (_replay.IsStarted) _replay.Stop(); _replay.PropertyChanged -= _replay_PropertyChanged; if (_replay.HasBodyFrames) _replay.BodyFrameArrived -= _replay_BodyFrameArrived; if (_replay.HasColorFrames) _replay.ColorFrameArrived -= _replay_ColorFrameArrived; if (_replay.HasDepthFrames) _replay.DepthFrameArrived -= _replay_DepthFrameArrived; if (_replay.HasInfraredFrames) _replay.InfraredFrameArrived -= _replay_InfraredFrameArrived; _replay = null; } var picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".kdvr"); var file = await picker.PickSingleFileAsync(); if (file != null) { _colorBitmap = null; // reset to force recreation for new file OutputCombo.Items.Clear(); _replay = new KinectReplay(await file.OpenStreamForReadAsync()); _replay.PropertyChanged += _replay_PropertyChanged; if (_replay.HasBodyFrames) { _replay.BodyFrameArrived += _replay_BodyFrameArrived; OutputCombo.Items.Add("Body"); } if (_replay.HasColorFrames) { _replay.ColorFrameArrived += _replay_ColorFrameArrived; OutputCombo.Items.Add("Color"); } if (_replay.HasDepthFrames) { _replay.DepthFrameArrived += _replay_DepthFrameArrived; OutputCombo.Items.Add("Depth"); } if (_replay.HasInfraredFrames) { _replay.InfraredFrameArrived += _replay_InfraredFrameArrived; OutputCombo.Items.Add("Infrared"); } if (OutputCombo.Items.Count > 0) { OutputCombo.SelectedIndex = 0; LocationSlider.Maximum = _replay.Duration.TotalMilliseconds; LocationSlider.TickFrequency = 1000; LocationSlider.SmallChange = 1000; } else { PlayButton.IsEnabled = false; } } }
void OpenButton_Click(object sender, RoutedEventArgs e) { if (_replay != null) { if (_replay.IsStarted) _replay.Stop(); _replay.PropertyChanged -= _replay_PropertyChanged; if (_replay.HasBodyFrames) _replay.BodyFrameArrived -= _replay_BodyFrameArrived; if (_replay.HasColorFrames) _replay.ColorFrameArrived -= _replay_ColorFrameArrived; if (_replay.HasDepthFrames) _replay.DepthFrameArrived -= _replay_DepthFrameArrived; if (_replay.HasInfraredFrames) _replay.InfraredFrameArrived -= _replay_InfraredFrameArrived; _replay = null; } var dlg = new OpenFileDialog() { DefaultExt = ".kdvr", Filter = "KinectEx.DVR Files (*.kdvr)|*.kdvr" }; if (dlg.ShowDialog().GetValueOrDefault()) { _colorBitmap = null; // reset to force recreation for new file OutputCombo.Items.Clear(); _replay = new KinectReplay(File.Open(dlg.FileName, FileMode.Open, FileAccess.Read)); _replay.PropertyChanged += _replay_PropertyChanged; if (_replay.HasBodyFrames) { _replay.BodyFrameArrived += _replay_BodyFrameArrived; OutputCombo.Items.Add("Body"); } if (_replay.HasColorFrames) { _replay.ColorFrameArrived += _replay_ColorFrameArrived; OutputCombo.Items.Add("Color"); } if (_replay.HasDepthFrames) { _replay.DepthFrameArrived += _replay_DepthFrameArrived; OutputCombo.Items.Add("Depth"); } if (_replay.HasInfraredFrames) { _replay.InfraredFrameArrived += _replay_InfraredFrameArrived; OutputCombo.Items.Add("Infrared"); } if (OutputCombo.Items.Count > 0) { OutputCombo.SelectedIndex = 0; } else { PlayButton.IsEnabled = false; } } }