Close

Seamless Import

A project log for Metaverse Lab

Experiments with Decentralized VR/AR Infrastructure, Neural Networks, and 3D Internet.

alusionalusion 04/15/2015 at 23:160 Comments

slop (Select Operation) is an application that queries for a selection from the user and prints the region to stdout.

For this you will need FFmpeg and xclip installed. I needed to have a way to select something on my desktop and open it in Janus. For the filehosting I used Teknik and modified the file upload script to copy to clipboard:

#!/usr/bin/env bash
# requires: bash 4.0+, curl
files="$@"
if [[ -z "${files}" ]]; then
    printf 'You must submit a file to be uploaded!\n'
    exit 1
else
    printf 'Uploading file(s) now!'
    n=1
    for i in "$@"; do
        printf "\nUploading file #${n} ... "
        out=$(curl -sf -F file="@${i}" https://api.somewebsite.io/upload/post)
        if [[ "${out}" =~ "error" ]]; then
            printf 'error uploading file!\n'
            exit 1
        else
            out="${out##*name\":\"}"
            out="${out%%\"*}"
            printf "uploaded! Your file can be found at https://u.somewebsite.io/${out}\n"
            xclip -selection clipboard <<< "https://u.somewebsite.io/${out}" 
        fi
        ((n++))
    done
fi

I stuck the script in my /usr/local/bin directory. Before installing slop make sure you have libXext installed as a dependency. The steps are straight forward from there:

git clone https://github.com/naelstrof/slop.git
cd slop
cmake ./
make && sudo make install

Slop has a lot of nice features such as supporting transparency, selecting x-display, removing window decorations, and having a much cleaner select rectangle than scrot -s.

You can create a video recording script in two lines of code, and ffmpeg will record it in a format of your choice. The combination is insanely powerful.

#!/bin/bash
eval $(slop)
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f alsa -i pulse ~/myfile.webm

Here is the one liner I made to record a window or selection and automatically upload it to a website, copying the URL directly to keyboard:

KEK="$(mktemp /tmp/out-XXXXXXXX.webm)"; eval $(slop); ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f alsa -i pulse $KEK; upload $KEK

I know using eval $(slop) isn't the cleanest solution and the examples on the github were terrible (calling awk 6 times) so I wrote my own bash script to improve the dirty one liner. Here's the finished script:

#!/bin/bash
# Requires xclip, upload, slop, ffmpeg
# optional maim ( https://github.com/naelstrof/maim )
# create a temporary file with -u flag
tmp="$(mktemp -u /tmp/out-XXXXXXXX.webm)";
# g and id are used when maim is called
read -r x y w h g id < <(slop -f "%x %y %w %h %g $id");
# maim -g $g -i $id
# record x11 window and output as webm
ffmpeg -f x11grab -s "$w"x"$h" -i :0.0+"$x","$y" -f alsa -i pulse "$tmp";
# upload to some website
upload "$tmp"

A cool way to implement this was to save it as a shell script (topkek) and gave it execute permission with chmod +x topkek and keybind it to a hotkey. I use openbox so I edited my rc.xml file (~/.config/openbox) and added the keybind to map to my windows key + j. Now just restart openbox and it should work. As a note, you should also hotkey a kill command.

    <keybind key="W-j">
        <action name="Execute">
            <startupnotify>
                <enabled>true</enabled>
                <name>slop</name>
            </startupnotify>
            <command>topkek</command>
        </action>
    </keybind>

I livestreamed from my android phone to vlc on my computer using Spydroid, ran the script that records the VLC window and uploads it to the filehosting site and copies the URL to my clipboard. I then open up the link in a new portal to see that which I just recorded: 

https://webmshare.com/wK918

I'm going to do some more tests and videos that can show the process better as well as how useful the application of this program can be. One test I have in mind is to go into a tunnel into a Linux shell from inside janus and record the x11 Window of a webcam and import that into the room. It's acts like you are reaching into the physical world and bringing it back into the virtual, audio included. I'll setup a raspberry pi or spare laptop and return to this idea later.

Discussions