示例#1
0
        public static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
              {
            ArgList.WriteDescription();
            return;
              }

              ArgList.Parse(args);

              if (ArgList.Get(Arg.INSTALL))
              {
            FfmpegLoader loader = new FfmpegLoader();
            Task.WaitAll(loader.Install());
            return;
              }

              if (ArgList.Get(Arg.YOUTUBE))
              {
            DownloadVideo();
            return;
              }

              string filePath = ArgList.Get(Arg.FILE).AsString();
              string subPath = ArgList.Get(Arg.SUBS).AsString();
              filePath = GetFullPath(filePath);

              if (ArgList.Get(Arg.GENERATE_TIMING))
              {
            string gentfile = null;
            if (ArgList.Get(Arg.GENERATE_T_FILE))
              gentfile = Path.Combine(GetFolder(filePath), ArgList.Get(Arg.GENERATE_T_FILE).Value);
            TimingGenerator tg = new TimingGenerator(filePath, gentfile);
            tg.Generate(true);
            return;
              }

              if (filePath.EndsWith(".webm") && ArgList.Get(Arg.PREVIEW))
              {
            GeneratePreview(filePath);
            return;
              }

              if (ArgList.Get(Arg.TIMINGS))
              {
            string[] lines = File.ReadAllLines(GetFullPath(ArgList.Get(Arg.TIMINGS).AsString()));
            ushort[] indexes = null;
            if (ArgList.Get(Arg.TIMINGS_INDEX))
              indexes = ArgList.Get(Arg.TIMINGS_INDEX).AsString().Split(',').Select(x => ushort.Parse(x)).ToArray();
            else
            {
              ushort i = 0;
              indexes = lines.Select(x => i++).ToArray();
            }
            Action<int> startEncodeTiming = (index) =>
            {
              Console.WriteLine("Start encode timing file {0} line", index);
              string[] splitted = lines[index].Split(' ');
              if (splitted.Length >= 2)
              {
            ushort crf = ArgList.Get(Arg.CRF_MODE) ? ushort.Parse(ArgList.Get(Arg.CRF_MODE).Value) : (ushort)0;
            TimeSpan start = ParseToTimespan(splitted[0]), end = ParseToTimespan(splitted[1]);
            start += ParseToTimespan(ArgList.Get(Arg.TIMINGS_DELTA).AsString());
            if (ArgList.Get(Arg.AUTOLIMIT))
              if (crf != 0)
                CrfLookupEncode(crf, (newCrf) => { return Encode(index, filePath, subPath, start, end, 0, newCrf); }, GetSizeMB);
              else
                BitrateLookupEncode((newTarget) => { return Encode(index, filePath, subPath, start, end, newTarget, 0); }, GetSizeKB);
            else
              Encode(index, filePath, subPath, start, end, ArgList.Get(Arg.LIMIT).AsInt(), 0);
              }
            };
            Parallel.ForEach(indexes, new ParallelOptions
            { MaxDegreeOfParallelism = ArgList.Get(Arg.SINGLE_THREAD) ? Math.Max(1, Environment.ProcessorCount - 1) : Math.Max(1, Environment.ProcessorCount / 2) },
              (singleIndex) =>
            {
              if (lines.Length > singleIndex && singleIndex >= 0)
            startEncodeTiming(singleIndex);
            });
              }
              else
              {
            LookupEndTime(filePath);
            if (ArgList.Get(Arg.END_TIME))
            {
              ushort crf = ArgList.Get(Arg.CRF_MODE) ? ushort.Parse(ArgList.Get(Arg.CRF_MODE).Value) : (ushort)0;
              TimeSpan start = ArgList.Get(Arg.START_TIME).AsTimeSpan(), end = ArgList.Get(Arg.END_TIME).AsTimeSpan();
              start += ParseToTimespan(ArgList.Get(Arg.TIMINGS_DELTA).AsString());
              if (ArgList.Get(Arg.AUTOLIMIT))
            if (crf != 0)
              CrfLookupEncode(crf, (newCrf) => Encode(DateTime.Now.ToFileTimeUtc(), filePath, subPath, start, end, 0, newCrf), GetSizeMB);
            else
              BitrateLookupEncode((newTarget) => Encode(DateTime.Now.ToFileTimeUtc(), filePath, subPath, start, end, newTarget, 0), GetSizeKB);
              else
            Encode(DateTime.Now.ToFileTimeUtc(), filePath, subPath, start, end, ArgList.Get(Arg.LIMIT).AsInt(), 0);
            }
              }

              MessageBox.Show("OK");
        }
示例#2
0
        public static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                ArgList.WriteDescription();
                return;
            }

            ArgList.Parse(args);

            if (ArgList.Get(Arg.INSTALL))
            {
                FfmpegLoader loader = new FfmpegLoader();
                Task.WaitAll(loader.Install());
                return;
            }

            if (ArgList.Get(Arg.YOUTUBE))
            {
                DownloadVideo();
                return;
            }

            string filePath = ArgList.Get(Arg.FILE).AsString();
            string subPath  = ArgList.Get(Arg.SUBS).AsString();

            filePath = GetFullPath(filePath);

            if (ArgList.Get(Arg.GENERATE_TIMING))
            {
                string gentfile = null;
                if (ArgList.Get(Arg.GENERATE_T_FILE))
                {
                    gentfile = Path.Combine(GetFolder(filePath), ArgList.Get(Arg.GENERATE_T_FILE).Value);
                }
                TimingGenerator tg = new TimingGenerator(filePath, gentfile);
                tg.Generate(true);
                return;
            }

            if (filePath.EndsWith(".webm") && ArgList.Get(Arg.PREVIEW))
            {
                GeneratePreview(filePath);
                return;
            }

            if (ArgList.Get(Arg.TIMINGS))
            {
                string[] lines   = File.ReadAllLines(GetFullPath(ArgList.Get(Arg.TIMINGS).AsString()));
                ushort[] indexes = null;
                if (ArgList.Get(Arg.TIMINGS_INDEX))
                {
                    indexes = ArgList.Get(Arg.TIMINGS_INDEX).AsString().Split(',').Select(x => ushort.Parse(x)).ToArray();
                }
                else
                {
                    ushort i = 0;
                    indexes = lines.Select(x => i++).ToArray();
                }
                Action <int> startEncodeTiming = (index) =>
                {
                    Console.WriteLine("Start encode timing file {0} line", index);
                    string[] splitted = lines[index].Split(' ');
                    if (splitted.Length >= 2)
                    {
                        ushort   crf = ArgList.Get(Arg.CRF_MODE) ? ushort.Parse(ArgList.Get(Arg.CRF_MODE).Value) : (ushort)0;
                        TimeSpan start = ParseToTimespan(splitted[0]), end = ParseToTimespan(splitted[1]);
                        start += ParseToTimespan(ArgList.Get(Arg.TIMINGS_DELTA).AsString());
                        if (ArgList.Get(Arg.AUTOLIMIT))
                        {
                            if (crf != 0)
                            {
                                CrfLookupEncode(crf, (newCrf) => { return(Encode(index, filePath, subPath, start, end, 0, newCrf)); }, GetSizeMB);
                            }
                            else
                            {
                                BitrateLookupEncode((newTarget) => { return(Encode(index, filePath, subPath, start, end, newTarget, 0)); }, GetSizeKB);
                            }
                        }
                        else
                        {
                            Encode(index, filePath, subPath, start, end, ArgList.Get(Arg.LIMIT).AsInt(), 0);
                        }
                    }
                };
                Parallel.ForEach(indexes, new ParallelOptions
                {
                    MaxDegreeOfParallelism = ArgList.Get(Arg.SINGLE_THREAD) ? Math.Max(1, Environment.ProcessorCount - 1) : Math.Max(1, Environment.ProcessorCount / 2)
                },
                                 (singleIndex) =>
                {
                    if (lines.Length > singleIndex && singleIndex >= 0)
                    {
                        startEncodeTiming(singleIndex);
                    }
                });
            }
            else
            {
                LookupEndTime(filePath);
                if (ArgList.Get(Arg.END_TIME))
                {
                    ushort   crf = ArgList.Get(Arg.CRF_MODE) ? ushort.Parse(ArgList.Get(Arg.CRF_MODE).Value) : (ushort)0;
                    TimeSpan start = ArgList.Get(Arg.START_TIME).AsTimeSpan(), end = ArgList.Get(Arg.END_TIME).AsTimeSpan();
                    start += ParseToTimespan(ArgList.Get(Arg.TIMINGS_DELTA).AsString());
                    if (ArgList.Get(Arg.AUTOLIMIT))
                    {
                        if (crf != 0)
                        {
                            CrfLookupEncode(crf, (newCrf) => Encode(DateTime.Now.ToFileTimeUtc(), filePath, subPath, start, end, 0, newCrf), GetSizeMB);
                        }
                        else
                        {
                            BitrateLookupEncode((newTarget) => Encode(DateTime.Now.ToFileTimeUtc(), filePath, subPath, start, end, newTarget, 0), GetSizeKB);
                        }
                    }
                    else
                    {
                        Encode(DateTime.Now.ToFileTimeUtc(), filePath, subPath, start, end, ArgList.Get(Arg.LIMIT).AsInt(), 0);
                    }
                }
            }

            MessageBox.Show("OK");
        }