A simple tool to reduce the size of MCAP files by reducing the frequency of high-frequency topics.
The reducer analyzes all topics in your MCAP file and reduces by half the messages from topics that have a frequency higher than the configured threshold (default: 50 Hz). Topics with frequency equal to or below the threshold are kept unchanged.
- Node.js
- npm
- Clone this repository:
git clone https://github.com/aneuwald-ctw/mcap-reducer.git
cd reduce-mcaps- Install dependencies:
npm installnpm run reduce /path/to/your/file.mcapnpm run reduce /path/to/file1.mcap /path/to/file2.mcap /path/to/file3.mcapnpm run reduce /path/to/mcaps/*.mcapNote: The shell will expand *.mcap to match all .mcap files in the directory
If needed you can control the maximum frequency of messages written to the reduced file using the --messageFrequency= flag. Provide the desired frequency (in Hz) as the value:
npm run reduce -- --messageFrequency=30 /path/to/your/file.mcapNote: The resulting frequency may not match the exact number provided, since it depends on the original message rates and how evenly messages are spaced
The reduced files will be created in the same directory as each input file with the suffix _reduced.mcap. If a file with the same name already exists, it will create numbered versions like _reduced (2).mcap, _reduced (3).mcap, etc.
For example:
- Input:
/home/user/data/recording.mcap - Output:
/home/user/data/recording_reduced.mcap - If exists:
/home/user/data/recording_reduced (2).mcap
You can adjust the frequency threshold by modifying the maxFrequency variable in reduce.ts:
const maxFrequency = 50; // Change this value as needed- Topics with frequency ≤
maxFrequencyHz: kept unchanged - Topics with frequency >
maxFrequencyHz: reduced by half