def control_camera(action): """ :param action: specified action such as down, up, left, right, stop, start :return: result of operation """ msg = 'action with cam: %s' % action logger.debug(msg) try: if action == 'stop': result = commands.getoutput('pkill -9 raspivid') logger.debug(result) return True elif action == 'start': result = commands.getoutput('pkill -9 raspivid') file_name = videoapi.get_name_video(settings.EXTENSION_VIDEO_FILE) path = settings.VIDEO_DIR # logger.debug(path) file_name = '%s/%s' % (path, file_name) # logger.debug(file_name) default_detail = videoapi.get_all_default_value() if default_detail is None: logger.error('Can get default detail of value') return False fps = default_detail[settings.VIDEO_TYPE_OPTION[1][0]] h = default_detail[settings.VIDEO_TYPE_OPTION[2][0]]['h'] w = default_detail[settings.VIDEO_TYPE_OPTION[2][0]]['w'] bit_rate = default_detail[settings.VIDEO_TYPE_OPTION[0][0]] command = '/usr/bin/raspivid -t 0 -w %s -h %s -fps %s -b %s -vf -o -| tee %s | /usr/local/bin/ffmpeg -i - ' \ '-vcodec copy -an -f flv -metadata streamName=myStream tcp://0.0.0.0:6666' % \ (w, h, fps, bit_rate, file_name) logger.debug(command) result = commands.getoutput(command) logger.debug(result) return True elif action == 'left' or action == 'down' or action == 'up' or action == 'right': control_cam_path = settings.CONTROL_CAM_PATH command = '%s/%s' % (control_cam_path, action) result = commands.getoutput(command) result = commands.getoutput(command) result = commands.getoutput(command) result = commands.getoutput(command) result = commands.getoutput(command) logger.debug(result) # Success to perform action if result == '': return True return False except Exception as detail: logger.debug(detail) return False
def run_raspivid_process_without_streaming(): file_name = videoapi.get_name_video(settings.EXTENSION_VIDEO_FILE) file_name = '%s/%s' % (settings.VIDEO_DIR, file_name) query = 'raspivid -t 0 -w 960 -h 540 -fps 25 -b 500000 -vf -o %s' % file_name # logger.debug(query) logger.debug(query) result = commands.getoutput(query)