コード例 #1
0
        public static async Task VideoToFrames(string inputFile, string framesDir, bool alpha, float rate, bool deDupe, bool delSrc, Size size)
        {
            Logger.Log("Extracting video frames from input video...");
            string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";

            IOUtils.CreateDir(framesDir);
            string  timecodeStr = /* timecodes ? $"-copyts -r {FrameOrder.timebase} -frame_pts true" : */ "-frame_pts true";
            string  mpStr       = deDupe ? ((Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr) : "";
            string  filters     = FormatUtils.ConcatStrings(new string[] { GetPadFilter(), mpStr });
            string  vf          = filters.Length > 2 ? $"-vf {filters}" : "";
            string  rateArg     = (rate > 0) ? $" -r {rate.ToStringDot()}" : "";
            string  pixFmt      = alpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
            string  args        = $"{rateArg} {GetTrimArg(true)} -i {inputFile.Wrap()} {compr} -vsync 0 {pixFmt} {timecodeStr} {vf} {sizeStr} {GetTrimArg(false)} \"{framesDir}/%{Padding.inputFrames}d.png\"";
            LogMode logMode     = Interpolate.currentInputFrameCount > 50 ? LogMode.OnlyLastLine : LogMode.Hidden;

            await RunFfmpeg(args, logMode, TaskType.ExtractFrames, true);

            int amount = IOUtils.GetAmountOfFiles(framesDir, false, "*.png");

            Logger.Log($"Extracted {amount} {(amount == 1 ? "frame" : "frames")} from input.", false, true);
            await Task.Delay(1);

            if (delSrc)
            {
                DeleteSource(inputFile);
            }
        }
コード例 #2
0
        public static async Task ImportImages(string inpath, string outpath, bool alpha, Size size, bool delSrc = false, bool showLog = true)
        {
            if (showLog)
            {
                Logger.Log("Importing images...");
            }
            Logger.Log($"Importing images from {inpath} to {outpath}.", true);
            IOUtils.CreateDir(outpath);
            string concatFile = Path.Combine(Paths.GetDataPath(), "png-concat-temp.ini");

            GetConcatFile(inpath, concatFile);

            string  sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
            string  pixFmt  = alpha ? "-pix_fmt rgba" : "-pix_fmt rgb24";  // Use RGBA for GIF for alpha support
            string  vf      = alpha ? $"-filter_complex \"[0:v]{GetPadFilter()},split[a][b];[a]palettegen=reserve_transparent=on:transparency_color=ffffff[p];[b][p]paletteuse\"" : $"-vf {GetPadFilter()}";
            string  args    = $"-f concat -safe 0 -i {concatFile.Wrap()} {compr} {sizeStr} {pixFmt} -vsync 0 {vf} \"{outpath}/%{Padding.inputFrames}d.png\"";
            LogMode logMode = IOUtils.GetAmountOfFiles(inpath, false) > 50 ? LogMode.OnlyLastLine : LogMode.Hidden;

            await RunFfmpeg(args, logMode, "panic", TaskType.ExtractFrames);

            if (delSrc)
            {
                DeleteSource(inpath);
            }
        }
コード例 #3
0
        public static async Task RunAi(string outpath, AI ai, bool stepByStep = false)
        {
            Program.mainForm.SetStatus("Downloading models...");
            await ModelDownloader.DownloadModelFiles(ai.pkgDir, current.model);

            if (canceled)
            {
                return;
            }

            currentlyUsingAutoEnc = Utils.CanUseAutoEnc(stepByStep, current);

            IOUtils.CreateDir(outpath);

            List <Task> tasks = new List <Task>();

            if (ai.aiName == Networks.rifeCuda.aiName)
            {
                tasks.Add(AiProcess.RunRifeCuda(current.framesFolder, current.interpFactor, current.model));
            }

            if (ai.aiName == Networks.rifeNcnn.aiName)
            {
                tasks.Add(AiProcess.RunRifeNcnn(current.framesFolder, outpath, (int)current.interpFactor, current.model));
            }

            if (ai.aiName == Networks.flavrCuda.aiName)
            {
                tasks.Add(AiProcess.RunFlavrCuda(current.framesFolder, current.interpFactor, current.model));
            }

            if (ai.aiName == Networks.dainNcnn.aiName)
            {
                tasks.Add(AiProcess.RunDainNcnn(current.framesFolder, outpath, current.interpFactor, current.model, Config.GetInt("dainNcnnTilesize", 512)));
            }

            if (currentlyUsingAutoEnc)
            {
                Logger.Log($"{Logger.GetLastLine()} (Using Auto-Encode)", true);
                tasks.Add(AutoEncode.MainLoop(outpath));
            }

            Program.mainForm.SetStatus("Running AI...");
            await Task.WhenAll(tasks);
        }
コード例 #4
0
        static async Task CopyOutputFrames(string framesPath, string folderName, bool dontMove)
        {
            Program.mainForm.SetStatus("Copying output frames...");
            string copyPath = Path.Combine(I.current.outPath, folderName);

            Logger.Log($"Moving output frames to '{copyPath}'");
            IOUtils.TryDeleteIfExists(copyPath);
            IOUtils.CreateDir(copyPath);
            Stopwatch sw = new Stopwatch();

            sw.Restart();

            string vfrFile = Path.Combine(framesPath.GetParentDir(), Paths.GetFrameOrderFilename(I.current.interpFactor));

            string[] vfrLines = IOUtils.ReadLines(vfrFile);

            for (int idx = 1; idx <= vfrLines.Length; idx++)
            {
                string line        = vfrLines[idx - 1];
                string inFilename  = line.Split('/').Last().Remove("'").RemoveComments();
                string framePath   = Path.Combine(framesPath, inFilename);
                string outFilename = Path.Combine(copyPath, idx.ToString().PadLeft(Padding.interpFrames, '0')) + Path.GetExtension(framePath);

                if (dontMove || ((idx < vfrLines.Length) && vfrLines[idx].Contains(inFilename)))   // If file is re-used in the next line, copy instead of move
                {
                    File.Copy(framePath, outFilename);
                }
                else
                {
                    File.Move(framePath, outFilename);
                }

                if (sw.ElapsedMilliseconds >= 500 || idx == vfrLines.Length)
                {
                    sw.Restart();
                    Logger.Log($"Moving output frames to '{Path.GetFileName(copyPath)}' - {idx}/{vfrLines.Length}", false, true);
                    await Task.Delay(1);
                }
            }
        }
コード例 #5
0
        //public async Task<IHttpActionResult> Get() {
        //    return Ok("成功");
        //}


        public async Task <IHttpActionResult> Post([FromBody] N_BuildPostVm model)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("请求参数不正确");
            }
            Dictionary <string, object> _dictData = new Dictionary <string, object>();

            _dictData.Add("TimeStamp", model.TimeStamp);
            _dictData.Add("Url", model.Url);
            _dictData.Add("ProjectId", model.ProjectId);
            _dictData.Add("Unit", model.Unit);
            var _sign = SignData.Md5SignDict("1234567890", _dictData);

            if (_sign != model.Sign)
            {
                throw new Exception("签名不正确");
            }

            //验证通过,下载Qiniu上面的zip文件
            string    _savePath   = Path.Combine(Constants.Temp, Path.GetFileName(model.Url));
            WebClient myWebClient = new WebClient();

            myWebClient.DownloadFile(model.Url, _savePath);

            //判断文件是否存在
            if (!IOUtils.FileExists(_savePath))
            { //表示文件下载失败
                throw new Exception(model.Url + " 下载失败");
            }

            //解压文件
            ZipFile.ExtractToDirectory(_savePath, Constants.Temp);

            //删除zip文件
            FileUtils.DeleteFile(_savePath);

            string _sourcePath = Path.Combine(Constants.Temp, model.ProjectId, model.Unit);
            string _targetPath = Path.Combine(Constants.RootPath, model.ProjectId, model.Unit);

            if (!IOUtils.DirExists(_targetPath))
            {
                IOUtils.CreateDir(_targetPath);
            }

            FileUtils.CopyDir(_sourcePath, _targetPath);

            FileUtils.DeleteDir(Path.Combine(Constants.Temp, model.ProjectId));

            //判断是否存在build.sh脚本文件,如果有就执行
            string shellFilePath = Path.Combine(_targetPath, Constants.ScripteFile);

            if (IOUtils.FileExists(shellFilePath))
            {
                int _code = CMDUtils.Execute(shellFilePath);
                if (_code == 0)
                {
                    //_logEngin.Debug("build " + _slnFile + " Success");
                }
                else
                {
                    //_logEngin.Debug("build " + _slnFile + " Fail");
                }
            }

            return(Ok());
        }