#!/usr/bin/env bash # ffprobe → normalized source profile (draft SPEC-1 preview). set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # shellcheck disable=SC1091 source "${ROOT}/lib/common.sh" # shellcheck disable=SC1091 source "${ROOT}/lib/source.sh" resolve_source "${1:-}" require_cmd "${FFPROBE_BIN}" probe_target="${SOURCE_URL}" if [[ "${USE_YTDLP}" == "1" ]]; then warn "page URL — ffprobe may fail; use a direct m3u8/mp4 URL or run encode-once" fi log "probing ${probe_target}" "${FFPROBE_BIN}" -hide_banner -loglevel error \ -show_format -show_streams -print_format json \ "${probe_target}" | python3 -c ' import json, sys data = json.load(sys.stdin) fmt = data.get("format", {}) streams = data.get("streams", []) v = next((s for s in streams if s.get("codec_type") == "video"), None) a = next((s for s in streams if s.get("codec_type") == "audio"), None) out = { "duration": fmt.get("duration"), "bitrate": fmt.get("bit_rate"), "format": fmt.get("format_name"), "video": None, "audio": None, } if v: out["video"] = { "codec": v.get("codec_name"), "width": v.get("width"), "height": v.get("height"), "fps": v.get("avg_frame_rate"), "profile": v.get("profile"), } if a: out["audio"] = { "codec": a.get("codec_name"), "channels": a.get("channels"), "sample_rate": a.get("sample_rate"), } print(json.dumps(out, indent=2)) '