public static void Main( string[] args ) { // Print Dependencies. //DependenciesDisplayer.PrintDependencies(typeof(TakToBvhBatch).Assembly); string logFilePath = Path.GetFullPath(@".\TakToBvhBatch.log"); using (StreamWriter loger = new StreamWriter(logFilePath)) { int loadingErros = 0; int bvhExportErrors = 0; int videoExportErrors = 0; // Select Directory containing Takes. string takeFileDirectory = SelectTakesRootDirectory(); if (Directory.Exists(takeFileDirectory)) { // Create take processors : to trajectorize, fill gaps, filter. IEnumerable<TakeProcessor> takeProcessors = CreateTakeProcessors(); // Exporters BVHExporter bvhExporter = CreateBVHExporter(); VideoExporter videoExporter = new VideoExporter(); // Process each take. IEnumerable<string> takeFiles = Directory.EnumerateFiles(takeFileDirectory, "*.tak", SearchOption.AllDirectories); foreach (string takeFile in takeFiles) { string takeFileFullPath = Path.GetFullPath(takeFile); Log(loger, string.Format("==> Loading take : {0}", takeFileFullPath)); Take take = null; try { take = new Take(takeFileFullPath); } catch (Exception e) { Log(loger, String.Format("\tError : failed to load take {0}: {1}", takeFileFullPath, e.Message)); ++loadingErros; } if(take != null) { Log(loger, "\t==> Take loaded successfully !"); int bvhExportEr = 0; if (ExportBVHs(take, takeProcessors, bvhExporter, loger, ref bvhExportEr)) { videoExportErrors += ExportVideo(take, videoExporter, loger); } bvhExportErrors += bvhExportEr; // Takes can use a lot of memory. Might not want to wait around for the garbage collector to do its clean up. take.Dispose(); } Log(loger, "\n================================================================================"); } } else { Log(loger, "No Directory selected ! Abort..."); } int totalErrors = loadingErros + bvhExportErrors + videoExportErrors; if (totalErrors > 0) { Log(loger, "==> Batch finished !"); Log(loger, string.Format("{0} Take Load Error(s)", loadingErros)); Log(loger, string.Format("{0} BVH Export Error(s)", bvhExportErrors)); Log(loger, string.Format("{0} Video Export Error(s)", videoExportErrors)); } else { Log(loger, "==> Batch finished with success (no errors) !"); } Console.WriteLine("See {0} for details", logFilePath); Console.WriteLine("\nAppuyer sur Entrée pour quitter..."); Console.ReadLine(); } }
static int ExportVideo(Take pTake, VideoExporter pExporter, StreamWriter pLoger) { int nbErrors = 0; Log(pLoger, "==> Exporting video..."); if (pTake.HasData(Take.DataType.Video)) { string takeDir = Path.GetDirectoryName(pTake.FileName); string videoFilePath = Path.GetFileNameWithoutExtension(pTake.FileName) + "." + pExporter.Extension; videoFilePath = Path.GetFullPath(Path.Combine(takeDir, videoFilePath)); try { //pExporter.FrameRate = VideoExporter.FrameRateValue.Quarter; DataStream videoStream = DataStreamWarehouse.OpenFile(videoFilePath, DataStream.StreamOpenMode.WriteOnly, pExporter.IsBinary); // Works since Motive 1.9.x Result exportResult = pExporter.Export(pTake, videoStream); if (exportResult.Success) { Log(pLoger, String.Format("\t==> Video exported successfully to file {0}", videoFilePath)); } else { Log(pLoger, String.Format("\tError : cannot export Video {0} => {1}", videoFilePath, exportResult.Message)); nbErrors = 1; } //videoStream.Dispose(); } catch (Exception e) { Log(pLoger, String.Format("\tError : cannot export Video {0} => {1}", videoFilePath, e.Message)); nbErrors = 1; } } else { Log(pLoger, "\t==> No video found !"); } return nbErrors; }
void ExportVideo(string testVideo) { VideoExporter exporter = new VideoExporter (FusedSkeleton_FromFile.recordDirectory + "/Videos/"+testVideo,testVideo, videoFrames); // Create the thread object, passing in the Alpha.Beta method // via a ThreadStart delegate. This does not start the thread. Thread oThread = new Thread (new ThreadStart (exporter.ExportVideo)); // Start the thread oThread.Start (); }