コード例 #1
0
ファイル: magik.py プロジェクト: yffud/zmMagik
def process_timeline():

    try:
        os.remove('blended.mp4')
    except:
        pass

    url = g.args['portal'] + '/api/events/index/StartTime >=:' + g.args[
        'from'] + '/EndTime <=:' + g.args['to']
    if g.args['objectonly']:
        url = url + '/Notes REGEXP:detected:'
    if g.args['alarmonly']:
        url = url + '/AlarmFrames >=:' + str(g.args['minalarmframes'])
    if g.args['blend'] and len(g.mon_list) > 1:
        utils.bold_print(
            'You have chosen to blend events from multiple monitors. Results may be poor. Blending should typically be done on a fixed view (single monitor)'
        )
    for mon in g.mon_list:
        #   print (mon)
        url = url + '/MonitorId =:' + str(mon)

    url = url + '.json?sort=StartTime&direction=asc&username='******'username'] + '&password='******'password']
    print('Getting list of events using: {}'.format(url))
    resp = requests.get(url)
    #print (resp.json())
    events = resp.json()['events']

    cnt = 0
    delay = 0
    for event in events:
        cnt = cnt + 1
        #print (event['Event']['Id'])
        url_download = g.args[
            'portal'] + '/index.php?view=view_video&eid=' + event['Event'][
                'Id'] + '&username='******'username'] + '&password='******'password']
        in_file = url_download

        print(
            '\n==============| Processing Event: {} Monitor: {} ({} of {})|============='
            .format(event['Event']['Id'], event['Event']['MonitorId'], cnt,
                    len(events)))

        #print ("VIDEO ID IS:",event['Event']['DefaultVideo'])
        if event['Event']['DefaultVideo'] is "":
            utils.fail_print("ERROR: only mp4 events supported, skipping")
            continue
        if g.args['download']:
            in_file = event['Event']['Id'] + '.mp4'
            utils.dim_print('downloading {}'.format(url_download))
            try:
                urllib.request.urlretrieve(url_download, in_file)
            except IOError as e:
                utils.fail_print('ERROR:{}'.format(e))
            except:  #handle other exceptions such as attribute errors
                utils.fail_print("Unexpected error:" + sys.exc_info()[0])

        g.out_file = 'analyzed-' + event['Event']['Id'] + '.mp4'

        #print (in_file, out_file)
        try:
            if g.args['blend']:
                res = zmm_blend.blend_video(
                    input_file=in_file,
                    out_file=g.out_file,
                    eid=event['Event']['Id'],
                    mid=event['Event']['MonitorId'],
                    starttime=event['Event']['StartTime'],
                    delay=delay)
                delay = delay + g.args['blenddelay']
            elif g.args['annotate']:
                res = zmm_annotate.annotate_video(
                    input_file=in_file,
                    out_file=g.out_file,
                    eid=event['Event']['Id'],
                    mid=event['Event']['MonitorId'],
                    starttime=event['Event']['StartTime'])

            elif g.args['find']:
                res = zmm_search.search_video(input_file=in_file,
                                              out_file=g.out_file,
                                              eid=event['Event']['Id'],
                                              mid=event['Event']['MonitorId'])
            else:
                raise ValueError('Unknown mode?')
            if not g.args['all'] and res:
                break
        except IOError as e:
            utils.fail_print('ERROR:{}'.format(e))

        if g.args['download']:
            try:
                os.remove(in_file)
            except:
                pass
コード例 #2
0
ファイル: magik.py プロジェクト: yffud/zmMagik
            urllib.request.urlretrieve(g.args['input'], fname)
            g.args['input'] = fname
            remove_downloaded = True
        g.out_file = 'analyzed-' + fname

    if g.args['find']:
        res = zmm_search.search_video(input_file=g.args['input'],
                                      out_file=g.out_file,
                                      eid=g.args['eventid'],
                                      mid=None,
                                      starttime=None,
                                      delay=0)
    elif g.args['blend']:
        res = zmm_blend.blend_video(input_file=g.args['input'],
                                    out_file=g.out_file,
                                    eid=g.args['eventid'],
                                    mid=None,
                                    starttime=None,
                                    delay=g.args['blenddelay'])
    elif g.args['annotate']:
        res = zmm_annotate.annotate_video(input_file=g.args['input'],
                                          eid=g.args['eventid'],
                                          mid=None,
                                          starttime=None)

end_time = time.time()
print('\nTotal time: {}s'.format(round(end_time - start_time, 2)))
if g.args['dumpjson']:
    jf = 'analyzed-' + datetime.now().strftime("%m_%d_%Y_%H_%M_%S") + '.json'
    print('Writing output to {}'.format(jf))
    with open(jf, 'w') as jo:
        json.dump(g.json_out, jo)