static void Main(string[] args) { Logging log = new Logging(); try { Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; Logging.WriteLog("Starting.."); Console.WriteLine("Source Folder: "); string sourceDir = Console.ReadLine(); // ex: C:\Users\alayedm\Videos if (Directory.Exists(sourceDir)) { Logging.WriteLog($"Source folder is: {sourceDir}"); Console.WriteLine("Distination Folder: "); string distDir = Console.ReadLine(); // ex: C:\inetpub\wwwroot\videos if (Directory.Exists(distDir)) { Logging.WriteLog($"Distination folder is: {distDir}"); DirectoriesHandler dh = new DirectoriesHandler(sourceDir, distDir); dh.CreateDirectories(); // Create all folders in distination lib. (can add a check if they're actually created) VideosHandler vh = new VideosHandler(sourceDir, distDir); vh.HandleVideoFiles(); // Transcode videos then place them in newly created folders. } else { throw new DirectoryNotFoundException(); } } else { throw new DirectoryNotFoundException(); } } catch (Exception ex) { Console.WriteLine(ex.Message); Logging.WriteLog(ex.Message); } }
static Task <int> Transcode(string fileName, string filePath, string newPath, string ext, int width, int height, string speed, bool isLong) { try { var tcs = new TaskCompletionSource <int>(); newPath += $@"\{ fileName }"; var process = new Process { StartInfo = { FileName = "ffmpeg.exe", Arguments = Arguments.GetWMVArgs(newPath, filePath, width, height, ext, speed) }, EnableRaisingEvents = true }; process.Exited += (sender, args) => { tcs.SetResult(process.ExitCode); process.Dispose(); }; if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); Logging.WriteLog($"Folder: {newPath} created."); } else { Logging.WriteLog($"Folder: {newPath} already exists. Moving on."); } DirectoriesHandler.CreateVideoFolders(newPath); Logging.WriteLog($"Created video folders for {newPath}"); process.Start(); string processName = process.ProcessName; Logging.WriteLog($"Started proccess: {processName}"); process.WaitForExit(); Logging.WriteLog($"Exited proccess: {processName}"); return(tcs.Task); } catch (Exception ex) { Logging.WriteLog($"Exception occured: {ex.Message}"); throw ex; } }