jackburton79 / bescreencapture

BeScreenCapture - Screen Capture software for Haiku
BSD 3-Clause "New" or "Revised" License
7 stars 10 forks source link

Option to export to animated GIFs #37

Closed probonopd closed 5 years ago

probonopd commented 5 years ago

Thanks for this very useful application.

BeScreenCapture should have an option to export to animated GIFs, like Peek has. It can be done with ffmpeg, which is available on Haiku.

Here is the code that does it:

https://github.com/phw/peek/blob/e967c3167b1dae3237480402f48fc7b6eba1f659/src/post-processing/ffmpeg-post-processor.vala

Reference: https://medium.com/@probonopd/my-sixth-day-with-haiku-under-the-hood-of-resources-icons-and-packages-abec8d0e4ec6

jackburton79 commented 5 years ago

Nice idea. I'll see if I can throw some time on it.

probonopd commented 5 years ago

Thanks @jackburton79 - it will help to make my future articles, feature requests and bug reports more lively ;-)

probonopd commented 5 years ago

This is what Peek does on Linux:

me@host:~$ strace -s 512 -feexecve squashfs-root/AppRun 2>&1 | grep ffmpeg

[pid  8142] execve("/usr/bin/which", ["which", "ffmpeg"], 0x18c7640 /* 53 vars */) = 0
[pid  8144] execve("/home/me/squashfs-root/usr/bin/ffmpeg", ["ffmpeg", "-f", "x11grab", "-show_region", "0", "-framerate", "10", "-video_size", "1045x664", "-i", ":0.0+120,255", "-filter:v", "scale=iw/1:-1", "-codec:v", "libx264rgb", "-preset:v", "ultrafast", "-crf", "0", "-y", "/home/me/.cache/peek/peekEE7I5Z.mkv"], 0x18c7640 /* 53 vars */) = 0
(...)
[pid  8152] execve("/home/me/squashfs-root/usr/bin/ffmpeg", ["ffmpeg", "-y", "-i", "/home/me/.cache/peek/peekEE7I5Z.mkv", "-vf", "fps=10,palettegen", "/home/me/.cache/peek/peekW6J44Z.png"], 0x18c7640 /* 53 vars */) = 0
[pid  8167] execve("/home/me/squashfs-root/usr/bin/ffmpeg", ["ffmpeg", "-y", "-i", "/home/me/.cache/peek/peekEE7I5Z.mkv", "-i", "/home/me/.cache/peek/peekW6J44Z.png", "-filter_complex", "fps=10,paletteuse", "/home/me/.cache/peek/peekY0KD5Z.gif"], 0x18c7640 /* 53 vars */) = 0

which translates to

# Grabbing to a temporary file which needs to be cleaned up afterwards
ffmpeg -f x11grab -show_region 0 -framerate 10 -video_size 1045x664 -i :0.0+120,255 -filter:v scale=iw/1:-1 -codec:v libx264rgb -preset:v ultrafast -crf 0 -y /home/me/.cache/peek/peekEE7I5Z.mkv

# Converting the temporary file to gif after the recording is complete
ffmpeg -y -i /home/me/.cache/peek/peekEE7I5Z.mkv -vf fps=10,palettegen /home/me/.cache/peek/peekW6J44Z.png
ffmpeg -y -i /home/me/.cache/peek/peekEE7I5Z.mkv -i /home/me/.cache/peek/peekW6J44Z.png -filter_complex fps=10,paletteuse /home/me/.cache/peek/peekY0KD5Z.gif

Looks easy enough, to me, do you think you can add it?

Thanks so much :+1:

jackburton79 commented 5 years ago

It's done (in a very rough way) in current master. Before releasing I need to polish it a bit, though, because I think I introduced a couple of memory leaks, plus the user experience isn't pretty when you create a GIF.

probonopd commented 5 years ago

Thanks @jackburton79. Seems you are using bmp intermediary files, why?

probonopd commented 5 years ago

The colors are funny:

funny_colors

jackburton79 commented 5 years ago

Thanks @jackburton79. Seems you are using bmp intermediary files, why?

Because it's easier this way and currently the GIF conversion is sort of an hack. What's missing is deleting the intermediary files.

jackburton79 commented 5 years ago

The colors are funny:

funny_colors

No idea yet. Yesterday when I finished it was too late to check.

probonopd commented 5 years ago

Let's try whether the commands I have extracted from Peek give better results.

jackburton79 commented 5 years ago

Let's try whether the commands I have extracted from Peek give better results.

I tried with the commands you extracted but with no changes. Anyway, I fixed another problem and it seems the colors are correct now (in master)

probonopd commented 5 years ago

Thanks @jackburton79 highly appreciated.