Beispiel #1
0
        /// <summary>
        /// Stops the decoding process. If the decoder is not running
        /// this does nothing.
        /// </summary>
        public void StopDecoding()
        {
            if (!IsDecoding)
            {
                return;
            }

            lock (this)
            {
                started = false;
            }

            // Give any currently running threads a chance to break
            encodedBuffers.Clear();
            decodedBuffers.Clear();

            try
            {
                process.StandardError.Close();
                process.StandardInput.Close();
                process.StandardOutput.Close();
                process.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            process = null;

            if (readThread != null)
            {
                readThread.Stop();
                readThread = null;
            }

            if (writeThread != null)
            {
                writeThread.Stop();
                writeThread = null;
            }

            if (errorThread != null)
            {
                errorThread.Stop();
                errorThread = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Starts the decoding process
        /// </summary>
        public void StartDecoding()
        {
            if (IsDecoding)
            {
                return;
            }

            lock (this)
            {
                started = true;
            }

            totalBytes = 0;

            // Create new buffer pools in case old threads are still doing things
            encodedBuffers = new BufferPool();
            decodedBuffers = new BufferPool();

            process = new Process();
            process.StartInfo.Arguments = GetFFMpegArguments();
            process.StartInfo.FileName = ffmpeg.Path;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.Start();

            readThread = new VideoDecoderReadThread(this, process, decodedBuffers);
            writeThread = new VideoDecoderWriteThread(this, process, encodedBuffers);
            errorThread = new VideoDecoderErrorThread(this, process);

            errorThread.Start();
            readThread.Start();
            writeThread.Start();
        }