Пример #1
0
        //
        //  Methods
        //
        public void ConvertFile(string path, string savedPath, Stream input = null)
        {
            //
            //  Set up filenames
            //
            // string baseXefPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));
            string basePath     = savedPath;
            string rgbVideoPath = basePath + "_RGB.mp4";
            string wavAudioPath = basePath + "_Audio.wav";
            // string fulVideoPath = basePath + "_Video.avi"; // remove the .avi video file output;
            string skeletonPath = basePath + "_Skeleton.csv";
            string depthDatPath = basePath + "_Depth.dat";  // .dat file for depth sensor file output;

            bool videoFlag    = UseVideo;
            bool skeletonFlag = UseSkeleton;
            bool depthFlag    = UseDepth;
            bool audioFlag    = UseAudio;

            // Check if files exist (disable flags if found)
            if (ResumeConversion)
            {
                if (File.Exists(rgbVideoPath))
                {
                    videoFlag = false;
                }
                if (File.Exists(skeletonPath))
                {
                    skeletonFlag = false;
                }
                if (File.Exists(depthDatPath))
                {
                    depthFlag = false;
                }
                if (File.Exists(wavAudioPath))
                {
                    audioFlag = false;
                }
            }
            // Start parsing events
            try
            {
                //
                //  Set up XEF data converters/writers
                //
                List <IXEFDataWriter> dataWriters = new List <IXEFDataWriter>();

                if (videoFlag)
                {
                    int fpsValue;
                    fpsValue = ext.FpsSetting();
                    dataWriters.Add(new XEFColorWriter(rgbVideoPath, fpsValue));
                }
                if (audioFlag)
                {
                    dataWriters.Add(new XEFAudioWriter(wavAudioPath));
                }
                if (skeletonFlag)
                {
                    dataWriters.Add(new XEFBodyWriter(skeletonPath));
                }
                if (depthFlag)
                {
                    dataWriters.Add(new XEFDepthWriter(depthDatPath));
                }
                if (dataWriters.Count == 0)
                {
                    ext.MessageShowing("Skipped: " + basePath + ".\n");
                    return;
                }

                //
                //  Process events
                //

                using (IEventReader reader = (input == null) ? new XEFEventReader(path) : new XEFEventStreamReader(input) as IEventReader)
                {
                    XEFEvent ev;
                    while ((ev = reader.GetNextEvent()) != null)
                    {
                        foreach (IXEFDataWriter dataWriter in dataWriters)
                        {
                            dataWriter.ProcessEvent(ev);
                        }
                    }
                }
                //
                //  Finalization
                //
                foreach (IXEFDataWriter dataWriter in dataWriters)
                {
                    dataWriter.Close();
                }

                if (videoFlag)  // 当开始提取视频格式的时候,将会执行FFMPEG command
                {
                    // First determine if there were any audio events processed
                    bool containsAudio = false;
                    foreach (IXEFDataWriter dataWriter in dataWriters)
                    {
                        if (dataWriter.GetType() == typeof(XEFAudioWriter))
                        {
                            containsAudio = dataWriter.EventCount > 0;
                        }
                    }
                    // Mux color and audio files into one video file
                    using (Process ffmpegProc = new Process())
                    {
                        ffmpegProc.StartInfo = new ProcessStartInfo()
                        {
                            // CreateNoWindow = false,
                            FileName  = "ffmpeg",
                            Arguments =
                                $"-v quiet " +
                                $"-i \"{rgbVideoPath}\" " +
                                (containsAudio ? $"-i \"{wavAudioPath}\" " : "") +
                                $"-codec copy " +
                                $"-shortest " +
                                $"-y ",
                            UseShellExecute = false,
                            CreateNoWindow  = false,
                        };
                        ffmpegProc.Start();
                        ffmpegProc.WaitForExit();
                    }
                }
            }
            catch (Exception)
            {
                ext.MessageShowing("Error processing file!");
                ext.MessageShowing("Exception thrown!");
                return;
            }
        }