File: gifski-post-processor.vala

package info (click to toggle)
peek 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,768 kB
  • sloc: xml: 234; sh: 85; python: 69; makefile: 14
file content (69 lines) | stat: -rw-r--r-- 1,951 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Peek Copyright (c) 2017-2018 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

using Peek.Recording;

namespace Peek.PostProcessing {

  /**
  * Use gifski (https://gif.ski/) to generate an optimized GIF from a video input
  */
  public class GifskiPostProcessor : CliPostProcessor {
    private RecordingConfig config;

    public GifskiPostProcessor (RecordingConfig config) {
      this.config = config;
    }

    public override async Array<File>? process_async (Array<File> files) throws RecordingError {
      try {
        var extension = Utils.get_file_extension_for_format (OutputFormat.GIF);
        var output_file = Utils.create_temp_file (extension);

        debug ("Running gifski\n    saving to: %s\n    quality: %d\n",
          output_file, config.gifski_quality);

        var argv = new Array<string> ();

        argv.append_val ("gifski");

        argv.append_val ("--fps");
        argv.append_val (config.framerate.to_string ());

        argv.append_val ("--quality");
        argv.append_val (config.gifski_quality.to_string ());

        argv.append_val ("-o");
        argv.append_val (output_file);

        foreach (var file in files.data) {
          argv.append_val (file.get_path ());
        }

        try {
          yield spawn_command_async (argv.data);
        } catch (RecordingError e) {
          FileUtils.remove (output_file);
          throw e;
        }

        var result = new Array<File> ();
        result.append_val (File.new_for_path (output_file));
        return result;
      } catch (FileError e) {
        stderr.printf ("Error: %s\n", e.message);
        throw new RecordingError.POSTPROCESSING_ABORTED (e.message);
      }
    }

    public static bool is_available () {
      return Utils.check_for_executable ("gifski");
    }
  }
}