These instructions cover a non-root manual build of Bruce Ravel's Demeter package under Ubuntu 12.04. The instructions are deliberately written with a non-technical audience in mind and hence might read as somewhat patronizing for the technical reader. The main
# Working (overlays image on videotestsrc) | |
gst-launch-1.0 videomixer name=mix ! videoconvert ! xvimagesink multifilesrc location="test.png" caps="image/png,framerate=0/1" ! pngdec ! imagefreeze ! alpha method=0 alpha=0.5 ! mix. videotestsrc ! "video/x-raw,format=AYUV,framerate=25/1,width=320,height=240" ! mix. | |
# Fails (attempts to overlay image on webcam source) | |
gst-launch-1.0 videomixer name=mix ! videoconvert ! xvimagesink multifilesrc location="test.png" caps="image/png,framerate=0/1" ! pngdec ! imagefreeze ! alpha method=0 alpha=0.5 ! mix. v4l2src device=/dev/video0 ! "video/x-raw,format=YUY2,width=320,height=240" ! videoconvert ! mix. | |
# Output of failing command: | |
cat << EOF | |
Setting pipeline to PAUSED ... |
CASE WHEN ContractPrice < DiscountPrice | |
THEN | |
CASE WHEN ContractPrice < ListPrice THEN ContractPrice ELSE ListPrice END | |
ELSE | |
CASE WHEN DiscountPrice < ListPrice THEN DiscountPrice ELSE ListPrice END | |
END |
CREATE VIEW some_dates AS | |
WITH RECURSIVE dates(i, d) AS ( | |
VALUES (1, DATE('1970-01-01')) | |
UNION ALL | |
SELECT i + 1, d + 1 DAY FROM dates WHERE d < DATE('2070-12-31') | |
) | |
SELECT | |
d.d AS a_date, | |
YEAR(d.d) AS a_year, | |
MONTH(d.d) AS a_month, |
WITH qdps_with_rows AS ( | |
SELECT | |
ROW_NUMBER() OVER (PARTITION BY q.product_code) AS row_num, | |
q.* | |
FROM qdps q | |
) | |
SELECT | |
p.product_code, | |
SUM(CASE WHEN q.row_num = 1 THEN q.value END) AS qdp1, | |
SUM(CASE WHEN q.row_num = 2 THEN q.value END) AS qdp2, |
#!/usr/bin/env python | |
import json | |
from itertools import izip, cycle, groupby | |
from operator import itemgetter, attrgetter | |
# Imagine this is the result of some DB query like: | |
# SELECT region, year, value FROM some_table ORDER BY region, year | |
data = [ | |
('Southwark', 2009, 71.89), |
def process_iis_directory(d): | |
print('Processing IIS directory %s' % d) | |
for entry in os.listdir(d): | |
entry = os.path.join(d, entry) | |
if entry.endswith('.gz'): | |
print('Processing %s into CSV' % entry) | |
with gzip.open(entry, 'rb') as uncompressed, \ | |
io.BufferedReader(uncompressed) as buffered, \ | |
io.TextIOWrapper(buffered, encoding='latin1') as infile, \ | |
io.open(os.path.splitext(entry)[0] + '.csv', 'wb') as outfile, \ |
def factorial(i): | |
if i > 1: | |
return factorial(i - 1) * i | |
elif i == 1: | |
return 1 | |
else: | |
raise ValueError('Cannot take factorial of %d' % i) | |
Assuming you want to record 10 seconds of video before motion is detected, and 10 seconds of video after motion is detected, you can simply create a circular buffer with enough space for 20 seconds of video, wait until motion is detected, then wait 10 seconds more, and only then write the contents of the circular buffer to disk. basic_circular.py
demonstrates this.
The second example is a little more complicated and results in a couple of files per motion event: the 10 seconds before and the all seconds that motion is still occurring after first detection. Once motion is detected, we start recording subsequent frames to a file, and while that's going on, dump the circular buffer to another file. Once we stop detecting motion, we close the "after" file, and split recording back to the circular stream. This is demonstrated in advanced_circular.py
.
import io | |
import picamera | |
class MyOutput(object): | |
def __init__(self): | |
self.file_num = 0 | |
self.output = None | |
def write(self, buf): | |
if buf.startswith(b'\xff\xd8'): |