]> www.vanbest.org Git - motioneye-debian/commitdiff
Merge branch 'master' into masksupport
authorCalin Crisan <ccrisan@gmail.com>
Mon, 12 Sep 2016 19:22:40 +0000 (22:22 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Mon, 12 Sep 2016 19:22:40 +0000 (22:22 +0300)
1  2 
motioneye/config.py
motioneye/static/js/main.js
motioneye/templates/main.html
motioneye/utils.py

index 0b9ec4d472e8691c85a8bf3babd2758b2fc9485b,bfbafecaff6a103c8d95a1d9d20b169250baa0bc..4b82ad9dbe0294de94962f616e57dcf08818399d
@@@ -843,27 -854,16 +857,27 @@@ def motion_camera_ui_to_dict(ui, old_co
          elif recording_mode == 'continuous':
              data['emulate_motion'] = True
  
-     if proto == 'v4l2':
-         max_val = data['width'] * data['height'] * data['framerate']
-     
-     else: # assume a netcam image size of 640x480, since we have no means to know it at this point
-         max_val = 640 * 480 * data['framerate']
-     max_val = min(max_val, 9999999)
+     data['ffmpeg_video_codec'] = ui['movie_format']
+     q = int(ui['movie_quality'])
+     if data['ffmpeg_video_codec'] in _EXPONENTIAL_QUALITY_CODECS:
+         vbr = max(1, _MAX_FFMPEG_VARIABLE_BITRATE * (1 - math.log(max(1, q * _EXPONENTIAL_QUALITY_FACTOR), _EXPONENTIAL_QUALITY_FACTOR * 100)))
+         
+     else:
+         vbr = 1 + (_MAX_FFMPEG_VARIABLE_BITRATE - 1) / 100.0 * (100 - q)
  
-     data['ffmpeg_bps'] = int(int(ui['movie_quality']) * max_val / 100)
+     data['ffmpeg_variable_bitrate'] = int(vbr)
  
 +    # motion detection
 +    if ui['mask']:
 +        if ui['mask_type'] == 'smart':
 +            data['smart_mask_speed'] = 10 - int(ui['smart_mask_slugginess'])
 +
 +        elif ui['mask_type'] == 'editable':
 +            data['mask_file'] = utils.build_editable_mask_file(ui['editable_mask'])
 +
 +        else:
 +            data['mask_file'] = ui['mask_file']
 +
      # working schedule
      if ui['working_schedule']:
          data['@working_schedule'] = (
Simple merge
Simple merge
index d3f0765f89cdd140e8355d3b58083dfa2b463984,d9258fe200f325ae50e6052a615be59e7d16727e..50763e75a1a3d80c7149a7bc05509c6927346987
@@@ -23,13 -23,12 +23,15 @@@ import loggin
  import os
  import re
  import socket
 +import struct
+ import sys
  import time
  import urllib
+ import urllib2
  import urlparse
  
 +from PIL import Image, ImageDraw
 +
  from tornado.httpclient import AsyncHTTPClient, HTTPRequest
  from tornado.iostream import IOStream
  from tornado.ioloop import IOLoop
@@@ -719,48 -766,17 +769,64 @@@ def build_digest_header(method, url, us
      return 'Digest %s' % (base)
  
  
+ def urlopen(*args, **kwargs):
+     if sys.version_info >= (2, 7, 9) and not settings.VALIDATE_CERTS:
+         # ssl certs are not verified by default
+         # in versions prior to 2.7.9
+         import ssl
+         ctx = ssl.create_default_context()
+         ctx.check_hostname = False
+         ctx.verify_mode = ssl.CERT_NONE
+     
+         kwargs.setdefault('context', ctx)
+     return urllib2.urlopen(*args, **kwargs)
++
++
 +def build_editable_mask_file(editable_mask):
 +    width = editable_mask[0]
 +    height = editable_mask[1]
 +    nx = editable_mask[2]
 +    ny = editable_mask[3]
 +    lines = editable_mask[4:]
 +    
 +    data = struct.pack('<HHBB', width, height, nx, ny)
 +    for line in lines:
 +        data += struct.pack('<I', line)
 +    
 +    name = base64.b64encode(data, '-_')
 +    
 +    # draw the actual mask image content
 +    im = Image.new('L', (width, height), 255) # all white
 +    dr = ImageDraw.Draw(im)
 +
 +    rw = width / nx
 +    rh = height / ny
 +
 +    for y in xrange(ny):
 +        line = lines[y]
 +        for x in xrange(nx):
 +            if line & (31 - x):
 +                print line & (31 - x)
 +                dr.rectangle((x * rw, y * rh, (x + 1) * rw, (y + 1) * rh), fill=0)
 +
 +    file_name = os.path.join(settings.CONF_PATH, name) + '.pgm'
 +    im.save(file_name, 'ppm')
 +
 +    return name
 +
 +
 +def parse_editable_mask_file(file_name):
 +    name = os.path.splitext(os.path.basename(file_name))[0]
 +    try:
 +        data = base64.b64decode(name, '-_')
 +        width, height, nx, ny = struct.unpack('<HHBB', data[:6])
 +        fmt = '<' + 'I' * ny
 +        lines = struct.unpack(fmt, data[6:])
 +        
 +        return [width, height, nx, ny] + list(lines)
 +
 +    except Exception:
 +        return None