Merge "Prevent invalid frame durations"
diff --git a/libvideoeditor/vss/3gpwriter/src/M4MP4W_Writer.c b/libvideoeditor/vss/3gpwriter/src/M4MP4W_Writer.c
index 9ad94e0..cdfc441 100755
--- a/libvideoeditor/vss/3gpwriter/src/M4MP4W_Writer.c
+++ b/libvideoeditor/vss/3gpwriter/src/M4MP4W_Writer.c
@@ -2486,6 +2486,12 @@
 
 #endif
 
+        if ((M4MP4W_Time32)auPtr->CTS < mMp4FileDataPtr->videoTrackPtr->CommonData.lastCTS) {
+            // Do not report as error, it will abort the entire filewrite. Just skip this frame.
+            M4OSA_TRACE1_0("Skip frame. Video frame has too old timestamp.");
+            return M4NO_ERROR;
+        }
+
         mMp4FileDataPtr->videoTrackPtr->currentPos += auPtr->size;
 
         /* Warning: time conversion cast 64to32! */