def test_run_command_smokescreen() -> None: """ Do not check output, just verify import works and does not crash. """ cmd = "echo 5678" run_command(cmd)
def visualize_ground_lidar_pts(log_id: str, dataset_dir: str, experiment_prefix: str): """Process a log by drawing the LiDAR returns that are classified as belonging to the ground surface in a red to green colormap in the image. Args: log_id: The ID of a log dataset_dir: Where the dataset is stored experiment_prefix: Output prefix """ sdb = SynchronizationDB(dataset_dir, collect_single_log_id=log_id) city_info_fpath = f"{dataset_dir}/{log_id}/city_info.json" city_info = read_json_file(city_info_fpath) city_name = city_info["city_name"] avm = ArgoverseMap() ply_fpaths = sorted(glob.glob(f"{dataset_dir}/{log_id}/lidar/PC_*.ply")) for i, ply_fpath in enumerate(ply_fpaths): if i % 500 == 0: print(f"\tOn file {i} of {log_id}") lidar_timestamp_ns = ply_fpath.split("/")[-1].split(".")[0].split( "_")[-1] pose_fpath = f"{dataset_dir}/{log_id}/poses/city_SE3_egovehicle_{lidar_timestamp_ns}.json" if not Path(pose_fpath).exists(): continue pose_data = read_json_file(pose_fpath) rotation = np.array(pose_data["rotation"]) translation = np.array(pose_data["translation"]) city_to_egovehicle_se3 = SE3(rotation=quat2rotmat(rotation), translation=translation) lidar_pts = load_ply(ply_fpath) lidar_timestamp_ns = int(lidar_timestamp_ns) draw_ground_pts_in_image( sdb, lidar_pts, city_to_egovehicle_se3, avm, log_id, lidar_timestamp_ns, city_name, dataset_dir, experiment_prefix, ) for camera_name in CAMERA_LIST: if "stereo" in camera_name: fps = 5 else: fps = 10 cmd = f"ffmpeg -r {fps} -f image2 -i '{experiment_prefix}_ground_viz/{log_id}/{camera_name}/%*.jpg' {experiment_prefix}_ground_viz/{experiment_prefix}_{log_id}_{camera_name}_{fps}fps.mp4" print(cmd) run_command(cmd)
def ffmpeg_compress_video(uncompressed_mp4_path: str, fps: int) -> None: """Generate compressed version of video, and delete uncompressed version. Args: img_wildcard: path to video to compress """ codec_params_string = get_ffmpeg_codec_params_string() fname_stem = Path(uncompressed_mp4_path).stem compressed_mp4_path = f"{Path(uncompressed_mp4_path).parent}/{fname_stem}_compressed.mp4" cmd = f"ffmpeg -r {fps} -i {uncompressed_mp4_path} {codec_params_string} {compressed_mp4_path}" print(cmd) run_command(cmd) os.remove(uncompressed_mp4_path)
def write_nonsequential_idx_video(img_wildcard: str, output_fpath: str, fps: int) -> None: """ Args: img_wildcard: string output_fpath: string fps: integer, frames per second """ codec_params_string = get_ffmpeg_codec_params_string() cmd = f"ffmpeg -r {fps} -f image2 -i {img_wildcard} {codec_params_string} {output_fpath}" print(cmd) run_command(cmd)
def write_video(image_prefix: str, output_prefix: str, fps: int = 10) -> None: """ Use FFMPEG to write a video to disk, from a sequence of images. Args: image_prefix: string, with %d embedded inside and ending with a prefix, e.g. .png/.jpg. Absolute path output_prefix: absolute path for output video, without .mp4 prefix fps: integer, frames per second """ codec_params_string = get_ffmpeg_codec_params_string() cmd = f"ffmpeg -r {fps} -i {image_prefix} {codec_params_string} {output_prefix}_{fps}fps.mp4" print(cmd) run_command(cmd)
def test_run_command_cat() -> None: """ Execute a command to dump a string to standard output. Returned output will be in byte format with a carriage return. """ cmd = "echo 5678" stdout_data, stderr_data = run_command(cmd, return_output=True) assert stderr_data is None assert stdout_data == "5678\n".encode()
def write_nonsequential_idx_video(img_wildcard: str, output_fpath: str, fps: int) -> None: """ Args: img_wildcard: string output_fpath: string fps: integer, frames per second Returns: None """ cmd = f"ffmpeg -r {fps} -f image2 -i {img_wildcard}" cmd += " -vcodec libx264 -profile:v main" cmd += " -level 3.1 -preset medium -crf 23 -x264-params ref=4 -acodec" cmd += " copy -movflags +faststart -pix_fmt yuv420p -vf scale=920:-2" cmd += f" {output_fpath}" print(cmd) run_command(cmd)
def write_video(image_prefix: str, output_prefix: str, fps: int = 10) -> None: """ Use FFMPEG to write a video to disk, from a sequence of images. Args: image_prefix: string, with %d embedded inside and ending with a prefix, e.g. .png/.jpg. Absolute path output_prefix: absolute path for output video, without .mp4 prefix fps: integer, frames per second Returns: None """ cmd = f"ffmpeg -r {fps} -i {image_prefix} -vcodec libx264 -profile:v main" cmd += " -level 3.1 -preset medium -crf 23 -x264-params ref=4 -acodec" cmd += f" copy -movflags +faststart -pix_fmt yuv420p -vf scale=920:-2 {output_prefix}_{fps}fps.mp4" print(cmd) run_command(cmd)