pymcap-cli 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. pymcap_cli-0.1.0/PKG-INFO +491 -0
  2. pymcap_cli-0.1.0/README.md +453 -0
  3. pymcap_cli-0.1.0/pyproject.toml +58 -0
  4. pymcap_cli-0.1.0/src/pymcap_cli/__init__.py +0 -0
  5. pymcap_cli-0.1.0/src/pymcap_cli/cli.py +99 -0
  6. pymcap_cli-0.1.0/src/pymcap_cli/cmd/__init__.py +0 -0
  7. pymcap_cli-0.1.0/src/pymcap_cli/cmd/cat_cmd.py +315 -0
  8. pymcap_cli-0.1.0/src/pymcap_cli/cmd/compress_cmd.py +91 -0
  9. pymcap_cli-0.1.0/src/pymcap_cli/cmd/convert_cmd.py +581 -0
  10. pymcap_cli-0.1.0/src/pymcap_cli/cmd/du_cmd.py +63 -0
  11. pymcap_cli-0.1.0/src/pymcap_cli/cmd/filter_cmd.py +210 -0
  12. pymcap_cli-0.1.0/src/pymcap_cli/cmd/info_cmd.py +377 -0
  13. pymcap_cli-0.1.0/src/pymcap_cli/cmd/info_json_cmd.py +654 -0
  14. pymcap_cli-0.1.0/src/pymcap_cli/cmd/list_cmd.py +272 -0
  15. pymcap_cli-0.1.0/src/pymcap_cli/cmd/merge_cmd.py +137 -0
  16. pymcap_cli-0.1.0/src/pymcap_cli/cmd/process_cmd.py +252 -0
  17. pymcap_cli-0.1.0/src/pymcap_cli/cmd/rechunk_cmd.py +179 -0
  18. pymcap_cli-0.1.0/src/pymcap_cli/cmd/recover_cmd.py +114 -0
  19. pymcap_cli-0.1.0/src/pymcap_cli/cmd/recover_inplace_cmd.py +172 -0
  20. pymcap_cli-0.1.0/src/pymcap_cli/cmd/roscompress_cmd.py +556 -0
  21. pymcap_cli-0.1.0/src/pymcap_cli/cmd/tftree_cmd.py +326 -0
  22. pymcap_cli-0.1.0/src/pymcap_cli/cmd/video_cmd.py +682 -0
  23. pymcap_cli-0.1.0/src/pymcap_cli/debug_wrapper.py +76 -0
  24. pymcap_cli-0.1.0/src/pymcap_cli/display_utils.py +579 -0
  25. pymcap_cli-0.1.0/src/pymcap_cli/http_utils.py +229 -0
  26. pymcap_cli-0.1.0/src/pymcap_cli/info_types.py +444 -0
  27. pymcap_cli-0.1.0/src/pymcap_cli/input_handler.py +66 -0
  28. pymcap_cli-0.1.0/src/pymcap_cli/mcap_processor.py +875 -0
  29. pymcap_cli-0.1.0/src/pymcap_cli/msg_resolver.py +284 -0
  30. pymcap_cli-0.1.0/src/pymcap_cli/osc_utils.py +240 -0
  31. pymcap_cli-0.1.0/src/pymcap_cli/processors.py +152 -0
  32. pymcap_cli-0.1.0/src/pymcap_cli/py.typed +0 -0
  33. pymcap_cli-0.1.0/src/pymcap_cli/types_manual.py +71 -0
  34. pymcap_cli-0.1.0/src/pymcap_cli/utils.py +342 -0
@@ -0,0 +1,491 @@
1
+ Metadata-Version: 2.3
2
+ Name: pymcap-cli
3
+ Version: 0.1.0
4
+ Summary: High-performance Python CLI for MCAP file processing with advanced recovery, filtering, and optimization capabilities
5
+ Keywords: mcap,cli,robotics,ros,ros2,recovery,filtering,compression
6
+ Author: Marko Bausch
7
+ License: GPL-3.0
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: System :: Archiving
21
+ Classifier: Topic :: Utilities
22
+ Classifier: Typing :: Typed
23
+ Requires-Dist: rich>=14.1.0
24
+ Requires-Dist: small-mcap[compression]
25
+ Requires-Dist: mcap-ros2-support-fast
26
+ Requires-Dist: cyclopts>=4
27
+ Requires-Dist: ros-parser
28
+ Requires-Dist: platformdirs>=4.0.0
29
+ Requires-Dist: typing-extensions>=4.15.0
30
+ Requires-Dist: av>=12.0.0 ; extra == 'video'
31
+ Requires-Dist: numpy>=1.24.0 ; extra == 'video'
32
+ Requires-Python: >=3.10
33
+ Project-URL: Homepage, https://github.com/mrkbac/robotic-tools
34
+ Project-URL: Issues, https://github.com/mrkbac/robotic-tools/issues
35
+ Project-URL: Repository, https://github.com/mrkbac/robotic-tools
36
+ Provides-Extra: video
37
+ Description-Content-Type: text/markdown
38
+
39
+ # pymcap-cli
40
+
41
+ A high-performance Python CLI for MCAP file processing with advanced recovery, filtering, and optimization capabilities.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ # Run directly without installing
47
+ uvx pymcap-cli info data.mcap
48
+
49
+ # Or add to your project
50
+ uv add pymcap-cli
51
+
52
+ # With video support (for video and roscompress commands)
53
+ uv add pymcap-cli[video]
54
+ ```
55
+
56
+ ## Why pymcap-cli over the official Go CLI?
57
+
58
+ - **Advanced Recovery**: Handles corrupt MCAP files with intelligent chunk-level recovery and MessageIndex validation
59
+ - **Smart Chunk Copying**: Fast chunk copying without decompression when possible - up to 10x faster for filtering operations
60
+ - **Unified Processing**: Single `process` command combines recovery + filtering + compression in one optimized pass
61
+ - **Precise Filtering**: Regex topic filtering, time range filtering, and content type filtering with deferred schema/channel writing
62
+ - **Rich Progress Display**: Beautiful progress bars with transfer speeds and time estimates using Rich console output
63
+ - **Robust Error Handling**: Graceful degradation with detailed error reporting and recovery statistics
64
+
65
+ ## Quick Start
66
+
67
+ ```bash
68
+ # Get file information
69
+ pymcap-cli info data.mcap
70
+
71
+ # Recover a corrupt MCAP file
72
+ pymcap-cli recover corrupted.mcap -o fixed.mcap
73
+
74
+ # Filter messages by topic with compression
75
+ pymcap-cli process large.mcap -o filtered.mcap -y "/camera.*" --compression zstd
76
+
77
+ # Rechunk by topic patterns
78
+ pymcap-cli rechunk data.mcap -o rechunked.mcap -p "/camera.*" -p "/lidar.*"
79
+
80
+ # Show disk usage breakdown
81
+ pymcap-cli du large.mcap
82
+
83
+ # Compress files
84
+ pymcap-cli compress input.mcap -o compressed.mcap --compression lz4
85
+ ```
86
+
87
+ ## Available Commands
88
+
89
+ ### `info` - File Information
90
+
91
+ Display detailed MCAP file information including schemas, channels, message counts, and time ranges.
92
+
93
+ ```bash
94
+ # Single file
95
+ pymcap-cli info data.mcap
96
+
97
+ # Multiple files (displays each file separately)
98
+ pymcap-cli info file1.mcap file2.mcap file3.mcap
99
+
100
+ # JSON output for single file
101
+ pymcap-cli info-json data.mcap
102
+
103
+ # JSON output for multiple files (returns array)
104
+ pymcap-cli info-json file1.mcap file2.mcap
105
+ ```
106
+
107
+ ### `cat` - Stream Messages
108
+
109
+ Stream MCAP messages to stdout. Outputs as Rich tables when interactive, JSONL when piped.
110
+
111
+ ```bash
112
+ # Display messages in a table (interactive)
113
+ pymcap-cli cat recording.mcap
114
+
115
+ # Pipe to file as JSONL
116
+ pymcap-cli cat recording.mcap > messages.jsonl
117
+
118
+ # Filter specific topics
119
+ pymcap-cli cat recording.mcap --topics /camera/image
120
+
121
+ # Filter by time range
122
+ pymcap-cli cat recording.mcap --start-secs 10 --end-secs 20
123
+
124
+ # Limit output
125
+ pymcap-cli cat recording.mcap --limit 100
126
+
127
+ # Query specific field using message path
128
+ pymcap-cli cat recording.mcap --query '/odom.pose.position.x'
129
+
130
+ # Filter array elements
131
+ pymcap-cli cat recording.mcap --query '/detections.objects[:]{confidence>0.8}'
132
+ ```
133
+
134
+ ### `recover` - Advanced Recovery
135
+
136
+ Recover data from potentially corrupt MCAP files with intelligent error handling.
137
+
138
+ ```bash
139
+ # Basic recovery
140
+ pymcap-cli recover corrupt.mcap -o fixed.mcap
141
+
142
+ # Force chunk decoding for maximum recovery
143
+ pymcap-cli recover corrupt.mcap -o fixed.mcap --always-decode-chunk
144
+ ```
145
+
146
+ ### `recover-inplace` - In-Place Recovery
147
+
148
+ Rebuild an MCAP file's summary and footer in place without creating a new file.
149
+
150
+ ```bash
151
+ # Rebuild summary/footer in place
152
+ pymcap-cli recover-inplace data.mcap
153
+
154
+ # With exact size calculation
155
+ pymcap-cli recover-inplace data.mcap --exact-sizes
156
+
157
+ # Skip confirmation prompt
158
+ pymcap-cli recover-inplace data.mcap --force
159
+ ```
160
+
161
+ ### `process` - Unified Processing
162
+
163
+ The most powerful command - combines recovery, filtering, and optimization in a single pass.
164
+
165
+ ```bash
166
+ # Filter by topic regex
167
+ pymcap-cli process data.mcap -o filtered.mcap -y "/camera.*" -y "/lidar.*"
168
+
169
+ # Time range filtering (nanoseconds or RFC3339)
170
+ pymcap-cli process data.mcap -o subset.mcap -S 1640995200000000000 -E 1640995260000000000
171
+ pymcap-cli process data.mcap -o subset.mcap -S "2022-01-01T00:00:00Z" -E "2022-01-01T01:00:00Z"
172
+
173
+ # Exclude topics and metadata
174
+ pymcap-cli process data.mcap -o clean.mcap -n "/debug.*" --exclude-metadata
175
+
176
+ # Change compression with filtering
177
+ pymcap-cli process zstd.mcap -o lz4.mcap --compression lz4 -y "/important.*"
178
+
179
+ # Recovery mode with filtering (handles corrupt files)
180
+ pymcap-cli process corrupt.mcap -o recovered.mcap -y "/camera.*" --recovery-mode
181
+ ```
182
+
183
+ ### `merge` - Merge Files
184
+
185
+ Merge multiple MCAP files chronologically into a single output file.
186
+
187
+ ```bash
188
+ # Merge two files
189
+ pymcap-cli merge recording1.mcap recording2.mcap -o combined.mcap
190
+
191
+ # Merge with compression
192
+ pymcap-cli merge *.mcap -o all_recordings.mcap --compression lz4
193
+
194
+ # Exclude metadata/attachments
195
+ pymcap-cli merge file1.mcap file2.mcap -o merged.mcap --metadata exclude
196
+ ```
197
+
198
+ ### `convert` - Convert DB3 to MCAP
199
+
200
+ Convert ROS2 DB3 (SQLite) bag files to MCAP format.
201
+
202
+ ```bash
203
+ # Basic conversion
204
+ pymcap-cli convert input.db3 -o output.mcap
205
+
206
+ # Specify ROS distro
207
+ pymcap-cli convert input.db3 -o output.mcap --distro jazzy
208
+
209
+ # With custom message definitions
210
+ pymcap-cli convert input.db3 -o output.mcap --extra-path /path/to/msgs
211
+
212
+ # Multiple custom paths
213
+ pymcap-cli convert input.db3 -o output.mcap \
214
+ --extra-path /path/to/msgs1 \
215
+ --extra-path /path/to/msgs2
216
+ ```
217
+
218
+ ### `rechunk` - Topic-Based Rechunking
219
+
220
+ Reorganize MCAP messages into separate chunk groups based on topic patterns. This is useful for optimizing file layout when different topics are accessed independently, improving playback performance for topic-specific queries.
221
+
222
+ ```bash
223
+ # Group camera and lidar topics into separate chunks
224
+ pymcap-cli rechunk data.mcap -o rechunked.mcap -p "/camera.*" -p "/lidar.*"
225
+
226
+ # Multiple patterns - each gets its own chunk group
227
+ pymcap-cli rechunk data.mcap -o rechunked.mcap \
228
+ -p "/camera/front.*" \
229
+ -p "/camera/rear.*" \
230
+ -p "/lidar.*" \
231
+ -p "/radar.*"
232
+
233
+ # With custom chunk size and compression
234
+ pymcap-cli rechunk data.mcap -o rechunked.mcap \
235
+ -p "/high_freq.*" \
236
+ --chunk-size 8388608 \
237
+ --compression lz4
238
+ ```
239
+
240
+ **How it works:**
241
+ - Messages are grouped by the first matching pattern (first match wins)
242
+ - Each pattern gets its own chunk group that can span multiple chunks
243
+ - Topics not matching any pattern go into a separate "unmatched" group
244
+ - Messages within each group preserve their original order
245
+ - Useful for optimizing access patterns when different topics are read independently
246
+
247
+ ### `filter` - Topic Filtering
248
+
249
+ Filter messages by topic patterns (simpler version of `process`).
250
+
251
+ ```bash
252
+ # Include specific topics
253
+ pymcap-cli filter data.mcap -o filtered.mcap --include-topics "/camera/image" "/lidar/points"
254
+
255
+ # Exclude topics
256
+ pymcap-cli filter data.mcap -o filtered.mcap --exclude-topics "/debug.*" "/test.*"
257
+ ```
258
+
259
+ ### `compress` - Compression Tool
260
+
261
+ Change MCAP file compression.
262
+
263
+ ```bash
264
+ # Compress with different algorithms
265
+ pymcap-cli compress input.mcap -o output.mcap --compression zstd
266
+ pymcap-cli compress input.mcap -o output.mcap --compression lz4
267
+ ```
268
+
269
+ ### `du` - Disk Usage Analysis
270
+
271
+ Analyze MCAP file size breakdown by chunks, schemas, channels, and message counts.
272
+
273
+ ```bash
274
+ pymcap-cli du large.mcap
275
+ ```
276
+
277
+ ### `list` - List Records
278
+
279
+ List various record types in an MCAP file with detailed information.
280
+
281
+ ```bash
282
+ # List channels
283
+ pymcap-cli list channels data.mcap
284
+
285
+ # List chunks
286
+ pymcap-cli list chunks data.mcap
287
+
288
+ # List schemas
289
+ pymcap-cli list schemas data.mcap
290
+
291
+ # List attachments
292
+ pymcap-cli list attachments data.mcap
293
+
294
+ # List metadata
295
+ pymcap-cli list metadata data.mcap
296
+ ```
297
+
298
+ ### `info-json` - JSON Statistics
299
+
300
+ Output comprehensive MCAP file statistics as JSON, including message distribution, channel rates, and compression stats.
301
+
302
+ ```bash
303
+ # Basic JSON output
304
+ pymcap-cli info-json data.mcap
305
+
306
+ # Rebuild from scratch with exact sizes
307
+ pymcap-cli info-json data.mcap --rebuild --exact-sizes
308
+ ```
309
+
310
+ ### `tftree` - TF Transform Tree
311
+
312
+ Display ROS TF transform tree from MCAP files with visual hierarchy.
313
+
314
+ ```bash
315
+ # Show complete TF tree (both /tf and /tf_static)
316
+ pymcap-cli tftree data.mcap
317
+
318
+ # Show only static transforms
319
+ pymcap-cli tftree data.mcap --static-only
320
+ ```
321
+
322
+ ### `video` - Video Generation
323
+
324
+ Generate MP4 videos from image topics (CompressedImage or Image) using hardware-accelerated encoding. Requires the `video` extra.
325
+
326
+ ```bash
327
+ # Basic video generation
328
+ pymcap-cli video data.mcap --topic /camera/front --output front.mp4
329
+
330
+ # With quality preset
331
+ pymcap-cli video data.mcap --topic /camera/rear --output rear.mp4 --quality high
332
+
333
+ # Use specific codec and encoder
334
+ pymcap-cli video data.mcap --topic /lidar/image --output lidar.mp4 --codec h265 --encoder videotoolbox
335
+
336
+ # Manual CRF quality control
337
+ pymcap-cli video data.mcap --topic /camera/debug --output debug.mp4 --crf 18
338
+ ```
339
+
340
+ ### `roscompress` - ROS Image Compression
341
+
342
+ Compress ROS MCAP files by converting CompressedImage/Image topics to CompressedVideo format. Requires the `video` extra.
343
+
344
+ ```bash
345
+ # Basic compression
346
+ pymcap-cli roscompress data.mcap -o compressed.mcap
347
+
348
+ # Specify quality (CRF: lower = better, 0-51)
349
+ pymcap-cli roscompress data.mcap -o compressed.mcap --quality 28
350
+
351
+ # Specify codec
352
+ pymcap-cli roscompress data.mcap -o compressed.mcap --codec h265
353
+
354
+ # Force specific encoder
355
+ pymcap-cli roscompress data.mcap -o compressed.mcap --encoder libx264
356
+ ```
357
+
358
+ ### Shell Autocompletion
359
+
360
+ pymcap-cli supports automatic shell completion for bash, zsh, fish, and PowerShell using Typer's built-in completion system.
361
+
362
+ #### Quick Install (recommended)
363
+ ```bash
364
+ # Automatically install completion for your current shell
365
+ pymcap-cli --install-completion
366
+
367
+ # That's it! Restart your shell or source your config file
368
+ ```
369
+
370
+ #### Manual Install
371
+ ```bash
372
+ # Bash - add to ~/.bashrc
373
+ eval "$(pymcap-cli --show-completion bash)"
374
+
375
+ # Zsh - add to ~/.zshrc
376
+ eval "$(pymcap-cli --show-completion zsh)"
377
+
378
+ # Fish - add to ~/.config/fish/config.fish
379
+ pymcap-cli --show-completion fish | source
380
+
381
+ # PowerShell - add to your profile
382
+ Invoke-Expression (& pymcap-cli --show-completion powershell)
383
+ ```
384
+
385
+ ## Advanced Usage
386
+
387
+ ### Performance Optimization
388
+
389
+ ```bash
390
+ # Fast chunk copying (default) - up to 10x faster for large files
391
+ pymcap-cli process data.mcap -o filtered.mcap -y "/camera.*" --chunk-copying
392
+
393
+ # Disable chunk copying for maximum compatibility
394
+ pymcap-cli process data.mcap -o filtered.mcap -y "/camera.*" --no-chunk-copying
395
+
396
+ # Always decode chunks (slower but handles edge cases)
397
+ pymcap-cli process data.mcap -o filtered.mcap -y "/camera.*" --always-decode-chunk
398
+ ```
399
+
400
+ ### Recovery Modes
401
+
402
+ ```bash
403
+ # Graceful error handling (default)
404
+ pymcap-cli process corrupt.mcap -o recovered.mcap --recovery-mode
405
+
406
+ # Strict mode - fail on any errors
407
+ pymcap-cli process data.mcap -o output.mcap --no-recovery
408
+ ```
409
+
410
+ ### Time Filtering Options
411
+
412
+ ```bash
413
+ # Using seconds (automatically converted to nanoseconds)
414
+ pymcap-cli process data.mcap -o subset.mcap --start-secs 1640995200 --end-secs 1640995260
415
+
416
+ # Using nanoseconds directly
417
+ pymcap-cli process data.mcap -o subset.mcap --start-nsecs 1640995200000000000
418
+
419
+ # Using RFC3339 timestamps (most readable)
420
+ pymcap-cli process data.mcap -o subset.mcap -S "2022-01-01T00:00:00Z" -E "2022-01-01T01:00:00Z"
421
+ ```
422
+
423
+ ## Common Use Cases
424
+
425
+ ### Clean Up Debug Data
426
+
427
+ ```bash
428
+ # Remove debug topics and metadata to reduce file size
429
+ pymcap-cli process raw_data.mcap -o clean_data.mcap \
430
+ -n "/debug.*" -n "/test.*" --exclude-metadata --compression zstd
431
+ ```
432
+
433
+ ### Extract Camera Data
434
+
435
+ ```bash
436
+ # Extract only camera topics with time filtering
437
+ pymcap-cli process full_log.mcap -o camera_only.mcap \
438
+ -y "/camera.*" -S "2024-01-01T10:00:00Z" -E "2024-01-01T11:00:00Z"
439
+ ```
440
+
441
+ ### Recover and Compress
442
+
443
+ ```bash
444
+ # Recover corrupt file and compress in one pass
445
+ pymcap-cli process corrupt.mcap -o recovered.mcap \
446
+ --recovery-mode --compression lz4
447
+ ```
448
+
449
+ ### High-Performance Filtering
450
+
451
+ ```bash
452
+ # Fast filtering with chunk copying for maximum performance
453
+ pymcap-cli process 100gb_file.mcap -o filtered.mcap \
454
+ -y "/lidar.*" --chunk-copying --compression zstd
455
+ ```
456
+
457
+ ### Optimize for Topic-Specific Playback
458
+
459
+ ```bash
460
+ # Rechunk by sensor type for faster topic-specific access
461
+ pymcap-cli rechunk robot_log.mcap -o optimized.mcap \
462
+ -p "/camera.*" \
463
+ -p "/lidar.*" \
464
+ -p "/imu.*" \
465
+ -p "/gps.*"
466
+ ```
467
+
468
+ ## Technical Details
469
+
470
+ - **Smart Chunk Processing**: Automatically chooses between fast chunk copying and individual record processing based on filter criteria
471
+ - **MessageIndex Validation**: Validates and rebuilds MessageIndexes when necessary for data integrity
472
+ - **Deferred Schema Writing**: Only writes schemas and channels that are actually used by included messages
473
+ - **Compression Support**: zstd, lz4, and uncompressed formats with configurable chunk sizes
474
+ - **Memory Efficient**: Streams processing with configurable buffer sizes for handling large files
475
+ - **Error Recovery**: Multiple fallback strategies for handling corrupt or incomplete MCAP files
476
+
477
+ ## Development
478
+
479
+ ```bash
480
+ # Setup development environment
481
+ uv sync
482
+
483
+ # Run locally during development
484
+ uv run pymcap-cli --help
485
+
486
+ # Format and lint code
487
+ uv run pre-commit run --all-files
488
+
489
+ # Run tests
490
+ uv run pytest pymcap-cli/tests
491
+ ```