1
1
using Flowframes . Data ;
2
2
using Flowframes . IO ;
3
3
using Flowframes . MiscUtils ;
4
- using Flowframes . Os ;
5
- using Flowframes . Properties ;
6
4
using Newtonsoft . Json ;
7
5
using System ;
8
6
using System . Collections . Generic ;
@@ -15,13 +13,12 @@ namespace Flowframes.Main
15
13
{
16
14
class FrameOrder
17
15
{
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 ;
25
22
26
23
public static async Task CreateFrameOrderFile ( string tempFolder , bool loopEnabled , float interpFactor )
27
24
{
@@ -154,8 +151,6 @@ public static async Task CreateFramesFileImgSeq(string tempFolder, bool loop, fl
154
151
155
152
string framesDir = Path . Combine ( tempFolder , Paths . framesDir ) ;
156
153
frameFiles = new DirectoryInfo ( framesDir ) . GetFiles ( "*" + Interpolate . currentSettings . framesExt ) ;
157
- frameFilesWithoutLast = frameFiles ;
158
- Array . Resize ( ref frameFilesWithoutLast , frameFilesWithoutLast . Length - 1 ) ;
159
154
string framesFile = Path . Combine ( tempFolder , Paths . GetFrameOrderFilename ( interpFactor ) ) ;
160
155
string fileContent = "" ;
161
156
string dupesFile = Path . Combine ( tempFolder , "dupes.json" ) ;
@@ -178,7 +173,7 @@ public static async Task CreateFramesFileImgSeq(string tempFolder, bool loop, fl
178
173
179
174
if ( interpFactor == ( int ) interpFactor ) // Use old multi-threaded code if factor is not fractional
180
175
{
181
- for ( int i = 0 ; i < frameFilesWithoutLast . Length ; i += linesPerTask )
176
+ for ( int i = 0 ; i < frameFiles . Length ; i += linesPerTask )
182
177
{
183
178
tasks . Add ( GenerateFrameLines ( num , i , linesPerTask , ( int ) interpFactor , sceneDetection , debug ) ) ;
184
179
num ++ ;
@@ -198,10 +193,13 @@ public static async Task CreateFramesFileImgSeq(string tempFolder, bool loop, fl
198
193
199
194
if ( Config . GetBool ( Config . Key . fixOutputDuration ) ) // Match input duration by padding duping last frame until interp frames == (inputframes * factor)
200
195
{
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 ( ) ;
202
197
203
198
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
+ }
205
203
}
206
204
207
205
if ( loop )
@@ -341,13 +339,15 @@ static async Task GenerateFrameLines(int number, int startIndex, int count, int
341
339
for ( int i = startIndex ; i < ( startIndex + count ) ; i ++ )
342
340
{
343
341
if ( Interpolate . canceled ) return ;
344
- if ( i >= frameFilesWithoutLast . Length ) break ;
342
+ if ( i >= frameFiles . Length ) break ;
345
343
346
- string frameName = GetNameNoExt ( frameFilesWithoutLast [ i ] . Name ) ;
344
+ string frameName = GetNameNoExt ( frameFiles [ i ] . Name ) ;
347
345
string frameNameImport = GetNameNoExt ( FrameRename . importFilenames [ i ] ) ;
348
346
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
350
348
349
+ if ( i == frameFiles . Length - 1 )
350
+ interpFramesAmount = 1 ;
351
351
for ( int frm = 0 ; frm < interpFramesAmount ; frm ++ ) // Generate frames file lines
352
352
{
353
353
if ( discardThisFrame ) // If frame is scene cut frame
@@ -386,7 +386,7 @@ static async Task GenerateFrameLines(int number, int startIndex, int count, int
386
386
fileContent = WriteFrameWithDupes ( dupesAmount , fileContent , totalFileCount , ext , debug , $ "[In: { frameName } ] [{ ( ( frm == 0 ) ? " Source " : $ "Interp { frm } ") } ]") ;
387
387
}
388
388
389
- inputFilenames . Add ( frameFilesWithoutLast [ i ] . Name ) ;
389
+ inputFilenames . Add ( frameFiles [ i ] . Name ) ;
390
390
}
391
391
}
392
392
@@ -398,8 +398,12 @@ static async Task GenerateFrameLines(int number, int startIndex, int count, int
398
398
399
399
static string WriteFrameWithDupes ( int dupesAmount , string fileContent , int frameNum , string ext , bool debug , string debugNote = "" , string forcedNote = "" )
400
400
{
401
+ string duration = $ "duration { 1f / Interpolate . currentSettings . outFps . GetFloat ( ) } ";
401
402
for ( int writtenDupes = - 1 ; writtenDupes < dupesAmount ; writtenDupes ++ ) // Write duplicates
403
+ {
402
404
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
+ }
403
407
404
408
return fileContent ;
405
409
}
0 commit comments