@@ -285,15 +285,18 @@ class DiagramGenerator {
285
285
for (final AnimationMetadata metadata in metadataList) {
286
286
final String prefix = '${metadata .category }/${metadata .name }' ;
287
287
288
- final File destination = File (path.join (destDir.path, '$prefix .${metadata .videoFormat .name }' ));
288
+ final File destination =
289
+ File (path.join (destDir.path, '$prefix .${metadata .videoFormat .name }' ));
289
290
if (destination.existsSync ()) {
290
291
destination.deleteSync ();
291
292
}
292
293
if (! destination.parent.existsSync ()) {
293
294
destination.parent.createSync (recursive: true );
294
295
}
295
- print ('Converting ${metadata .name } animation to ${metadata .videoFormat .name }.' );
296
- _generateCommands (metadata: metadata, destination: destination.path, jobs: jobs);
296
+ print (
297
+ 'Converting ${metadata .name } animation to ${metadata .videoFormat .name }.' );
298
+ _generateCommands (
299
+ metadata: metadata, destination: destination.path, jobs: jobs);
297
300
outputs.add (destination);
298
301
}
299
302
final ProcessPool pool = ProcessPool (processRunner: processRunner);
@@ -310,11 +313,13 @@ class DiagramGenerator {
310
313
required String destination,
311
314
required Map <int , List <WorkerJob >> jobs,
312
315
}) {
313
- switch (metadata.videoFormat) {
316
+ switch (metadata.videoFormat) {
314
317
case VideoFormat .mp4:
315
- _generateMp4Commands (metadata: metadata, destination: destination, jobs: jobs);
318
+ _generateMp4Commands (
319
+ metadata: metadata, destination: destination, jobs: jobs);
316
320
case VideoFormat .gif:
317
- _generateGifCommands (metadata: metadata, destination: destination, jobs: jobs);
321
+ _generateGifCommands (
322
+ metadata: metadata, destination: destination, jobs: jobs);
318
323
}
319
324
}
320
325
@@ -324,71 +329,74 @@ class DiagramGenerator {
324
329
required Map <int , List <WorkerJob >> jobs,
325
330
}) {
326
331
jobs.putIfAbsent (0 , () => < WorkerJob > []).add (
327
- WorkerJob (
328
- < String > [
329
- ffmpegCommand,
330
- '-loglevel' , 'fatal' , // Only print fatal errors.
331
- '-framerate' , metadata.frameRate.toStringAsFixed (2 ),
332
- '-i' , '-' , // read in the concatenated frame files from stdin.
333
- // Yes, specify the -framerate flag twice: once for input, once for
334
- // output.
335
- '-framerate' , metadata.frameRate.toStringAsFixed (2 ),
336
- '-tune' , 'animation' , // Optimize the encoder for cell animation.
337
- '-preset' ,
338
- 'veryslow' , // Use the slowest (best quality) compression preset.
339
- // Almost lossless quality (can't use lossless '0' because Safari
340
- // doesn't support it).
341
- '-crf' , '1' ,
342
- '-c:v' , 'libx264' , // encode to mp4 H.264
343
- '-y' , // overwrite output
344
- // Video format set to YUV420 color space for compatibility.
345
- '-vf' , 'format=yuv420p' ,
346
- destination, // output movie.
347
- ],
348
- workingDirectory: temporaryDirectory,
349
- stdinRaw: _concatInputs (metadata.frameFiles),
350
- printOutput: true ,
351
- ),
352
- );
332
+ WorkerJob (
333
+ < String > [
334
+ ffmpegCommand,
335
+ '-loglevel' , 'fatal' , // Only print fatal errors.
336
+ '-framerate' , metadata.frameRate.toStringAsFixed (2 ),
337
+ '-i' , '-' , // read in the concatenated frame files from stdin.
338
+ // Yes, specify the -framerate flag twice: once for input, once for
339
+ // output.
340
+ '-framerate' , metadata.frameRate.toStringAsFixed (2 ),
341
+ '-tune' , 'animation' , // Optimize the encoder for cell animation.
342
+ '-preset' ,
343
+ 'veryslow' , // Use the slowest (best quality) compression preset.
344
+ // Almost lossless quality (can't use lossless '0' because Safari
345
+ // doesn't support it).
346
+ '-crf' , '1' ,
347
+ '-c:v' , 'libx264' , // encode to mp4 H.264
348
+ '-y' , // overwrite output
349
+ // Video format set to YUV420 color space for compatibility.
350
+ '-vf' , 'format=yuv420p' ,
351
+ destination, // output movie.
352
+ ],
353
+ workingDirectory: temporaryDirectory,
354
+ stdinRaw: _concatInputs (metadata.frameFiles),
355
+ printOutput: true ,
356
+ ),
357
+ );
353
358
}
354
359
355
360
void _generateGifCommands ({
356
361
required AnimationMetadata metadata,
357
362
required String destination,
358
363
required Map <int , List <WorkerJob >> jobs,
359
364
}) {
360
- final String palette = path.join (temporaryDirectory.path, '${metadata .category }_${metadata .name }.png' );
365
+ final String palette = path.join (
366
+ temporaryDirectory.path, '${metadata .category }_${metadata .name }.png' );
361
367
// Generate palette.
362
368
jobs.putIfAbsent (0 , () => < WorkerJob > []).add (
363
- WorkerJob (
364
- < String > [
365
- ffmpegCommand,
366
- '-loglevel' , 'fatal' , // Only print fatal errors.
367
- '-i' , '-' , // read in the concatenated frame files from stdin.
368
- '-vf' , 'fps=${metadata .frameRate .toStringAsFixed (0 )},scale=${metadata .width }:-1:flags=lanczos,palettegen' ,
369
- palette,
370
- ],
371
- workingDirectory: temporaryDirectory,
372
- stdinRaw: _concatInputs (metadata.frameFiles),
373
- printOutput: true ,
374
- ),
375
- );
369
+ WorkerJob (
370
+ < String > [
371
+ ffmpegCommand,
372
+ '-loglevel' , 'fatal' , // Only print fatal errors.
373
+ '-i' , '-' , // read in the concatenated frame files from stdin.
374
+ '-vf' ,
375
+ 'fps=${metadata .frameRate .toStringAsFixed (0 )},scale=${metadata .width }:-1:flags=lanczos,palettegen' ,
376
+ palette,
377
+ ],
378
+ workingDirectory: temporaryDirectory,
379
+ stdinRaw: _concatInputs (metadata.frameFiles),
380
+ printOutput: true ,
381
+ ),
382
+ );
376
383
// Create the final gif with the palette.
377
384
jobs.putIfAbsent (1 , () => < WorkerJob > []).add (
378
- WorkerJob (
379
- < String > [
380
- ffmpegCommand,
381
- '-loglevel' , 'fatal' , // Only print fatal errors.
382
- '-i' , '-' ,
383
- '-i' , palette,
384
- '-filter_complex' , 'fps=${metadata .frameRate .toStringAsFixed (0 )},scale=${metadata .width }:-1:flags=lanczos[x];[x][1:v]paletteuse' ,
385
- destination,
386
- ],
387
- workingDirectory: temporaryDirectory,
388
- stdinRaw: _concatInputs (metadata.frameFiles),
389
- printOutput: true ,
390
- ),
391
- );
385
+ WorkerJob (
386
+ < String > [
387
+ ffmpegCommand,
388
+ '-loglevel' , 'fatal' , // Only print fatal errors.
389
+ '-i' , '-' ,
390
+ '-i' , palette,
391
+ '-filter_complex' ,
392
+ 'fps=${metadata .frameRate .toStringAsFixed (0 )},scale=${metadata .width }:-1:flags=lanczos[x];[x][1:v]paletteuse' ,
393
+ destination,
394
+ ],
395
+ workingDirectory: temporaryDirectory,
396
+ stdinRaw: _concatInputs (metadata.frameFiles),
397
+ printOutput: true ,
398
+ ),
399
+ );
392
400
}
393
401
394
402
Future <List <File >> _combineAnimations (List <File > inputFiles) async {
0 commit comments