Skip to content
Snippets Groups Projects
Commit 7e5e2d8c authored by Lars Beckers's avatar Lars Beckers Committed by Christopher Spinrath
Browse files

clean up

parent aa2479a2
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys, os, re, subprocess, string
from threading import Timer
import pygtk, gtk
import gst
import zbar, Image
#
# required dependencies:
# zbar (http://pypi.python.org/pypi/zbar)
# Python Imaging Library (http://www.pythonware.com/products/pil/index.htm)
# gstreamer python bindings (http://gstreamer.freedesktop.org/modules/gst-python.html)
# firefox (http://www.mozilla.org/en-US/firefox/fx/#desktop)
#
class GTK_Main:
def __init__(self):
self.clean()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Webcam-Viewer")
window.set_default_size(500, 400)
window.connect("destroy", gtk.main_quit, "WM destroy")
vbox = gtk.VBox()
window.add(vbox)
self.movie_window = gtk.DrawingArea()
vbox.add(self.movie_window)
hbox = gtk.HBox()
vbox.pack_start(hbox, False)
hbox.set_border_width(10)
hbox.pack_start(gtk.Label())
self.button = gtk.Button("Quit")
self.button.connect("clicked", self.exit)
hbox.pack_start(self.button, False)
self.button_restart = gtk.Button('Restart')
self.button_restart.connect('clicked',self.restart)
hbox.pack_start(self.button_restart,True)
hbox.add(gtk.Label())
window.show_all()
# Set up the gstreamer pipepile
self.player = gst.parse_launch ("""v4l2src !
tee name=t ! queue ! autovideosink t.
! queue ! videorate ! video/x-raw-yuv, width=800, height=600, framerate=1/1
! jpegenc ! multifilesink location=snapshot-%03d.jpg""")
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect('message', self.on_message)
bus.connect('sync-message::element', self.on_sync_message)
self.player.set_state(gst.STATE_PLAYING)
self.scan()
def exit(self, widget, data=None):
self.t.cancel()
self.clean()
gtk.main_quit()
def restart(self, widget, data=None):
self.clean()
self.scan()
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
self.button.set_label("Start")
elif t == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.player.set_state(gst.STATE_NULL)
self.button.set_label("Start")
def on_sync_message(self, bus, message):
if message.structure is None:
return
message_name = message.structure.get_name()
if message_name == 'prepare-xwindow-id':
# Assign the viewport
imagesink = message.src
imagesink.set_property('force-aspect-ratio', True)
imagesink.set_xwindow_id(self.movie_window.window.xid)
def scan(self):
files = os.listdir(".")
files = filter(lambda x: re.search('^snapshot-[0-9]*.jpg$', x) != None, files)
for f in files:
print("processing image: "+str(f))
self.process_qr(str(f))
os.remove(f)
self.t = Timer(3.0, self.scan)
self.t.start()
def process_qr(self, picture):
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
pil = Image.open(picture).convert('L')
width,height = pil.size
raw = pil.tostring()
image = zbar.Image(width,height,'Y800',raw)
scanner.scan(image)
no_qr = True
result = ''
for symbol in image:
qr = symbol.data
print(qr)
if qr.find('http://fsmpi.rwth-aachen.de/lip/view/') >= 0:
os.system('firefox -new-tab '+qr)
elif qr.find('pk: ') >= 0:
pk = string.split(string.split(qr,'%')[0],': ')[1]
os.system('firefox -new-tab http://fsmpi.rwth-aachen.de/lip/view/' + pk + '+0')
else:
self.invalid_code()
no_qr = False
del(image)
if no_qr:
print('\033[1;31mno QR code found\033[1;m')
else:
exit()
def stop(self):
exit()
def clean(self):
files = os.listdir(".")
files = filter(lambda x: re.search('^snapshot-[0-9]*.jpg$', x) != None, files)
for f in files:
os.remove(f)
def invalid_code(self):
print('\033[1;41m _ _ _ _ _ ___ _ _ ___ ___ ___ ___ ___ ___ ___ \033[1;m')
print('\033[1;41m | || \| || | |/ - \| | | || \ / \| - | / _|/ \| \| __| \033[1;m')
print('\033[1;41m | || \ || | || | || |_ | || | | | | || \ | (_ | | || | || __| \033[1;m')
print('\033[1;41m |_||_\__| \_/ |_|_||___||_||___/ \__\_|_|\_\ \___|\___/|___/|___| \033[1;m')
print('\033[1;41m \033[1;m')
g = GTK_Main()
gtk.gdk.threads_init()
gtk.main()
#!/bin/bash
# ffmpeg recorder script for audio and video
# Source: http://filmsbykris.com/wordpress/screen-capturing-with-ffmpeg/
cd $HOME/Videos/tutorials/original
SavePath=$(zenity --file-selection --save --confirm-overwrite)
echo "Saving video to $szSavePath"
INFO=$(xwininfo -frame)
WIN_GEO=$(echo "$INFO"|grep -e "Height:" -e "Width:"|cut -d\: -f2|tr "\n" " "|awk '{print $1 "x" $2}')
WIN_POS=$(echo "$INFO"|grep "upper-left"|head -n 2|cut -d\: -f2|tr "\n" " "|awk '{print $1 "," $2}')
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s $WIN_GEO -r 15 -i :0.0+$WIN_POS -r 15 -acodec pcm_s16le -sameq "$SavePath.avi"
echo "$WIN_GEO -i :0.0+$WIN_POS -acodec"
echo "$WIN_POS"
#!/bin/bash
# dirty little script to split a video into 15 minutes parts with ten
# seconds overlap (for upload to youtube)
# Author: milan <milan.santosi@gmail.com>
#
# USAGE: read comments and adjust where necessary, then:
# ./ffmpeg_splitter.sh <inputfile>
####################################################################
# use globbing to get basename and extension.
# see http://linuxgazette.net/18/bash.html
fname=$1 # the file name
bname=${fname%%.*} # the file basename
ext=${fname#*.} # the file extension
# to avoid async a/v, re-encode with every frame as keyframe
if
test -f $bname-keyframes.$ext
then
:
else
ffmpeg -g 1 -i $1 $bname-keyframes.$ext
fi
# get length of the original video, calculate amount of segments and
# combined length of all parts (with overlap)
let vidlen=$(ffprobe -show_format $bname-keyframes.$ext | grep duration | cut -d "." -f 1 | cut -d "=" -f 2)
let segcount=$vidlen/900
let withoverlap=$vidlen+$segcount*10
let newsegcount=$withoverlap/900
# loop until it's done (actually one more time, just to make sure)
for (( i = 1; i <= $newsegcount+1; i++))
do
ffmpeg -vcodec copy -acodec copy -ss $[i*890 - 890] -t 899.999 -i $bname-keyframes.$ext $bname-part0$i.$ext
done
#!/bin/bash
# Dieses Skript verwendet avconv oder ffmpeg um den Bildschirm aufzunehmen.
# Wenn AUDIO=1 gesetzt ist wird auch der Ton aufgenommen.
# In die Variable $DEVICE wird der Bezeichner des Anschlusse eingetragen, von dem aufgenommen werden soll (siehe xrandr).
# Erster und einziger, optionaler, Parameter ist die Datei, in die gespeichert wird. Wenn die nicht angegeben wird wird nach cap.avi gespeichert.
# Teilweise gibt es Probleme mit der Syncronität Bild<->Ton, daher dringen auf den Präsentationslaptops ausprobieren.
DEVICE="VGA"
AUDIO=0
info=$(xrandr | grep $DEVICE)
res=$(echo $info | grep -Eo '[0-9]+x[0-9]+')
pos=$(echo $info | grep -Eo '\+[0-9]+\+[0-9]+')
if [ "$1" == "" ]
then
file=cap.avi
else
file=$1
fi
if which avconv
then
prog=avconv
elif which ffmpeg
then
prog=ffmpeg
else
echo "Weder avconv, noch ffmpeg gefunden!"
exit
fi
if [ $AUDIO -eq 1 ]
then
audiocmd="-f alsa -ac 2 -i hw:0,0 -r 25 -c:a pcm_s16le"
else
audiocmd="-an"
fi
$prog -f x11grab -s $res -r 25 -i :0.0$pos $audiocmd -c:v libx264 -crf 1 -preset:v fast $file
#!/bin/bash
# Dieses Skript verwendet recordmydesktop um den Bildschirm + Ton aufzunehmen.
# In die Variable $DEVICE wird der Bezeichner des Anschlusse eingetragen, von dem aufgenommen werden soll (siehe xrandr).
# Wenn ON_THE_FLY_ENCODING=1 ist wird das Video direkt bei der Aufnahme encodiert. Dies frist einiges an Rechenleistung, falls die Aufnahme aber abbricht ist alles bis zum Abbruch vorhanden und das fertige Video steht direkt nach der Beendigung der Aufnahme zur Verfügung. Sonst dauert es am Ende noch einige Zeit.
# Erster und einziger, optionaler, Parameter ist die Datei, in die gespeichert wird. Wenn die nicht angegeben wird wird nach out.ogv gespeichert.
# Teilweise gibt es Probleme mit der Syncronität Bild<->Ton, daher dringen auf den Präsentationslaptops ausprobieren.
DEVICE="VGA"
ON_THE_FLY_ENCODING=1
FPS="15"
info=$(xrandr | grep $DEVICE | grep -Eo '[0-9]+x[0-9]+\+[0-9]*\+[0-9]*' | tr x+ " ")
x=$(echo $info | awk '{print $3}')
y=$(echo $info | awk '{print $4}')
width=$(echo $info | awk '{print $1}')
height=$(echo $info | awk '{print $2}')
if ! which recordmydesktop
then
echo "recordmydesktop nicht gefunden!"
exit
fi
if [ $x -gt 0 ]
then
cmd="$cmd -x $x"
fi
if [ $y -gt 0 ]
then
cmd="$cmd -y $y"
fi
if [ $ON_THE_FLY_ENCODING -eq 1 ]
then
cmd="$cmd --on-the-fly-encoding"
fi
recordmydesktop $cmd --fps $FPS --width $width --height $height $1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment