I have encountered too many erroneous real media files. For a long time I searched RM fixing tools on the Web, but the fixed results are not always good. Finally, when I found RealMedia File Format Reference, I decided to make such a tool by myself.
Read and Write Real Media Files
The RealMedia File Format is defined in the Format.xml file. It is deserialized into a
Format object, which contain
FieldDefs. Then some generalized methods are used to read and write real media files according to its format definition.
Check and Fix Errors
There are some common errors in a real media file.
Problem: Some Portion of the File Can't be Played
- Cause: There are bad packets in the DATA chunk.
- Symptom: There are decoding errors.
- Cause: The DATA chunk's size value is not correct.
- Symptom: The chunk that follows DATA chunk is not an INDX chunk.
- Cause: The DATA chunk's num_packets value is not correct.
- Symptom: DATA chunk's size value and calculated size mismatch.
Fix: Recover all media packets.
Problem: Player Can't Seek in the File
- Cause: The INDX chunks are corrupted or nonexistent.
- Symptom: The number of INDX chunks is less than the number of MDPR chunks.
Fix: Rebuild index chunks.
The operations also apply to RMVB files.
Using the following steps:
- Recover all packets
- Remove invalid chunks if there are any
- Rebuild index chunks
It is possible to give a maximum fix for all fixable real media files.
The Algorithm of Recovering all Media Packets
The pseudo-code is as follows:
read a packet
if(the packet is good)
collect the packet
remember the bad point
find synchronized points using INDX chunks
backtrack to some recoverable point
search packets between bad point and recoverable point
go on reading from recoverable point
- Load and list chunks and their fields
- Load and list media packets and index records
- Show MDPR chunk's type_specific_data
- Cut out a portion of the media file. Not perfect, need help!
- Recover all media packets
- Improved the efficiency of backtracking in recovery
- Search packets in corrupted area to recover more
- Remove dummy packets
- Search packets if synchronized point is not found
- Read packets only when needed, open file is now fast
- Recover Index Chunk before recovering packets
- Use temporary file to store recovered packets, memory usage is greatly reduced