Esempio n. 1
0
        private void ExtractTracksWorker(String SourceVideo, String ExtractPath, List<Track> Tracks, AsyncContext Context, out bool Cancelled)
        {
            StringBuilder Args = new StringBuilder();
            Args.Append("tracks " + SourceVideo + " ");
            Files = new List<string>();
            foreach (Track T in Tracks)
            {
                String Extension;
                switch (T.Codec)
                {
                    case "A_AC3":
                        Extension = "ac3";
                        break;
                    case "V_MPEG4/ISO/AVC":
                        Extension = "h264";
                        break;
                    default:
                        Extension = "track";
                        break;
                }
                String FileName = ExtractPath + "\\" + T.Number.ToString() + "." + Extension;
                Args.Append(T.Number.ToString() + ":" + "\"" + FileName + "\"" + " ");
                Files.Add(FileName);
            }

            RunExternalProcess(Args.ToString(), Context, out Cancelled, new DataReceivedEventHandler(MkvExtractProcess_OutputDataReceived));
        }
Esempio n. 2
0
        public void CombineWorker(List<String> Files, String OutputFile, AsyncContext Context, out bool Cancelled)
        {
            StringBuilder Args = new StringBuilder();
            TotalTracks = Files.Count;
            foreach (String File in Files)
            {
                Args.Append("-add \"" + File + "\" ");
            }
            Args.Append("\"" + OutputFile + "\"");

            RunExternalProcess(Args.ToString(), Context, out Cancelled, new DataReceivedEventHandler(MP4BoxProcess_OutputDataReceived));
        }
Esempio n. 3
0
        public void CombineAsync(List<String> Files, String OutputFile)
        {
            CombineWorkerDelegate worker = new CombineWorkerDelegate(CombineWorker);
            AsyncCallback completedCallback = new AsyncCallback(TaskCompletedCallback);

            lock (_sync)
            {
                if (_isRunning)
                    throw new InvalidOperationException("The control is currently busy.");

                async = AsyncOperationManager.CreateOperation(null);
                AsyncContext Context = new AsyncContext();
                bool Cancelled;
                worker.BeginInvoke(Files, OutputFile, Context, out Cancelled, completedCallback, async);
                _context = Context;
                _isRunning = true;
            }
        }
Esempio n. 4
0
        public void EncodeAsync(String SourceFile, String DestinationFile)
        {
            EncodeWorkerDelegate worker = new EncodeWorkerDelegate(EncodeWorker);
            AsyncCallback completedCallback = new AsyncCallback(TaskCompletedCallback);

            lock (_sync)
            {
                if (_isRunning)
                    throw new InvalidOperationException("The control is currently busy.");

                async = AsyncOperationManager.CreateOperation(null);
                AsyncContext Context = new AsyncContext();
                bool Cancelled;
                worker.BeginInvoke(SourceFile, DestinationFile, Context, out Cancelled, completedCallback, async);
                _context = Context;
                _isRunning = true;
            }
        }
Esempio n. 5
0
        public void ExtractTracksAsync(String SourceVideo, String ExtractPath, List<Track> Tracks)
        {
            ExtractTracksWorkerDelegate worker = new ExtractTracksWorkerDelegate(ExtractTracksWorker);
            AsyncCallback completedCallback = new AsyncCallback(TaskCompletedCallback);

            lock (_sync)
            {
                if (_isRunning)
                    throw new InvalidOperationException("The control is currently busy.");

                async = AsyncOperationManager.CreateOperation(null);
                AsyncContext Context = new AsyncContext();
                bool Cancelled;
                worker.BeginInvoke(SourceVideo, ExtractPath, Tracks, Context, out Cancelled, completedCallback, async);
                _context = Context;
                _isRunning = true;
            }
        }
Esempio n. 6
0
        protected void RunExternalProcess(String Args, AsyncContext Context, out bool Cancelled, DataReceivedEventHandler DataHandler)
        {
            Cancelled = false;
            ProcessStartInfo StartInfo = new ProcessStartInfo();
            StartInfo.CreateNoWindow = true;
            StartInfo.UseShellExecute = false;
            StartInfo.FileName = ProgramPath;
            StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            StartInfo.Arguments = Args.ToString();
            StartInfo.RedirectStandardOutput = true;
            StartInfo.RedirectStandardError = true;

            try
            {
                Process ExtProcess = Process.Start(StartInfo);
                ExtProcess.OutputDataReceived += DataHandler;
                ExtProcess.ErrorDataReceived += DataHandler;
            //                ExtProcess.ErrorDataReceived += new DataReceivedEventHandler(ExtProcess_ErrorDataReceived);
                ExtProcess.BeginErrorReadLine();
                ExtProcess.BeginOutputReadLine();
                while (!ExtProcess.HasExited)
                {
                    if (Context.IsCancelling)
                    {
                        ExtProcess.Kill();
                        ExtProcess.WaitForExit();
                        Cancelled = true;
                        return;
                    }
                    Thread.Sleep(250);
                }

                ExtProcess.WaitForExit();
            }
            catch (Exception E)
            {
                throw E;
            //                Console.WriteLine(E.Message);
            //                Environment.Exit(0);
            }
        }
Esempio n. 7
0
 public void EncodeWorker(String SourceFile, String DestinationFile, AsyncContext Context, out bool Cancelled)
 {
     String Args = "-o \"" + DestinationFile + "\" \"" + SourceFile + "\"";
     RunExternalProcess(Args, Context, out Cancelled, new DataReceivedEventHandler(FaacProcess_OutputDataReceived));
 }
Esempio n. 8
0
        protected void TaskCompletedCallback(IAsyncResult ar)
        {
            bool Cancelled;
            AsyncOperation async = (AsyncOperation)ar.AsyncState;
            TaskCompletedSpecific(ar, out Cancelled);

            // clear the running task flag
            lock (_sync)
            {
                _isRunning = false;
                _context = null;
            }

            // raise the completed event
            AsyncCompletedEventArgs completedArgs = new AsyncCompletedEventArgs(null,
              Cancelled, null);
            async.PostOperationCompleted(
              delegate(object e) { OnTaskCompleted((AsyncCompletedEventArgs)e); },
              completedArgs);
        }
Esempio n. 9
0
        public void DecodeWorker(String SourceFile, String DestinationFile, AsyncContext Context, out bool Cancelled)
        {
            String Args = "-core( -input \"" + SourceFile + "\" -2ch -output \"" + DestinationFile + "\" )";

            RunExternalProcess(Args, Context, out Cancelled, new DataReceivedEventHandler(BesweetProcess_OutputDataReceived));
        }