[rtmpdump] Patch: improve recovery by scanning forward following packet headers to find last valid packet offset

Peter Pickford rtmpdump at netremedies.ca
Wed Nov 5 01:04:52 CET 2014


diff --git a/rtmpdump.c b/rtmpdump.c
index 13741a7..5a69395 100644
--- a/rtmpdump.c
+++ b/rtmpdump.c
@@ -303,8 +303,29 @@ GetLastKeyframe(FILE * file,       // output file [in]
   // find the last seekable frame
   off_t tsize = 0;
   uint32_t prevTagSize = 0;
+  uint32_t headerSize = 0;
+  uint32_t payloadSize = 0;
+  off_t offset = 0;
+  off_t lastGoodTag = 0;

   // go through the file and find the last video keyframe
+  fseek(file, 5, SEEK_SET);
+  if (fread(buffer, 1, 4, file) != 4) {
+       RTMP_Log(RTMP_LOGERROR, "Couldn't read headerSize from file!");
+       return RD_FAILED;
+  }
+  headerSize = AMF_DecodeInt32(buffer);
+  offset = headerSize;
+  while (offset < size) {
+       fseeko(file, offset + 5, SEEK_SET);
+       if (fread(buffer, 1, 4, file) != 4) {
+               break;
+       }
+       payloadSize = AMF_DecodeInt24(buffer);
+       lastGoodTag = offset;
+       offset += payloadSize + 15; // the back pointer the tag header
and the payload
+  }
+  tsize = size - lastGoodTag - 4; // set tsize to point to offset
from end of file of the header of last good tag
   do
     {
       int xread;


More information about the rtmpdump mailing list