Пример #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 VideoToFrames(string inputFile, string framesDir, bool alpha, Fraction rate, bool deDupe, bool delSrc, Size size, string format)
        {
            Logger.Log("Extracting video frames from input video...");
            Logger.Log($"VideoToFrames() - Alpha: {alpha} - Rate: {rate} - Size: {size} - Format: {format}", true, false, "ffmpeg");
            string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";

            IoUtils.CreateDir(framesDir);
            string  mpStr   = deDupe ? ((Config.GetInt(Config.Key.mpdecimateMode) == 0) ? mpDecDef : mpDecAggr) : "";
            string  filters = FormatUtils.ConcatStrings(new[] { GetPadFilter(), mpStr });
            string  vf      = filters.Length > 2 ? $"-vf {filters}" : "";
            string  rateArg = (rate.GetFloat() > 0) ? $" -r {rate}" : "";
            string  args    = $"{GetTrimArg(true)} -i {inputFile.Wrap()} {GetImgArgs(format, true, alpha)} -vsync 0 {rateArg} -frame_pts 1 {vf} {sizeStr} {GetTrimArg(false)} \"{framesDir}/%{Padding.inputFrames}d{format}\"";
            LogMode logMode = await Interpolate.GetCurrentInputFrameCount() > 50 ? LogMode.OnlyLastLine : LogMode.Hidden;

            await RunFfmpeg(args, logMode, true);

            int amount = IoUtils.GetAmountOfFiles(framesDir, false, "*" + format);

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

            if (delSrc)
            {
                DeleteSource(inputFile);
            }
        }
Пример #3
0
        public static async Task FramesToGifConcat(string framesFile, string outPath, float fps, bool palette, int colors = 64, float resampleFps = -1, LogMode logMode = LogMode.OnlyLastLine)
        {
            if (logMode != LogMode.Hidden)
            {
                Logger.Log((resampleFps <= 0) ? $"Encoding GIF..." : $"Encoding GIF resampled to {resampleFps.ToString().Replace(",", ".")} FPS...");
            }
            string vfrFilename   = Path.GetFileName(framesFile);
            string paletteFilter = palette ? $"-vf \"split[s0][s1];[s0]palettegen={colors}[p];[s1][p]paletteuse=dither=floyd_steinberg\"" : "";
            string fpsFilter     = (resampleFps <= 0) ? "" : $"fps=fps={resampleFps.ToStringDot()}";
            string vf            = FormatUtils.ConcatStrings(new string[] { paletteFilter, fpsFilter });
            string rate          = fps.ToStringDot();
            string args          = $"-f concat -r {rate} -i {vfrFilename.Wrap()} -f gif {vf} {outPath.Wrap()}";

            await RunFfmpeg(args, framesFile.GetParentDir(), LogMode.OnlyLastLine, "error", TaskType.Encode);
        }
Пример #4
0
        public static async Task FramesToGifConcat(string framesFile, string outPath, Fraction rate, bool palette, int colors, Fraction resampleFps, float itsScale, LogMode logMode = LogMode.OnlyLastLine)
        {
            if (rate.GetFloat() > 50f && (resampleFps.GetFloat() > 50f || resampleFps.GetFloat() < 1))
            {
                resampleFps = new Fraction(50, 1);  // Force limit framerate as encoding above 50 will cause problems
            }
            if (logMode != LogMode.Hidden)
            {
                Logger.Log((resampleFps.GetFloat() <= 0) ? $"Encoding GIF..." : $"Encoding GIF resampled to {resampleFps.GetFloat().ToString().Replace(",", ".")} FPS...");
            }

            string framesFilename = Path.GetFileName(framesFile);
            string dither         = Config.Get(Config.Key.gifDitherType).Split(' ').First();
            string paletteFilter  = palette ? $"-vf \"split[s0][s1];[s0]palettegen={colors}[p];[s1][p]paletteuse=dither={dither}\"" : "";
            string fpsFilter      = (resampleFps.GetFloat() <= 0) ? "" : $"fps=fps={resampleFps}";
            string vf             = FormatUtils.ConcatStrings(new string[] { paletteFilter, fpsFilter });
            string extraArgs      = Config.Get(Config.Key.ffEncArgs);

            rate = rate / new Fraction(itsScale);
            string args = $"-f concat -r {rate} -i {framesFilename.Wrap()} -gifflags -offsetting {vf} {extraArgs} {outPath.Wrap()}";

            await RunFfmpeg(args, framesFile.GetParentDir(), LogMode.OnlyLastLine, "error");
        }