예제 #1
0
def filter_video_before_upload(video, filter_night_time=False):
    try:
        if not get_blackvue_info(video)['is_Blackvue_video']:
            print_error(
                "ERROR: Direct video upload is currently only supported for BlackVue DRS900S and BlackVue DR900M cameras. Please use video_process command for other camera files"
            )
            return True
        if get_blackvue_info(video)['camera_direction'] != 'Front':
            print_error(
                "ERROR: Currently, only front Blackvue videos are supported on this command. Please use video_process command for backwards camera videos"
            )
            return True
    except:
        print_error("ERROR: Unable to determine video details, skipping video")
        return True
    [gpx_file_path,
     isStationaryVid] = gpx_from_blackvue(video,
                                          use_nmea_stream_timestamp=False)
    video_start_time = get_video_start_time_blackvue(video)

    if isStationaryVid:
        if not gpx_file_path:
            if os.path.basename(os.path.dirname(video)) != 'no_gps_data':
                no_gps_folder = os.path.dirname(video) + '/no_gps_data/'
                if not os.path.exists(no_gps_folder):
                    os.mkdir(no_gps_folder)
                os.rename(video, no_gps_folder + os.path.basename(video))
            print_error(
                "Skipping file {} due to file not containing gps data".format(
                    video))
            return True
        if os.path.basename(os.path.dirname(video)) != 'stationary':
            stationary_folder = os.path.dirname(video) + '/stationary/'
            if not os.path.exists(stationary_folder):
                os.mkdir(stationary_folder)
            os.rename(video, stationary_folder + os.path.basename(video))
            os.rename(gpx_file_path,
                      stationary_folder + os.path.basename(gpx_file_path))
        print_error(
            "Skipping file {} due to camera being stationary".format(video))
        return True

    if not isStationaryVid:
        gpx_points = get_points_from_bv(video)
        gps_video_start_time = gpx_points[0][0]
        if filter_night_time == True:
            # Unsupported feature: Check if video was taken at night
            # TODO: Calculate sun incidence angle and decide based on threshold
            # angle
            sunrise_time = 9
            sunset_time = 18
            try:
                timeZoneName, local_timezone_offset = get_timezone_and_utc_offset(
                    gpx_points[0][1], gpx_points[0][2])
                if timeZoneName is None:
                    print(
                        "Could not determine local time. Video will be uploaded"
                    )
                    return False
                local_video_datetime = video_start_time + local_timezone_offset
                if local_video_datetime.time() < datetime.time(
                        sunrise_time, 0,
                        0) or local_video_datetime.time() > datetime.time(
                            sunset_time, 0, 0):
                    if os.path.basename(os.path.dirname(video)) != 'nighttime':
                        night_time_folder = os.path.dirname(
                            video) + '/nighttime/'
                    if not os.path.exists(night_time_folder):
                        os.mkdir(night_time_folder)
                    os.rename(video,
                              night_time_folder + os.path.basename(video))
                    os.rename(
                        gpx_file_path,
                        night_time_folder + os.path.basename(gpx_file_path))
                    print_error(
                        "Skipping file {} due to video being recorded at night (Before 9am or after 6pm)"
                        .format(video))
                    return True
            except Exception as e:
                print(
                    "Unable to determine time of day. Exception raised: {} \n Video will be uploaded"
                    .format(e))
        return False
예제 #2
0
def filter_video_before_upload(video, filter_night_time=False):
    try:
        if not get_blackvue_info(video)['is_Blackvue_video']:
            print("ERROR: Direct video upload is currently only supported for Blackvue DRS900S camera. Please use video_process command for other camera files")
            return True
        if get_blackvue_info(video)['camera_direction'] != 'Front':
            print("ERROR: Currently, only front Blackvue videos are supported on this command. Please use video_process command for backwards camera videos")
            return True
    except:
        print("ERROR: Unable to determine video details, skipping video")
        return True
    [gpx_file_path, isStationaryVid] = gpx_from_blackvue(
        video, use_nmea_stream_timestamp=False)
    video_start_time = get_video_start_time_blackvue(video)

    if isStationaryVid:
        if not gpx_file_path:
            if os.path.basename(os.path.dirname(video)) != 'no_gps_data':
                no_gps_folder = os.path.dirname(video) + '/no_gps_data/'
                if not os.path.exists(no_gps_folder):
                    os.mkdir(no_gps_folder)
                os.rename(video, no_gps_folder + os.path.basename(video))
            print(
                "Skipping file {} due to file not containing gps data".format(video))
            return True
        if os.path.basename(os.path.dirname(video)) != 'stationary':
            stationary_folder = os.path.dirname(video) + '/stationary/'
            if not os.path.exists(stationary_folder):
                os.mkdir(stationary_folder)
            os.rename(video, stationary_folder + os.path.basename(video))
            os.rename(gpx_file_path, stationary_folder +
                      os.path.basename(gpx_file_path))
        print("Skipping file {} due to camera being stationary".format(video))
        return True

    if not isStationaryVid:
        gpx_points = get_points_from_bv(video)
        gps_video_start_time = gpx_points[0][0]
        if filter_night_time == True:
            # Unsupported feature: Check if video was taken at night
            # TODO: Calculate sun incidence angle and decide based on threshold
            # angle
            sunrise_time = 9
            sunset_time = 18
            try:
                timeZoneName, local_timezone_offset = get_timezone_and_utc_offset(
                    gpx_points[0][1], gpx_points[0][2])
                if timeZoneName is None:
                    print("Could not determine local time. Video will be uploaded")
                    return False
                local_video_datetime = video_start_time + local_timezone_offset
                if local_video_datetime.time() < datetime.time(sunrise_time, 0, 0) or local_video_datetime.time() > datetime.time(sunset_time, 0, 0):
                    if os.path.basename(os.path.dirname(video)) != 'nighttime':
                        night_time_folder = os.path.dirname(
                            video) + '/nighttime/'
                    if not os.path.exists(night_time_folder):
                        os.mkdir(night_time_folder)
                    os.rename(video, night_time_folder +
                              os.path.basename(video))
                    os.rename(gpx_file_path, night_time_folder +
                              os.path.basename(gpx_file_path))
                    print(
                        "Skipping file {} due to video being recorded at night (Before 9am or after 6pm)".format(video))
                    return True
            except Exception as e:
                print(
                    "Unable to determine time of day. Exception raised: {} \n Video will be uploaded".format(e))
        return False