Skip to content

Instantly share code, notes, and snippets.

@mythmon
Created May 2, 2014 20:32
Show Gist options
  • Save mythmon/e31427fd29ed61a28757 to your computer and use it in GitHub Desktop.
Save mythmon/e31427fd29ed61a28757 to your computer and use it in GitHub Desktop.
My video screenshot scripts
  1. Install recordmydesktop. I found this in Arch's Community repo. There are GTK and QT versions, but neither of them were useful for me.
  2. Compile xrectsel.c and put it on your path. This is used to select a screen region to record.
  3. Get dropbox-cli. I found this in the AUR. This is how the script gets the URL to share.
  4. Run record.sh. It should let you select a region of your screen, and then it will immediately start recording.
  5. When you are done recording, press Ctrl+Alt+S. This is the default stop key for recordmydesktop. It is probably customizable, but I couldn't figure it out.
  6. The script will print the public sharable url of your recording to stdout, and also put it on your clipboard.
  7. The script will use notify-send to notify you that the URL is on your clipboard. This is useful if you run the script from a keybinding or a launcher (I use dmenu). I use notify-osd-customizable to get notifications from send-notify.

This generates .ogv files. Chrome and Firefox can both play this out of the box (I didn't test it anywhere else). If you are a horrible luddite you can probably modify the script to generate gifs. I bet ffmpeg might be helpful.

#!/bin/bash
geom=$(xrectsel | tr '+x' ' ')
w=$(echo $geom | awk '{print $1}')
h=$(echo $geom | awk '{print $2}')
x=$(echo $geom | awk '{print $3}')
y=$(echo $geom | awk '{print $4}')
file="$HOME/Dropbox/Public/screenshot-$(date -I | sed -e 's/-//g')-$$.ogv"
recordmydesktop -x $x -y $y --width $w --height $h \
--no-sound -o $file
echo $file
dropbox puburl $file
dropbox puburl $file | tr '\n' ' ' | xclip
notify-send "It's on Dropbox. Public URL is on the clipboard."
#include<stdio.h>
#include<stdlib.h>
#include<X11/Xlib.h>
#include<X11/cursorfont.h>
int main(void)
{
int rx = 0, ry = 0, rw = 0, rh = 0;
int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0;
int btn_pressed = 0, done = 0;
XEvent ev;
Display *disp = XOpenDisplay(NULL);
if(!disp)
return EXIT_FAILURE;
Screen *scr = NULL;
scr = ScreenOfDisplay(disp, DefaultScreen(disp));
Window root = 0;
root = RootWindow(disp, XScreenNumberOfScreen(scr));
Cursor cursor, cursor2;
cursor = XCreateFontCursor(disp, XC_left_ptr);
cursor2 = XCreateFontCursor(disp, XC_lr_angle);
XGCValues gcval;
gcval.foreground = XWhitePixel(disp, 0);
gcval.function = GXxor;
gcval.background = XBlackPixel(disp, 0);
gcval.plane_mask = gcval.background ^ gcval.foreground;
gcval.subwindow_mode = IncludeInferiors;
GC gc;
gc = XCreateGC(disp, root,
GCFunction | GCForeground | GCBackground | GCSubwindowMode,
&gcval);
/* this XGrab* stuff makes XPending true ? */
if ((XGrabPointer
(disp, root, False,
ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync,
GrabModeAsync, root, cursor, CurrentTime) != GrabSuccess))
printf("couldn't grab pointer:");
if ((XGrabKeyboard
(disp, root, False, GrabModeAsync, GrabModeAsync,
CurrentTime) != GrabSuccess))
printf("couldn't grab keyboard:");
while (!done) {
while (!done && XPending(disp)) {
XNextEvent(disp, &ev);
switch (ev.type) {
case MotionNotify:
/* this case is purely for drawing rect on screen */
if (btn_pressed) {
if (rect_w) {
/* re-draw the last rect to clear it */
XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
} else {
/* Change the cursor to show we're selecting a region */
XChangeActivePointerGrab(disp,
ButtonMotionMask | ButtonReleaseMask,
cursor2, CurrentTime);
}
rect_x = rx;
rect_y = ry;
rect_w = ev.xmotion.x - rect_x;
rect_h = ev.xmotion.y - rect_y;
if (rect_w < 0) {
rect_x += rect_w;
rect_w = 0 - rect_w;
}
if (rect_h < 0) {
rect_y += rect_h;
rect_h = 0 - rect_h;
}
/* draw rectangle */
XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
XFlush(disp);
}
break;
case ButtonPress:
btn_pressed = 1;
rx = ev.xbutton.x;
ry = ev.xbutton.y;
break;
case ButtonRelease:
done = 1;
break;
}
}
}
/* clear the drawn rectangle */
if (rect_w) {
XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
XFlush(disp);
}
rw = ev.xbutton.x - rx;
rh = ev.xbutton.y - ry;
/* cursor moves backwards */
if (rw < 0) {
rx += rw;
rw = 0 - rw;
}
if (rh < 0) {
ry += rh;
rh = 0 - rh;
}
XCloseDisplay(disp);
printf("%dx%d+%d+%d\n",rw,rh,rx,ry);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment