def process_all_videos(video_folder):
    vids = os.listdir(video_folder)
    date = Fn.extract_date_from_beginning(video_folder)
    print date

    for i, vid in enumerate(vids):
        if not vid.endswith("MOV"):
            continue
        print ("Processing video {}".format(vid))
        process_video(os.path.join(video_folder, vid), date)
        if i >= 2:
            return
def process_all_videos(video_folder):
    vids = os.listdir(video_folder)
    date = Fn.extract_date_from_beginning(video_folder)
    print date

    for i, vid in enumerate(vids):
        if not vid.endswith("MOV"):
            continue
        print("Processing video {}".format(vid))
        process_video(os.path.join(video_folder, vid), date)
        if i >= 2:
            return
    df, meta = read_meta_file(fn)
    if len(df)<=1:
        #print("Not a distance related ground truth file, skipping")
        return
    w = get_pitch_width(meta)
    l = get_pitch_length(meta)
    if w is None or l is None:
        print("No width or length information, skipping {}".format(fn))
        return
    diag = math.sqrt(l*l + w*w)
    distances=get_corner_to_dist_mapping(w,l,date)
    dfprev = df.shift(1)
    df["route"] = dfprev.corner + df.corner
    df["dist_from_prev_to_curr"] = df.route.apply(lambda x: get_distance(x,distances))
    df["dist_covered"] = df["dist_from_prev_to_curr"].cumsum()
    df["secs_elapsed"] = df["secs_from_prev_to_curr"].cumsum()
    df2 = df[["secs_elapsed","dist_covered"]]
    ts = pd.Series(df.dist_covered.values, index=df.secs_elapsed)
    ts.to_csv(Fn.change_ext(fn,"dground"))

def process_all_ground_truth(folder,date):
    all_meta_files = Fn.find_files_with_ext(folder,"meta")
    for fn in all_meta_files:
        #print(fn)
        process_file(fn,date)

if __name__ == '__main__':
    folder = sys.argv[1]
    date = Fn.extract_date_from_beginning(folder)
    process_all_ground_truth(folder,date)
        return
    w = get_pitch_width(meta)
    l = get_pitch_length(meta)
    if w is None or l is None:
        print("No width or length information, skipping {}".format(fn))
        return
    diag = math.sqrt(l * l + w * w)
    distances = get_corner_to_dist_mapping(w, l, date)
    dfprev = df.shift(1)
    df["route"] = dfprev.corner + df.corner
    df["dist_from_prev_to_curr"] = df.route.apply(
        lambda x: get_distance(x, distances))
    df["dist_covered"] = df["dist_from_prev_to_curr"].cumsum()
    df["secs_elapsed"] = df["secs_from_prev_to_curr"].cumsum()
    df2 = df[["secs_elapsed", "dist_covered"]]
    ts = pd.Series(df.dist_covered.values, index=df.secs_elapsed)
    ts.to_csv(Fn.change_ext(fn, "dground"))


def process_all_ground_truth(folder, date):
    all_meta_files = Fn.find_files_with_ext(folder, "meta")
    for fn in all_meta_files:
        #print(fn)
        process_file(fn, date)


if __name__ == '__main__':
    folder = sys.argv[1]
    date = Fn.extract_date_from_beginning(folder)
    process_all_ground_truth(folder, date)