diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4.cpp mpeg4ip-1.6.1/lib/mp4v2/mp4.cpp
--- mpeg4ip-1.6/lib/mp4v2/mp4.cpp	2007-07-19 20:09:44.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4.cpp	2007-09-28 22:45:11.000000000 +0200
@@ -119,15 +119,16 @@
 	try {
 		pFile = new MP4File(verbosity);
 		// LATER useExtensibleFormat, moov first, then mvex's
-		pFile->Modify(fileName);
+		if (pFile->Modify(fileName))
 		return (MP4FileHandle)pFile;
 	}
 	catch (MP4Error* e) {
 		VERBOSE_ERROR(verbosity, e->Print());
 		delete e;
-		delete pFile;
-		return MP4_INVALID_FILE_HANDLE;
 	}
+
+	if (pFile) delete pFile;
+	return MP4_INVALID_FILE_HANDLE;
 }
 
 extern "C" bool MP4Optimize(const char* existingFileName, 
diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4file.cpp mpeg4ip-1.6.1/lib/mp4v2/mp4file.cpp
--- mpeg4ip-1.6/lib/mp4v2/mp4file.cpp	2007-07-05 18:38:02.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4file.cpp	2007-09-28 22:45:11.000000000 +0200
@@ -195,7 +195,7 @@
 }
 
     
-void MP4File::Modify(const char* fileName)
+bool MP4File::Modify(const char* fileName)
 {
 	m_fileName = MP4Stralloc(fileName);
 	m_mode = 'r';
@@ -211,7 +211,8 @@
 
 	if (pMoovAtom == NULL) {
 		// there isn't one, odd but we can still proceed
-		pMoovAtom = AddChildAtom(m_pRootAtom, "moov");
+	  return false;
+	  //pMoovAtom = AddChildAtom(m_pRootAtom, "moov");
 	} else {
 		numAtoms = m_pRootAtom->GetNumberOfChildAtoms();
 
@@ -285,6 +286,7 @@
 
 	// start writing new mdat
 	pMdatAtom->BeginWrite(Use64Bits("mdat"));
+	return true;
 }
 
 void MP4File::Optimize(const char* orgFileName, const char* newFileName)
@@ -624,7 +626,6 @@
 		ASSERT(m_pTracks[i]);
 		m_pTracks[i]->FinishWrite();
 	}
-
 	// ask root atom to write
 	m_pRootAtom->FinishWrite();
 
diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4file.h mpeg4ip-1.6.1/lib/mp4v2/mp4file.h
--- mpeg4ip-1.6/lib/mp4v2/mp4file.h	2007-06-04 18:21:51.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4file.h	2007-09-28 22:45:11.000000000 +0200
@@ -56,7 +56,7 @@
 		    char* majorBrand = NULL, 
 		    u_int32_t minorVersion = 0, char** supportedBrands = NULL, 
 		    u_int32_t supportedBrandsCount = 0);
-	void Modify(const char* fileName);
+	bool Modify(const char* fileName);
 	void Optimize(const char* orgFileName, 
 		const char* newFileName = NULL);
 	void Dump(FILE* pDumpFile = NULL, bool dumpImplicits = false);
diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4.h mpeg4ip-1.6.1/lib/mp4v2/mp4.h
--- mpeg4ip-1.6/lib/mp4v2/mp4.h	2007-09-19 19:44:49.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4.h	2007-09-28 22:45:11.000000000 +0200
@@ -1287,6 +1287,9 @@
 			uint32_t decodeSize, 
 			uint32_t *pDataSize);
 void MP4Free(void *p);
+
+  void MP4SetLibFunc(lib_message_func_t libfunc);
+
 #ifdef __cplusplus
 }
 #endif
diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4track.cpp mpeg4ip-1.6.1/lib/mp4v2/mp4track.cpp
--- mpeg4ip-1.6/lib/mp4v2/mp4track.cpp	2007-04-12 19:04:03.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4track.cpp	2007-09-28 22:45:11.000000000 +0200
@@ -483,6 +483,7 @@
 {
 	// write out any remaining samples in chunk buffer
 	WriteChunkBuffer();
+
 	if (m_pStszFixedSampleSizeProperty == NULL &&
 	    m_stsz_sample_bits == 4) {
 	  if (m_have_stz2_4bit_sample) {
@@ -646,7 +647,10 @@
     numBytes /= m_bytesPerSample;
   }
 	// for first sample
-	if (sampleId == 1) {
+	// wmay - if we are adding, we want to make sure that
+	// we don't inadvertently set up the fixed size again.
+	// so, we check the number of samples
+	if (sampleId == 1 && GetNumberOfSamples() == 0) {
 	  if (m_pStszFixedSampleSizeProperty == NULL ||
 	      numBytes == 0) {
 	    // special case of first sample is zero bytes in length
@@ -670,13 +674,15 @@
 	  // doesn't match our sample size, we need to write the current
 	  // sample size into the table
 	  if (fixedSampleSize == 0 || numBytes != fixedSampleSize) {
-
 	    if (fixedSampleSize != 0) {
 	      // fixed size was set; we need to clear fixed sample size
 	      m_pStszFixedSampleSizeProperty->SetValue(0); 
 	      
 	      // and create sizes for all previous samples
-	      for (MP4SampleId sid = 1; sid < sampleId; sid++) {
+	      // use GetNumberOfSamples due to needing the total number
+	      // not just the appended part of the file
+	      uint32_t samples = GetNumberOfSamples();
+	      for (MP4SampleId sid = 1; sid <= samples; sid++) {
 		SampleSizePropertyAddValue(fixedSampleSize);
 	      }
 	    }
@@ -1345,7 +1351,8 @@
 			      (MP4Property**)&m_pStssSampleProperty));
 
       // set values for all samples that came before this one
-      for (MP4SampleId sid = 1; sid < sampleId; sid++) {
+      uint32_t samples = GetNumberOfSamples();
+      for (MP4SampleId sid = 1; sid < samples; sid++) {
 	m_pStssSampleProperty->AddValue(sid);
 	m_pStssCountProperty->IncrementValue();
       }
diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4util.cpp mpeg4ip-1.6.1/lib/mp4v2/mp4util.cpp
--- mpeg4ip-1.6/lib/mp4v2/mp4util.cpp	2007-04-12 19:04:03.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4util.cpp	2007-09-28 22:45:11.000000000 +0200
@@ -22,8 +22,21 @@
 
 #include "mp4common.h"
 
+static lib_message_func_t libfunc = NULL;
+extern "C"   void MP4SetLibFunc(lib_message_func_t libf)
+{
+  libfunc = libf;
+}
+
 void MP4Error::Print(FILE* pFile)
 {
+  if (libfunc != NULL) {
+    (libfunc)(LOG_ERR, "MP4ERROR", "%s:%s:%s",
+	      m_where == NULL ? "" : m_where, 
+	      m_errstring == NULL ? "" : m_errstring,
+	      m_errno ? strerror(m_errno) : "");
+    return;
+  } 
 	fprintf(pFile, "MP4ERROR: ");
 	if (m_where) {
 		fprintf(pFile, "%s", m_where);
diff -Naur -X no mpeg4ip-1.6/lib/mp4v2/mp4util.h mpeg4ip-1.6.1/lib/mp4v2/mp4util.h
--- mpeg4ip-1.6/lib/mp4v2/mp4util.h	2007-05-24 21:13:17.000000000 +0200
+++ mpeg4ip-1.6.1/lib/mp4v2/mp4util.h	2007-09-28 22:45:11.000000000 +0200
@@ -26,8 +26,7 @@
 #ifndef ASSERT
 #define ASSERT(expr) \
 	if (!(expr)) { \
-		(void)fflush(stdout); \
-		assert((expr)); \
+		throw new MP4Error("assert failure", __STRING((expr))); \
 	}
 #endif
 #define WARNING(expr) \
