Files
cvmmap-streamer/scripts/replay_mcap.sh
T

69 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_DIR="${BUILD_DIR:-$ROOT_DIR/build}"
REPLAY_BIN="${REPLAY_BIN:-$BUILD_DIR/mcap_replay_tester}"
FFPLAY_BIN="${FFPLAY_BIN:-ffplay}"
FFPLAY_ARGS="${FFPLAY_ARGS:-}"
usage() {
cat <<'EOF'
Usage:
replay_mcap.sh <input.mcap> [h264|h265]
This replays MCAP video using the recorded timestamps and pipes frames to ffplay.
The optional codec argument defaults to h264. Extra ffplay flags may be supplied
via FFPLAY_ARGS, for example: FFPLAY_ARGS='-window_title replay'.
EOF
}
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
usage
exit 0
fi
if [[ $# -lt 1 || $# -gt 2 ]]; then
usage >&2
exit 1
fi
INPUT_PATH="$1"
FORMAT="${2:-h264}"
if [[ "$FORMAT" != "h264" && "$FORMAT" != "h265" ]]; then
echo "unsupported format: $FORMAT (expected h264 or h265)" >&2
exit 1
fi
if [[ ! -f "$INPUT_PATH" ]]; then
echo "input MCAP not found: $INPUT_PATH" >&2
exit 1
fi
if [[ ! -x "$REPLAY_BIN" ]]; then
echo "replay binary not found: $REPLAY_BIN" >&2
exit 1
fi
if ! command -v "$FFPLAY_BIN" >/dev/null 2>&1; then
echo "ffplay not found: $FFPLAY_BIN" >&2
exit 1
fi
extra_args=()
if [[ -n "$FFPLAY_ARGS" ]]; then
# shellcheck disable=SC2206
extra_args=($FFPLAY_ARGS)
fi
cmd=(
"$REPLAY_BIN"
"$INPUT_PATH"
--expect-format "$FORMAT"
--ffplay-path "$FFPLAY_BIN"
)
for arg in "${extra_args[@]}"; do
cmd+=(--ffplay-arg "$arg")
done
"${cmd[@]}"