Click here to Skip to main content
Click here to Skip to main content

Repair RealMedia Files

By , 3 Jan 2007
 
Sample Image - RealMedia.png

Introduction

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 RecordDefs and 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:

  1. Recover all packets
  2. Remove invalid chunks if there are any
  3. 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
}
else
{
    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
}

History

  • 2006-11-17
    • Load and list chunks and their fields
  • 2006-11-18
    • Load and list media packets and index records
  • 2006-11-19
    • Check and fix errors
  • 2006-11-20
    • Show MDPR chunk's type_specific_data
    • Cut out a portion of the media file. Not perfect, need help!
  • 2006-11-21
    • Fixed some bugs
  • 2006-11-22
    • Recover all media packets
  • 2006-11-23
    • Improved the efficiency of backtracking in recovery
    • Search packets in corrupted area to recover more
  • 2006-11-25
    • Remove dummy packets
    • Search packets if synchronized point is not found
  • 2006-12-23
    • Read packets only when needed, open file is now fast
    • Recover Index Chunk before recovering packets
  • 2007-01-04
    • Use temporary file to store recovered packets, memory usage is greatly reduced

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Liu Junfeng
Software Developer
China China
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionReal Media Decoding Encodingmemberalionline24 Jan '07 - 22:51 
Generaldisk i/o rather memory manipulationmemberUnruled Boy27 Nov '06 - 16:52 
how about that? it is REALLY SLOW to load large rm files!
 

btw. hao dong xi, ji xu nu liLaugh | :laugh:
 
Regards,
unruledboy@hotmail.com

GeneralRe: disk i/o rather memory manipulationmemberdfer28 Nov '06 - 0:15 
NewsRe: disk i/o rather memory manipulationmemberLiu Junfeng4 Jan '07 - 1:24 
GeneralRe: disk i/o rather memory manipulationmemberdfer6 Jan '07 - 10:48 
JokeShaFa..of course cool stuff..memberdfer24 Nov '06 - 10:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 4 Jan 2007
Article Copyright 2006 by Liu Junfeng
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid