def run_vfs(video_uri, out_dir, r_config):
    """
    Processing all participants for fetching voice frame score
    ---------------
    ---------------
    Args:
        video_uri: video path; r_config: raw variable config object
        out_dir: (str) Output directory for processed output
    """
    try:

        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)
        aud_filter = glob.glob(join(input_loc, fl_name + '.wav'))
        if len(aud_filter) > 0:

            audio_file = aud_filter[0]
            aud_dur = librosa.get_duration(filename=audio_file)

            if float(aud_dur) < 0.064:
                logger.info('Output file {} size is less than 0.064sec'.format(
                    audio_file))

                empty_vfs(video_uri, out_loc, fl_name, r_config)
                return

            calc_vfs(video_uri, audio_file, out_loc, fl_name, r_config)
    except Exception as e:
        logger.error('Failed to process audio file')
Beispiel #2
0
def run_eye_gaze(video_uri, out_dir, r_config):
    """
    Processing all patient's for getting eye movement artifacts 
    --------------------------------
    --------------------------------
    Args:
        video_uri: video path; input_dir : input directory for video's
        out_dir: (str) Output directory for processed output; r_config: raw variable config object
    """
    try:

        #filtering path to generate input & output path
        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)
        of_csv_path = glob.glob(join(out_loc, fl_name + '_OF_features/*.csv'))

        if len(of_csv_path) > 0:

            of_csv = of_csv_path[0]
            df_of = pd.read_csv(of_csv, error_bad_lines=False)

            logger.info('Processing Output file {} '.format(
                os.path.join(out_loc, fl_name)))
            calc_eye_mov(video_uri, df_of, out_loc, fl_name, r_config)
    except Exception as e:
        logger.error('Failed to process video file')
def batch_open_face(filepaths,video_url, input_dir, out_dir, of_path):
    """ Computes open_face features for the files in filepaths
    
    Args:
    -----
        filepaths: (itreable[str])
        video_tracking: To specify whether openface's video tracking module (FaceLandmarkVid)
                    is being used or the default (FeatureExtract)
        video_url: Raw video location on S3 bucket
        input_dir: Path to the input videos
        out_dir: Path to the processed output
        of_path: OpenFace source code path
                    
    Returns:
    --------
        (itreable[str]) list of .csv files
    """
    
    suffix = '_OF_features'
    csv_files = []
    
    for fp in filepaths:
        try:
            
            _, out_loc, fl_name = ut.filter_path(video_url, out_dir)
            full_f_name = fl_name + suffix
            output_directory = os.path.join(out_loc, full_f_name)

            csv_files.append(ut.compute_open_face_features(fp,output_directory,of_path))
            
        except Exception as e:
            logger.error('Failed to run OpenFace on {}\n{}'.format(fp, e))
            
    return csv_files
Beispiel #4
0
def run_face_expressivity(video_uri, out_dir, f_cfg):
    """
    Processing all patient's for fetching facial landmarks
    ---------------
    ---------------
    Args:
        video_uri: video path; f_cfg: raw variable config object
        out_dir: (str) Output directory for processed output
    """
    try:

        #Baseline logic
        cfr = ConfigFaceReader()
        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)

        of_csv_path = glob.glob(join(out_loc, fl_name + '_OF_features/*.csv'))
        if len(of_csv_path) > 0:

            df_of = pd.read_csv(of_csv_path[0], error_bad_lines=False)
            df_of = df_of[cfr.AU_fl]
            expr_df_list = of_feature(df_of, cfr, f_cfg)

            exp_final_df = pd.concat(expr_df_list, ignore_index=True)
            exp_final_df['dbm_master_url'] = video_uri

            logger.info('Processing Output file {} '.format(
                os.path.join(out_loc, fl_name)))
            ut.save_output(exp_final_df, out_loc, fl_name, face_expr_dir,
                           csv_ext)

    except Exception as e:
        logger.error('Failed to process video file')
Beispiel #5
0
def run_transcribe(video_uri, out_dir, r_config, deep_path):
    """
    Processing all patient's for fetching Formant freq
    ---------------
    ---------------
    Args:
        video_uri: video path; r_config: raw variable config object
        out_dir: (str) Output directory for processed output; deep_path: deepspeech build path
    """
    try:

        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)
        aud_filter = glob.glob(join(input_loc, fl_name + '.wav'))
        if len(aud_filter) > 0:

            audio_file = aud_filter[0]
            aud_dur = librosa.get_duration(filename=audio_file)

            if float(aud_dur) < 0.1:
                logger.info('Output file {} size is less than 0.1 sec'.format(
                    audio_file))

                empty_transcribe(video_uri, out_loc, fl_name, r_config)
                return

            calc_transcribe(video_uri, audio_file, out_loc, fl_name, r_config,
                            deep_path, aud_dur)
    except Exception as e:
        logger.error('Failed to process audio file')
Beispiel #6
0
def run_face_asymmetry(video_uri, out_dir, f_cfg):
    """
    Processing all patient's for calculating facial asymmetry
    ---------------
    ---------------
    Args:
        video_uri: video path; f_cfg: face config object
        out_dir: (str) Output directory for processed output
    """
    try:

        #Baseline logic
        cfr = ConfigFaceReader()
        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)

        of_csv_path = glob.glob(join(out_loc, fl_name + '_OF_features/*.csv'))
        if len(of_csv_path) > 0:

            of_csv = of_csv_path[0]
            asym_df_list = calc_asym_feature(of_csv, f_cfg)

            asym_final_df = pd.concat(asym_df_list, ignore_index=True)
            asym_final_df['dbm_master_url'] = video_uri

            logger.info('Processing Output file {} '.format(
                os.path.join(out_loc, fl_name)))
            ut.save_output(asym_final_df, out_loc, fl_name, face_asym_dir,
                           csv_ext)

    except Exception as e:
        logger.error('Failed to process video file')
Beispiel #7
0
def run_pause_segment(video_uri, out_dir, r_config):
    """
    Processing all patient's for getting Pause Segment
    ---------------
    ---------------
    Args:
        video_uri: video path; r_config: raw variable config object
        out_dir: (str) Output directory for processed output
    """
    try:

        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)
        aud_filter = glob.glob(join(input_loc, fl_name + '.wav'))
        if len(aud_filter) > 0:

            audio_file = aud_filter[0]
            aud_dur = librosa.get_duration(filename=audio_file)

            if float(aud_dur) < 0.064:
                logger.info('Output file {} size is less than 0.064sec'.format(
                    audio_file))

                error_txt = 'error: length less than 0.064'
                empty_pause_segment(video_uri, out_loc, fl_name, r_config,
                                    error_txt)
                return

            logger.info('Converting stereo sound to mono-lD')
            sound_mono = AudioSegment.from_wav(audio_file)
            sound_mono = sound_mono.set_channels(1)
            sound_mono = sound_mono.set_frame_rate(48000)

            mono_wav = os.path.join(input_loc, fl_name + '_mono.wav')
            sound_mono.export(mono_wav, format="wav")

            df_pause_seg = process_silence(mono_wav, r_config)
            os.remove(mono_wav)  #removing mono wav file

            if isinstance(df_pause_seg,
                          pd.DataFrame) and len(df_pause_seg) > 0:
                logger.info('Processing Output file {} '.format(out_loc))

                df_pause_seg['dbm_master_url'] = video_uri
                ut.save_output(df_pause_seg, out_loc, fl_name, pause_seg_dir,
                               csv_ext)

            else:
                error_txt = 'error: webrtcvad returns no segment'
                empty_pause_segment(video_uri, out_loc, fl_name, r_config,
                                    error_txt)

    except Exception as e:
        logger.error('Failed to process audio file')
Beispiel #8
0
def run_face_landmark(video_uri, out_dir, f_cfg):
    """
    Processing all patient's for fetching facial landmarks
    ---------------
    ---------------
    Args:
        video_uri: video path;  f_cfg: raw variable config object
        out_dir: (str) Output directory for processed output
    """
    try:

        #Baseline logic
        cfr = ConfigFaceReader()
        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)

        of_csv_path = glob.glob(join(out_loc, fl_name + '_OF_features/*.csv'))
        if len(of_csv_path) > 0:

            df_of = pd.read_csv(of_csv_path[0], error_bad_lines=False)
            df_lmk = df_of[extract_col_nm_lmk(df_of)]
            df_lmk = df_lmk.copy()

            df_lmk['frame'] = df_of['frame']
            df_lmk['face_id'] = df_of[' face_id']
            df_lmk['timestamp'] = df_of[' timestamp']
            df_lmk['confidence'] = df_of[' confidence']
            df_lmk['success'] = df_of[' success']

            df_lmk = lmk_col_nm_map(df_lmk)
            df_lmk = add_disp_3D(df_lmk)
            df_lmk['dbm_master_url'] = video_uri

            logger.info('Processing Output file {} '.format(
                join(out_loc, fl_name)))
            ut.save_output(df_lmk, out_loc, fl_name, face_lmk_dir, csv_ext)

    except Exception as e:
        logger.error('Failed to process video file')
Beispiel #9
0
def run_eye_blink(video_uri, out_dir, r_config, facial_landmarks):
    """
    Processing all patient's for getting eye blink artifacts
    ---------------
    ---------------
    Args:
        video_uri: video path; input_dir : input directory for video's
        out_dir: (str) Output directory for processed output; r_config: raw variable config object;
        facial_landmarks: landmark model path
    """
    try:

        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)
        vid_file_path = os.path.exists(video_uri)
        if vid_file_path == True:

            logger.info('Processing Output file {} '.format(
                os.path.join(out_loc, fl_name)))
            df_blink = blink_detection(video_uri, facial_landmarks, r_config)
            ut.save_output(df_blink, out_loc, fl_name, movement_expr_dir,
                           csv_ext)

    except Exception as e:
        logger.error('Failed to process video file')
Beispiel #10
0
def run_speech_feature(video_uri, out_dir, r_config):
    """
    Processing all patient's for fetching nlp features
    -------------------
    -------------------
    Args:
        video_uri: video path; r_config: raw variable config object
        out_dir: (str) Output directory for processed output
    """
    try:
        
        input_loc, out_loc, fl_name = ut.filter_path(video_uri, out_dir)

        transcribe_path = glob.glob(join(out_loc, transcribe_ext))
        if len(transcribe_path)>0:

            transcribe_df = pd.read_csv(transcribe_path[0])
            df_speech= n_util.process_speech(transcribe_df, r_config)

            logger.info('Saving Output file {} '.format(out_loc))
            ut.save_output(df_speech, out_loc, fl_name, speech_dir, speech_ext)
            
    except Exception as e:
        logger.error('Failed to process video file')