This is how the RM reads the tmcpr files: https://github.com/ReplayMod/ReplayStudio/blob/master/src/main/java/com/replaymod/replaystudio/io/ReplayInputStream.java
It's probably far more complicated than necessary for what you want to do (cause it also does stuff like backwards compatibility with older RM versions and converting replays between Minecraft versions via ViaVersion).
This post probably has all you really need to know.