From fd280007936339d6fcdf90c475860215f45e0aee Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Tue, 15 Dec 2020 16:45:31 +0100 Subject: [PATCH] Fixed weird duplicate frames problem with 2x --- Code/AudioVideo/FFmpegCommands.cs | 5 ++--- Code/Main/AutoEncode.cs | 5 +++-- Code/Main/CreateVideo.cs | 3 +-- Code/Main/Interpolate.cs | 3 +-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Code/AudioVideo/FFmpegCommands.cs b/Code/AudioVideo/FFmpegCommands.cs index 4ad7646..647bbd4 100644 --- a/Code/AudioVideo/FFmpegCommands.cs +++ b/Code/AudioVideo/FFmpegCommands.cs @@ -103,7 +103,7 @@ namespace Flowframes string enc = useH265 ? "libx265" : "libx264"; string presetStr = $"-preset {Config.Get("ffEncPreset")}"; string vfrFilename = Path.GetFileName(framesFile); - string args = $"-vsync 2 -f concat -i {vfrFilename} -r {fps.ToString().Replace(",", ".")} -c:v {enc} -crf {crf} {presetStr} {videoEncArgs} -threads {Config.GetInt("ffEncThreads")} -c:a copy {outPath.Wrap()}"; + string args = $"-vsync 1 -f concat -i {vfrFilename} -r {fps.ToString().Replace(",", ".")} -c:v {enc} -crf {crf} {presetStr} {videoEncArgs} -threads {Config.GetInt("ffEncThreads")} -c:a copy {outPath.Wrap()}"; await AvProcess.RunFfmpeg(args, framesFile.GetParentDir(), logMode); } @@ -111,9 +111,8 @@ namespace Flowframes { Logger.Log($"Merging videos..."); string loopStr = (looptimes > 0) ? $"-stream_loop {looptimes}" : ""; - string vsyncStr = Config.GetInt("vfrMode") == 0 ? "-vsync 1" : "-vsync 2"; string vfrFilename = Path.GetFileName(concatFile); - string args = $" {loopStr} {vsyncStr} -f concat -r {fps.ToString().Replace(",", ".")} -i {vfrFilename} -c copy -pix_fmt yuv420p -movflags +faststart {outPath.Wrap()}"; + string args = $" {loopStr} -vsync 1 -f concat -r {fps.ToString().Replace(",", ".")} -i {vfrFilename} -c copy -pix_fmt yuv420p -movflags +faststart {outPath.Wrap()}"; await AvProcess.RunFfmpeg(args, concatFile.GetParentDir(), AvProcess.LogMode.Hidden); } diff --git a/Code/Main/AutoEncode.cs b/Code/Main/AutoEncode.cs index c019ceb..4daf760 100644 --- a/Code/Main/AutoEncode.cs +++ b/Code/Main/AutoEncode.cs @@ -61,14 +61,15 @@ namespace Flowframes.Main if (unencodedFrames.Count >= (chunkSize + safetyBufferFrames) || !aiRunning) // Encode every n frames, or after process has exited { busy = true; - Logger.Log("Encoding Chunk #" + videoIndex, true, false, "ffmpeg.txt"); List framesToEncode = aiRunning ? unencodedFrames.Take(chunkSize).ToList() : unencodedFrames; // Take all remaining frames if process is done + Logger.Log($"Encoding Chunk #{videoIndex} using {Path.GetFileName(framesToEncode.First())} through {Path.GetFileName(framesToEncode.Last())}", true, false, "ffmpeg.txt"); + IOUtils.ZeroPadDir(framesToEncode, Padding.interpFrames); // Zero-pad frames before encoding to make sure filenames match with VFR file string outpath = Path.Combine(videoChunksFolder, $"{videoIndex.ToString().PadLeft(4, '0')}{InterpolateUtils.GetExt(Interpolate.currentOutMode)}"); int firstFrameNum = Path.GetFileNameWithoutExtension(framesToEncode[0]).GetInt(); - await CreateVideo.EncodeChunk(outpath, firstFrameNum, framesToEncode.Count); + await CreateVideo.EncodeChunk(outpath, firstFrameNum - 1, framesToEncode.Count); if(Interpolate.canceled) return; diff --git a/Code/Main/CreateVideo.cs b/Code/Main/CreateVideo.cs index 24d9d6e..add4aec 100644 --- a/Code/Main/CreateVideo.cs +++ b/Code/Main/CreateVideo.cs @@ -150,11 +150,10 @@ namespace Flowframes.Main int crf = h265 ? Config.GetInt("h265Crf") : Config.GetInt("h264Crf"); string vfrFileOriginal = Path.Combine(i.currentTempDir, $"vfr-{i.lastInterpFactor}x.ini"); - string vfrFile = Path.Combine(i.currentTempDir, $"vfr-chunk-temp.ini"); + string vfrFile = Path.Combine(i.currentTempDir, $"vfr-chunk-{firstFrameNum}-{firstFrameNum + framesAmount}.ini"); File.WriteAllLines(vfrFile, IOUtils.ReadLines(vfrFileOriginal).Skip(firstFrameNum * 2).Take(framesAmount * 2)); await FFmpegCommands.FramesToMp4Vfr(vfrFile, outPath, h265, crf, i.currentOutFps, AvProcess.LogMode.Hidden); - IOUtils.TryDeleteIfExists(vfrFile); } static async Task Loop(string outPath, int looptimes) diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index db382ff..0be453f 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -138,8 +138,7 @@ namespace Flowframes Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?"); else Cancel("Frame extraction failed!\n\nYour input file might be incompatible."); - } - + } if (Config.GetInt("dedupMode") == 1) await MagickDedupe.Run(currentFramesPath);