Пример #1
0
        public void GetFileDuration()
        {
            if (InputFileDurationInSeconds > 0)
            {
                return;
            }

            string tempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".txt");

            string[] args = { InputPath, tempFileName };

            int ret = InteropHelper.Probe(args);

            if (ret == 0)
            {
                Dictionary <string, List <Dictionary <string, string> > > probeInfo = new Dictionary <string, List <Dictionary <string, string> > >();
                string nodeName = null;

                foreach (var line in File.ReadAllLines(tempFileName))
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line[0] == '[')
                    {
                        if (nodeName != null)
                        {
                            nodeName = null;
                        }
                        else
                        {
                            nodeName = line.Substring(1, line.Length - 2);
                            if (!probeInfo.ContainsKey(nodeName))
                            {
                                probeInfo.Add(nodeName, new List <Dictionary <string, string> >());
                            }

                            probeInfo[nodeName].Add(new Dictionary <string, string>());
                        }
                    }
                    else
                    {
                        int eqlIdx = -1;
                        eqlIdx = line.IndexOf('=');

                        if (eqlIdx != -1)
                        {
                            string key = null, value = null;

                            key   = line.Substring(0, eqlIdx);
                            value = line.Substring(eqlIdx + 1, line.Length - (eqlIdx + 1));

                            probeInfo[nodeName][probeInfo[nodeName].Count - 1].Add(key, value);
                        }
                    }
                }

                TimeSpan ts;
                if (!probeInfo.ContainsKey("FORMAT") || !probeInfo["FORMAT"][0].ContainsKey("duration") || !TimeSpan.TryParse(probeInfo["FORMAT"][0]["duration"], out ts))
                {
                    throw new ApplicationException("Unable to probe input file format and retrieve its duration.");
                }

                this.InputFileDurationInSeconds = (int)ts.TotalSeconds;
            }
        }
Пример #2
0
        private void SegmentHlsStream()
        {
            var options = EncodingProcess.Current.SegmentOptions;

            InteropHelper.Segment(options.ToStringArray());
        }