def get_devices(refresh_devices): curr_input_id_list = get_input_src_id_list() num_input_src = len(curr_input_id_list) if num_input_src != 0 and refresh_devices == False: return num_input_src # Stop all running instances and remove all input sources if refresh is requested if refresh_devices == True: for i in range(0, num_input_src): stopencoder.stop_encoder(i) configdb.delete_config('CapInputNames') num_input_src = get_decklink_devices() num_input_src += get_v4l2_devices() num_input_src += get_avfoundation_devices() return num_input_src
def delete(self, inst_id=None): status_code, reason = stopencoder.stop_encoder(inst_id) if status_code == 200: status_code, reason = wc_input_source.remove_input(inst_id) status = str(status_code) + ' ' + str(reason) self.response.set_status(status) self.response.headers['Content-Type'] = 'text/html' self.response.out.write('')
def start_encoder(enc_params): print 'Starting encoder' """ WSGI Application that gets called with the set environment and the response generation function. """ default_config = { "input_id": "-1", "video": { "speed_preset": "fast", "rate_control": "cbr", "enable_cc": "on", "num_b_frame": 8, "variants": [{ "codec": "libx264", "bitrate": "-1", "video_width": "-1", "video_height": "-1", "audio_tag": "0" }] }, "audio": { "0": { "bitrate": "-1", "codec": "aac" } }, "output": { "out_type": "HLS", "segment_size": "5", "burn_tc": "off", "create_muxed_av": "off", "enable_abs_seg_path": "off", "abs_seg_path_base_url": "", "seg_in_subfolder": "off", "ingest_url": "", "b_ingest_url": "", "dash_chunked": "off", "lhls": "off", "hls_master_manifest": "master.m3u8", "dash_master_manifest": "out.mpd" }, } ffmpeg_proc_name = 'ffmpeg ' store_default_config(default_config, enc_params) status, msg = validate_encoder_params(enc_params) if False == status: reason = 'Bad Request: ' + msg return 400, reason input_id = str(enc_params['input_id']) segment_size = wc_utils.to_int(enc_params['output']['segment_size']) out_type = enc_params['output']['out_type'] print 'Inside start_encoder.py input_id:' + str(enc_params['input_id']) #Kill any existing process stopencoder.stop_encoder(input_id) #Store the json input in a file store_load_input_cfg.store_json_cfg(enc_params) enc_params['input'] = {} enc_params['input']['input_interface'] = capture.get_input_interface( int(input_id)) enc_params['input']['inputurl'] = capture.get_inputurl(int(input_id)) ffmpeg_format_args = '' if enc_params['input']['input_interface'] == capture.INPUT_INTERFACE_URL: ffmpeg_format_args += ' -timeout 1000000 -analyzeduration 5000000 ' else: ffmpeg_format_args += ' -probesize 10M -f ' + enc_params['input'][ 'input_interface'] ffmpeg_format_args += ' -i %s' % (enc_params['input']['inputurl']) vid_w, vid_h, vid_fr, scantype, device_status = capture.find_input_format( ffmpeg_proc_name + ffmpeg_format_args) if device_status != 'Active': print 'Input signal detection failed: ' + str(device_status) enc_params['input']['vid_width'] = vid_w enc_params['input']['vid_height'] = vid_h enc_params['input']['vid_framerate'] = vid_fr enc_params['input']['vid_scantype'] = scantype enc_params['output']['user_agent'] = USER_AGENT enc_params['output']['drawbox_width'] = 500 enc_params['output']['drawbox_height'] = 88 enc_params['output']['fonttype'] = "FreeSerif" enc_params['output']['fontsize'] = 80 args = wc_ffmpeg_args.get_args(enc_params) print ffmpeg_proc_name + args proc = subprocess.Popen(shlex.split(ffmpeg_proc_name + args)) pid = proc.pid current_time = time.time() * 1000000 for n in range(0, len(enc_params['video']['variants'])): cfg = { 'TIME': int(current_time), #current time 'InputID': int(input_id), #Input ID 'SubStreamID': int(n), #Substream ID 'ProcessID': pid, #ProcessID 'VidInWidth': int(vid_w), #Input video width 'VidInHt': int(vid_h), #Input video height 'InScanType': str(scantype), #Input scantype 'VidInFrameRate': str(vid_fr), #Input framerate 'FrameRate': str(vid_fr), #Output framerate } configdb.insert_stream_config(cfg) print 'All Ok, encoder started successfully' return 200, 'OK'