private void ParseOutputStream(Stream stdoutStream, Reference<WebTranscodingInfo> data, int startPosition, bool logProgress)
        {
            StreamReader reader = new StreamReader(stdoutStream);
            TranscodingInfoCalculator calculator = new TranscodingInfoCalculator(position, 25, 500, info.Duration); //VLCWrapper prints twice a second

            bool aborted = false;
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                try
                {
                    Log.Trace("VLCWrapperParsing: read line {0}", line);

                    // just for debugging of the wrapper tool
                    if(line.StartsWith("A") || line.StartsWith("I") || line == "S started" || line == "S null")
                        continue;

                    // propagate start event to Start() method
                    if (line == "S playing")
                    {
                        vlcIsStarted = true;
                        continue;
                    }

                    // events
                    if (line == "S error")
                    {
                        vlcIsStarted = true;
                        data.Value.Finished = true;
                        data.Value.Failed = true;
                        break;
                    }

                    if (line == "S finished")
                    {
                        data.Value.Failed = false;
                        data.Value.Finished = true;
                        continue;
                    }

                    // the actual progress parsing
                    if(line.StartsWith("P"))
                    {
                        // the format is 'P [time in microseconds] [percentage of file]'. Sadly we can't use the way more detailed time in microseconds
                        // because the VLC guys decided it would be a good idea to convert it to a 32-bit integer before returning it, as opposed to
                        // returning libvlc_time_t or a int64_t. And since it's in microseconds it gets big very fast, so it's absolutely useless.
                        double percentage = Double.Parse(line.Substring(line.IndexOf(",") + 2), CultureInfo.InvariantCulture);
                        calculator.NewPercentage(percentage);
                        calculator.SaveStats(data);
                        continue;
                    }

                    Log.Warn("VLCWrapperParsing: encountered unknown line {0}", line);
                }
                catch (ThreadAbortException)
                {
                    aborted = true;
                    break;
                }
                catch (Exception e)
                {
                    Log.Error("Failure during parsing of VLC output", e);
                }
            }

            data.Value.Failed = aborted;
            data.Value.Finished = true;
            reader.Close();
            return;
        }
        private void ParseOutputStream(Stream stdoutStream, Reference<WebTranscodingInfo> data, bool logProgress, int position)
        {
            StreamReader reader = new StreamReader(stdoutStream);
            TranscodingInfoCalculator calculator = new TranscodingInfoCalculator(position * 1000, 25, 500, info.Duration); //VLCWrapper prints twice a second

            bool aborted = false;
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                try
                {
                    // just for debugging of the wrapper tool
                    if(line.StartsWith("A") || line == "S started" || line == "S null")
                        continue;

                    // propagate start event to Start() method
                    if (line == "S playing")
                    {
                        vlcIsStarted = true;
                        continue;
                    }

                    // events
                    if (line == "S error")
                    {
                        vlcIsStarted = true;
                        data.Value.Finished = true;
                        data.Value.Failed = true;
                        break;
                    }

                    if (line == "S finished")
                    {
                        data.Value.Failed = false;
                        data.Value.Finished = true;
                        continue;
                    }

                    // the actual progress parsing
                    if(line.StartsWith("P"))
                    {
                        int msecs = Int32.Parse(line.Substring(2, line.IndexOf(",") - 2)) / 1000;
                        if (msecs != 0)
                        {
                            calculator.NewTime(msecs);
                        }
                        else
                        {
                            double percentage = Double.Parse(line.Substring(line.IndexOf(",") + 2), CultureInfo.InvariantCulture);
                            calculator.NewPercentage(percentage);
                        }
                        calculator.SetStats(data);
                        continue;
                    }

                    Log.Warn("VLCWrapperParsing: encountered unknown line {0}", line);
                }
                catch (ThreadAbortException)
                {
                    aborted = true;
                    break;
                }
                catch (Exception e)
                {
                    Log.Error("Failure during parsing of VLC output", e);
                }
            }

            data.Value.Failed = aborted;
            data.Value.Finished = true;
            reader.Close();
            return;
        }