reprostim.bids.properties¶
Extraction of BIDS media-file properties (sidecar-JSON-key-keyed values) from ffprobe results, split-video results, and in future from cached VaRecord (videos.tsv) rows and file paths. The single place bids-inject-sidecar, bids-inject, and split-video produce BIDS sidecar properties from, instead of each reimplementing the AudioInfo/VideoInfo/SplitResult/VaRecord -> BIDS-dict mapping independently.
See .ai/bids/properties-spec.md for the full specification.
Functions
|
Map ffprobe-derived stream info to BIDS media-file properties. |
|
Run |
|
Convert a split-video result to a BEP044/BEP047 BIDS sidecar dict. |
|
Look up a cached |
- reprostim.bids.properties.bids_properties_from_audio_video_info(audio: AudioInfo | None, video: VideoInfo | None, props: Dict[str, Any] | None = None) Dict[str, Any][source]¶
Map ffprobe-derived stream info to BIDS media-file properties.
Fields that cannot be determined (no matching stream, field absent from ffprobe output) are simply omitted from the result rather than written as
"n/a"orNone, matching the BEP044 sidecar convention (see .ai/bids/media-spec.md).- Parameters:
audio (Optional[AudioInfo]) – Audio stream info from
get_audio_video_info_ffprobe, orNoneif the file has no audio stream.video (Optional[VideoInfo]) – Video stream info from
get_audio_video_info_ffprobe, orNoneif the file has no video stream.props (Optional[Dict[str, Any]]) – Optional dict to populate/merge into instead of creating a fresh one — lets a caller accumulate properties from several
bids_properties_from_*calls into one shared dict. Existing keys are overwritten by non-Nonevalues from this call (likedict.update()); when composing multiple sources, priority is controlled by call order, not by this parameter.
- Returns:
props (or a new dict if props was
None), with mappable properties set; only properties that could be determined are present.- Return type:
Dict[str, Any]
- reprostim.bids.properties.bids_properties_from_ffprobe(path: str, props: Dict[str, Any] | None = None) Dict[str, Any][source]¶
Run
ffprobeon path and map the result to BIDS media-file properties.Convenience wrapper combining
get_audio_video_info_ffprobeandbids_properties_from_audio_video_info().- Parameters:
path (str) – Path to the audio/video file.
props (Optional[Dict[str, Any]]) – Optional dict to populate/merge into instead of creating a fresh one; see
bids_properties_from_audio_video_info().
- Returns:
props (or a new dict if props was
None); seebids_properties_from_audio_video_info().- Return type:
Dict[str, Any]
- reprostim.bids.properties.bids_properties_from_split_result(sr, sidecar_metadata: Dict[str, Any] | None = None) Dict[str, Any][source]¶
Convert a split-video result to a BEP044/BEP047 BIDS sidecar dict.
Maps a video-splitting result’s fields to BIDS metadata field names as defined in the common media file definitions (bids-standard/bids-specification PR #2367).
sr is intentionally untyped: annotating it as
reprostim.video.split.SplitResultwould make this module import fromvideo.split— butsplit.pyis the caller of this function, so that import would be circular. sr is expected to expose the same attributes asSplitResult:orig_device,orig_device_serial_number,buffer_duration,video_codec,video_frame_rate,video_width,video_height,audio_codec,audio_sample_rate,audio_bit_depth,audio_channel_count.- Parameters:
sr – Split-result-like object to convert (see note above).
sidecar_metadata (Optional[Dict[str, Any]]) – Optional dict with extra BIDS fields to inject. Supports
TaskName(written as the first field when present),VideoCodecRFC6381,AudioCodecRFC6381,ImageBitDepth,ImagePixelFormat, andVideoFrameCount(seeBidsMediaPropertyfor the field-name constants backing these keys).
- Returns:
Dict with BIDS-compliant metadata field names.
- Return type:
Dict[str, Any]
- reprostim.bids.properties.bids_properties_from_video_audit(path: str, path_tsv: str | None = None, props: Dict[str, Any] | None = None) Dict[str, Any][source]¶
Look up a cached
VaRecordfor path in path_tsv (avideos.tsvproduced byvideo-audit) and map it to BIDS media-file properties.Wraps
get_file_video_audit(path, path_tsv, cached=True, use_lock=False): prefers already-loaded, cached TSV data over reloading from disk, and skips the advisory file lock (dirty read) — appropriate for read-mostly batch tooling (e.g.bids-inject-sidecar) rather than thevideo-auditwriter itself. Falls back to auditing the file directly when path has no matching row in path_tsv, or path_tsv is not given/found — seereprostim.video.audit.get_file_video_audit().Uses the
VaRecord’sduration/video_res_recorded/video_fps_recorded/audio_srfields (derived from the media stream itself via ffprobe/QR parsing), not the*_detectedones (derived from the psychopy display-capture log), since the sidecar should describe the file, not what was displayed. Fields absent or"n/a"in theVaRecordare omitted, matching every otherbids_properties_from_*function in this module.VaRecord/videos.tsvhas noDevice/DeviceSerialNumbercolumns yet, so those two are instead recovered the same wayvideo.splitdoes: by looking for asession_beginREPROSTIM-METADATA-JSON entry in<path>.log(seereprostim.capture.metadata.find_metadata_by_class()) and reading itsvDev/serialfields. Omitted if<path>.logdoesn’t exist, has nosession_beginentry, or that entry lacks the field.VaRecordalso has no codec column, soVideoCodecis set to"h264"whenevervideo_res_recordedis present (not"n/a"), reflecting thatreprostim-videocapturealways encodes with-c:v libx264— matchingSplitResult.video_codec’s inference inbids_properties_from_split_result.- Parameters:
path (str) – Path to the audio/video file.
path_tsv (Optional[str]) – Optional path to
videos.tsv.props (Optional[Dict[str, Any]]) – Optional dict to populate/merge into instead of creating a fresh one; see
bids_properties_from_audio_video_info().
- Returns:
props (or a new dict if props was
None); seebids_properties_from_audio_video_info().- Return type:
Dict[str, Any]