Skip to content

Commit

Permalink
Support APNG as output format
Browse files Browse the repository at this point in the history
See #108
  • Loading branch information
phw committed Oct 12, 2017
1 parent 163f19f commit d4529e4
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version 1.?.? - 2017-??-??
* feat: Optional GIF conversion with ffmpeg
* feat: Optional GIF conversion with Ffmpeg
* feat: Support APNG as output format (#108)
* fix: Temporary files get unique name again

# Version 1.1.0 - 2017-10-05
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ vala_precompile(VALA_C
src/dbus/freedesktop-dbus.vala
src/dbus/freedesktop-filemanager.vala
src/dbus/gnome-shell-screencast.vala
src/post-processing/ffmpeg-gif-post-processor.vala
src/post-processing/ffmpeg-post-processor.vala
src/post-processing/imagemagick-post-processor.vala
src/post-processing/post-processor.vala
src/recording/screen-recorder.vala
Expand Down
2 changes: 2 additions & 0 deletions data/com.uploadedlobster.peek.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
<key name="recording-output-format" type="s">
<choices>
<choice value="gif"/>
<choice value="apng"/>
<choice value="mp4"/>
<choice value="webm"/>
</choices>
<aliases>
<alias value="GIF" target="gif"/>
<alias value="APNG" target="apng"/>
<alias value="MP4" target="mp4"/>
<alias value="WebM" target="webm"/>
</aliases>
Expand Down
1 change: 1 addition & 0 deletions src/defaults.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Peek {
const int DEFAULT_FRAMERATE = 15;
const int DEFAULT_DOWNSAMPLE = 1;

const string OUTPUT_FORMAT_APNG = "apng";
const string OUTPUT_FORMAT_GIF = "gif";
const string OUTPUT_FORMAT_WEBM = "webm";
const string OUTPUT_FORMAT_MP4 = "mp4";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace Peek.PostProcessing {
/**
* Use FFmpeg to generate an optimized GIF from a video input
*/
public class FfmpegGifPostProcessor : Object, PostProcessor {
public class FfmpegPostProcessor : Object, PostProcessor {
public int framerate { get; set; default = 15; }

private Pid? pid = null;
private string output_format;

public FfmpegGifPostProcessor (int framerate) {
public FfmpegPostProcessor (int framerate, string output_format) {
this.framerate = framerate;
this.output_format = output_format;
}

public async File? process_async (File file) {
Expand Down Expand Up @@ -68,7 +70,8 @@ namespace Peek.PostProcessing {
var argv = new Array<string> ();
argv.append_vals (args, args.length);

return yield spawn_file_conversion_async (argv, "gif");
var extension = Utils.get_file_extension_for_format (output_format);
return yield spawn_file_conversion_async (argv, extension);
}

private async File? spawn_file_conversion_async (Array<string> argv, string output_extension) {
Expand Down
8 changes: 6 additions & 2 deletions src/recording/base-screen-recorder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ namespace Peek.Recording {
private async File? run_post_processors_async () {
var file = File.new_for_path (temp_file);

PostProcessor? post_processor = null;
if (output_format == OUTPUT_FORMAT_GIF) {
PostProcessor post_processor;
if (Environment.get_variable ("PEEK_POSTPROCESSOR") == "ffmpeg") {
post_processor = new FfmpegGifPostProcessor (framerate);
post_processor = new FfmpegPostProcessor (framerate, output_format);
} else {
post_processor = new ImagemagickPostProcessor (framerate);
}
} else if (output_format == OUTPUT_FORMAT_APNG) {
post_processor = new FfmpegPostProcessor (framerate, output_format);
}

if (post_processor != null) {
active_post_processor = post_processor;
file = yield post_processor.process_async (file);
active_post_processor = null;
Expand Down
9 changes: 7 additions & 2 deletions src/recording/gnome-shell-dbus-recorder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ namespace Peek.Recording {
}

private string get_temp_file_extension () {
var extension = output_format == OUTPUT_FORMAT_GIF ?
"avi" : Utils.get_file_extension_for_format (output_format);
string extension;
if (output_format == OUTPUT_FORMAT_GIF || output_format == OUTPUT_FORMAT_APNG) {
extension = "avi";
} else {
extension = Utils.get_file_extension_for_format (output_format);
}

return extension;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace Peek {
return "webm";
case OUTPUT_FORMAT_MP4:
return "mp4";
case OUTPUT_FORMAT_APNG:
return "apng";
case OUTPUT_FORMAT_GIF:
return "gif";
default:
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_test(
vala_precompile(VALA_TEST_COMMAND_LINE_SCREEN_RECORDER_C
screen-recorder/test-command-line-screen-recorder.vala
../src/post-processing/post-processor.vala
../src/post-processing/ffmpeg-gif-post-processor.vala
../src/post-processing/ffmpeg-post-processor.vala
../src/post-processing/imagemagick-post-processor.vala
../src/recording/recording-area.vala
../src/recording/screen-recorder.vala
Expand Down
3 changes: 2 additions & 1 deletion ui/preferences.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0
<!-- Generated with glade 3.20.0
Copyright (C) Philipp Wolfer <ph.wolfer@gmail.com>
Expand Down Expand Up @@ -198,6 +198,7 @@ Author: Philipp Wolfer <ph.wolfer@gmail.com>
<property name="active">0</property>
<items>
<item id="gif" translatable="yes">GIF</item>
<item id="apng" translatable="yes">APNG</item>
<item id="webm" translatable="yes">WebM</item>
<item id="mp4" translatable="yes">MP4</item>
</items>
Expand Down

0 comments on commit d4529e4

Please sign in to comment.