11using Flowframes . Data ;
22using Flowframes . IO ;
33using Flowframes . MiscUtils ;
4- using Flowframes . Os ;
5- using Flowframes . Properties ;
64using Newtonsoft . Json ;
75using System ;
86using System . Collections . Generic ;
@@ -15,13 +13,12 @@ namespace Flowframes.Main
1513{
1614 class FrameOrder
1715 {
18- private static Stopwatch benchmark = new Stopwatch ( ) ;
19- private static FileInfo [ ] frameFiles ;
20- private static FileInfo [ ] frameFilesWithoutLast ;
21- private static List < string > sceneFrames = new List < string > ( ) ;
22- private static Dictionary < int , string > frameFileContents = new Dictionary < int , string > ( ) ;
23- private static List < string > inputFilenames = new List < string > ( ) ;
24- private static int lastOutFileCount ;
16+ static Stopwatch benchmark = new Stopwatch ( ) ;
17+ static FileInfo [ ] frameFiles ;
18+ static List < string > sceneFrames = new List < string > ( ) ;
19+ static Dictionary < int , string > frameFileContents = new Dictionary < int , string > ( ) ;
20+ static List < string > inputFilenames = new List < string > ( ) ;
21+ static int lastOutFileCount ;
2522
2623 public static async Task CreateFrameOrderFile ( string tempFolder , bool loopEnabled , float interpFactor )
2724 {
@@ -154,8 +151,6 @@ public static async Task CreateFramesFileImgSeq(string tempFolder, bool loop, fl
154151
155152 string framesDir = Path . Combine ( tempFolder , Paths . framesDir ) ;
156153 frameFiles = new DirectoryInfo ( framesDir ) . GetFiles ( "*" + Interpolate . currentSettings . framesExt ) ;
157- frameFilesWithoutLast = frameFiles ;
158- Array . Resize ( ref frameFilesWithoutLast , frameFilesWithoutLast . Length - 1 ) ;
159154 string framesFile = Path . Combine ( tempFolder , Paths . GetFrameOrderFilename ( interpFactor ) ) ;
160155 string fileContent = "" ;
161156 string dupesFile = Path . Combine ( tempFolder , "dupes.json" ) ;
@@ -178,7 +173,7 @@ public static async Task CreateFramesFileImgSeq(string tempFolder, bool loop, fl
178173
179174 if ( interpFactor == ( int ) interpFactor ) // Use old multi-threaded code if factor is not fractional
180175 {
181- for ( int i = 0 ; i < frameFilesWithoutLast . Length ; i += linesPerTask )
176+ for ( int i = 0 ; i < frameFiles . Length ; i += linesPerTask )
182177 {
183178 tasks . Add ( GenerateFrameLines ( num , i , linesPerTask , ( int ) interpFactor , sceneDetection , debug ) ) ;
184179 num ++ ;
@@ -198,10 +193,13 @@ public static async Task CreateFramesFileImgSeq(string tempFolder, bool loop, fl
198193
199194 if ( Config . GetBool ( Config . Key . fixOutputDuration ) ) // Match input duration by padding duping last frame until interp frames == (inputframes * factor)
200195 {
201- int neededFrames = ( frameFiles . Length * interpFactor ) . RoundToInt ( ) - fileContent . SplitIntoLines ( ) . Where ( x => x . StartsWith ( "' file " ) ) . Count ( ) ;
196+ int neededFrames = ( frameFiles . Length * interpFactor ) . RoundToInt ( ) - fileContent . SplitIntoLines ( ) . Where ( x => x . StartsWith ( "file " ) ) . Count ( ) ;
202197
203198 for ( int i = 0 ; i < neededFrames ; i ++ )
204- fileContent += fileContent . SplitIntoLines ( ) . Where ( x => x . StartsWith ( "'file " ) ) . Last ( ) ;
199+ {
200+ fileContent += fileContent . SplitIntoLines ( ) . Where ( x => x . StartsWith ( "file " ) ) . Last ( ) + "\n " ;
201+ fileContent += fileContent . SplitIntoLines ( ) . Where ( x => x . StartsWith ( "duration " ) ) . Last ( ) + "\n " ;
202+ }
205203 }
206204
207205 if ( loop )
@@ -341,13 +339,15 @@ static async Task GenerateFrameLines(int number, int startIndex, int count, int
341339 for ( int i = startIndex ; i < ( startIndex + count ) ; i ++ )
342340 {
343341 if ( Interpolate . canceled ) return ;
344- if ( i >= frameFilesWithoutLast . Length ) break ;
342+ if ( i >= frameFiles . Length ) break ;
345343
346- string frameName = GetNameNoExt ( frameFilesWithoutLast [ i ] . Name ) ;
344+ string frameName = GetNameNoExt ( frameFiles [ i ] . Name ) ;
347345 string frameNameImport = GetNameNoExt ( FrameRename . importFilenames [ i ] ) ;
348346 int dupesAmount = dupesDict . ContainsKey ( frameNameImport ) ? dupesDict [ frameNameImport ] . Count : 0 ;
349- bool discardThisFrame = ( sceneDetection && i < frameFilesWithoutLast . Length && sceneFrames . Contains ( GetNameNoExt ( FrameRename . importFilenames [ i + 1 ] ) ) ) ; // i+2 is in scene detection folder, means i+1 is ugly interp frame
347+ bool discardThisFrame = ( sceneDetection && ( i + 1 ) < FrameRename . importFilenames . Length && sceneFrames . Contains ( GetNameNoExt ( FrameRename . importFilenames [ i + 1 ] ) ) ) ; // i+2 is in scene detection folder, means i+1 is ugly interp frame
350348
349+ if ( i == frameFiles . Length - 1 )
350+ interpFramesAmount = 1 ;
351351 for ( int frm = 0 ; frm < interpFramesAmount ; frm ++ ) // Generate frames file lines
352352 {
353353 if ( discardThisFrame ) // If frame is scene cut frame
@@ -386,7 +386,7 @@ static async Task GenerateFrameLines(int number, int startIndex, int count, int
386386 fileContent = WriteFrameWithDupes ( dupesAmount , fileContent , totalFileCount , ext , debug , $ "[In: { frameName } ] [{ ( ( frm == 0 ) ? " Source " : $ "Interp { frm } ") } ]") ;
387387 }
388388
389- inputFilenames . Add ( frameFilesWithoutLast [ i ] . Name ) ;
389+ inputFilenames . Add ( frameFiles [ i ] . Name ) ;
390390 }
391391 }
392392
@@ -398,8 +398,12 @@ static async Task GenerateFrameLines(int number, int startIndex, int count, int
398398
399399 static string WriteFrameWithDupes ( int dupesAmount , string fileContent , int frameNum , string ext , bool debug , string debugNote = "" , string forcedNote = "" )
400400 {
401+ string duration = $ "duration { 1f / Interpolate . currentSettings . outFps . GetFloat ( ) } ";
401402 for ( int writtenDupes = - 1 ; writtenDupes < dupesAmount ; writtenDupes ++ ) // Write duplicates
403+ {
402404 fileContent += $ "file '{ Paths . interpDir } /{ frameNum . ToString ( ) . PadLeft ( Padding . interpFrames , '0' ) } { ext } ' # { ( debug ? ( $ "Dupe { ( writtenDupes + 1 ) . ToString ( "000" ) } { debugNote } ") . Replace ( "Dupe 000" , " " ) : "" ) } { forcedNote } \n ";
405+ fileContent += $ "{ duration } \n ";
406+ }
403407
404408 return fileContent ;
405409 }
0 commit comments