def count_frames(nusc, sample):
    """Counts frames to use for progress bar
    Args:
        nusc: NuScenes api object
        sample: nuScenes frame, this should be the first frame
    Returns:
        frame_count: number of frames
        """
    frame_count = 0

    # This prevents our function from modifying the sample
    if sample['next'] != '':
        frame_count += 1

        # Don't want to change where sample['next'] points to since it's used later, so we'll create our own pointer
        sample_counter = nusc.get('sample', sample['next'])

        while sample_counter['next'] != '':
            frame_count += 1
            sample_counter = nusc.get('sample', sample_counter['next'])

    return frame_count