@@ -285,15 +285,18 @@ class DiagramGenerator {
285285 for (final AnimationMetadata metadata in metadataList) {
286286 final String prefix = '${metadata .category }/${metadata .name }' ;
287287
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 }' ));
289290 if (destination.existsSync ()) {
290291 destination.deleteSync ();
291292 }
292293 if (! destination.parent.existsSync ()) {
293294 destination.parent.createSync (recursive: true );
294295 }
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);
297300 outputs.add (destination);
298301 }
299302 final ProcessPool pool = ProcessPool (processRunner: processRunner);
@@ -310,11 +313,13 @@ class DiagramGenerator {
310313 required String destination,
311314 required Map <int , List <WorkerJob >> jobs,
312315 }) {
313- switch (metadata.videoFormat) {
316+ switch (metadata.videoFormat) {
314317 case VideoFormat .mp4:
315- _generateMp4Commands (metadata: metadata, destination: destination, jobs: jobs);
318+ _generateMp4Commands (
319+ metadata: metadata, destination: destination, jobs: jobs);
316320 case VideoFormat .gif:
317- _generateGifCommands (metadata: metadata, destination: destination, jobs: jobs);
321+ _generateGifCommands (
322+ metadata: metadata, destination: destination, jobs: jobs);
318323 }
319324 }
320325
@@ -324,71 +329,74 @@ class DiagramGenerator {
324329 required Map <int , List <WorkerJob >> jobs,
325330 }) {
326331 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+ );
353358 }
354359
355360 void _generateGifCommands ({
356361 required AnimationMetadata metadata,
357362 required String destination,
358363 required Map <int , List <WorkerJob >> jobs,
359364 }) {
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' );
361367 // Generate palette.
362368 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+ );
376383 // Create the final gif with the palette.
377384 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+ );
392400 }
393401
394402 Future <List <File >> _combineAnimations (List <File > inputFiles) async {
0 commit comments