示例#1
0
        private void Execute(string arguments)
        {
            string ffmpegpath = System.IO.Path.Combine(FFMpegSettings.Location, "ffmpeg.exe");

            var result = _shellExecutableFactory
                         .Get(ffmpegpath, arguments)
                         .Execute();
        }
        public VideoMetadata GetMetaData(string filePath)
        {
            CleanTemporaryFolder();

            string ffprobePath = System.IO.Path.Combine(_options.Location, "ffprobe.exe");
            string args        = $"-v quiet -print_format json -show_format -show_streams -show_chapters -i \"{filePath}\"";

            var results = _shellExecutableFactory
                          .Get(ffprobePath, args, true, true)
                          .Execute();

            string fileName   = System.IO.Path.GetFileNameWithoutExtension(filePath);
            string outputPath = System.IO.Path.Combine(_options.TemporaryOutputLocation, "output.json");

            //string outputPath = System.IO.Path.Combine(_options.TemporaryOutputLocation, $"{fileName}.json");
            System.IO.File.WriteAllText(outputPath, results.Output);

            var metadata = Newtonsoft.Json.JsonConvert.DeserializeObject <VideoMetadata>(results.Output);

            // ensure at least 1 chapter
            if (metadata.Chapters.Length == 0)
            {
                Dictionary <string, string> tags = new Dictionary <string, string>();
                tags["title"] = "video";

                metadata.Chapters = new Chapter[]
                {
                    new Chapter()
                    {
                        EndTime   = metadata.Format.Duration,
                        StartTime = metadata.Format.StartTime,
                        Tags      = tags
                    }
                };
            }

            // check to cut-in and cut-out if necessary
            if (metadata.Chapters.Length >= 0)
            {
                if (CutInTime > 0 && string.Compare(metadata.Chapters.First().Tags["title"], "video", true) == 0)
                {
                    var chapter = metadata.Chapters.First();
                    chapter.StartTime += CutInTime;
                }
                if (CutOutTime > 0 && string.Compare(metadata.Chapters.Last().Tags["title"], "video", true) == 0)
                {
                    var chapter = metadata.Chapters.Last();
                    chapter.EndTime -= CutOutTime;
                }
            }

            return(metadata);
        }