Index: src/atoms.c
===================================================================
--- src/atoms.c	(revision 126)
+++ src/atoms.c	(working copy)
@@ -564,7 +564,7 @@
   guint64 sum = 0;
   while(walker) {
     STTSEntry *entry = (STTSEntry*) walker->data;
-    sum += entry->sample_count * entry->sample_delta;
+    sum += (guint64)(entry->sample_count) * entry->sample_delta;
     walker = g_list_next(walker);
   }
   return sum;
Index: src/gstqtmux.c
===================================================================
--- src/gstqtmux.c	(revision 126)
+++ src/gstqtmux.c	(working copy)
@@ -795,36 +795,35 @@
   }
 
   nsamples = 0;
-  guint64 offset = 0;
+  gint64 offset = 0;
 
   //calculate ctts entry values (if needed)
   caps = GST_BUFFER_CAPS(last_buf);
   mimetype = gst_structure_get_name(gst_caps_get_structure(caps, 0));
   if (strcmp(mimetype, "video/x-qt-part") == 0) {
-    offset = (guint64)GST_BUFFER_TIMESTAMP(last_buf) -
-        GST_BUFFER_OFFSET(last_buf);
+    guint64 dts = gst_qt_mux_scale_clock_time(qtmux,
+                      GST_BUFFER_OFFSET(last_buf),
+                      track_data_get_timescale(pad->track));
+    guint64 pts = gst_qt_mux_scale_clock_time(qtmux,
+                      GST_BUFFER_TIMESTAMP(last_buf),
+                      track_data_get_timescale(pad->track));
+    offset = (gint64)(pts - dts);
     nsamples = 1;
   } else if (strcmp(mimetype, "video/x-h264") == 0) {
+    guint64 dts = gst_qt_mux_scale_clock_time(qtmux, get_dts(qtmux, pad),
+                      track_data_get_timescale(pad->track));
+    guint64 pts = gst_qt_mux_scale_clock_time(qtmux,
+                      GST_BUFFER_TIMESTAMP(last_buf),
+                      track_data_get_timescale(pad->track));
+
+    offset = (gint64)(pts - dts);
     nsamples = 1;
-    guint64 dts = get_dts(qtmux, pad);
-    if (dts < (guint64)GST_BUFFER_TIMESTAMP(last_buf)) {
-      offset = (guint64)GST_BUFFER_TIMESTAMP(last_buf) - dts;
-    } else {
-      /*
-       * due to rounding, offset could be -1, so we
-       * prevent it here
-       * (probably this was another bug that was fixed, so
-       * we need to test this again) FIXME
-       */
-      offset = 0;
-    }
   }
   //add ctts entry (if needed)
   if (nsamples > 0) {
     GST_DEBUG_OBJECT(qtmux, "Adding ctts entry for pad %s: %" G_GUINT64_FORMAT,
         GST_PAD_NAME(pad->collect.pad), offset);
-    sample->pts_offset = (guint32)gst_qt_mux_scale_clock_time(qtmux, offset,
-        track_data_get_timescale(pad->track));
+    sample->pts_offset = offset;
     sample->pts_offset_samples = nsamples;
   }
 
@@ -1034,8 +1033,9 @@
 
 static guint32
 adjust_rate(guint64 rate) {
-  /* if it is larger than 32bits we need to truncate */
-  while(rate >= G_MAXUINT32) {
+  /* if it is larger than 1000000 (1us), truncate so we can handle decent
+   * durations */
+  while(rate >= 1000000) {
     guint last = rate % 10;
     rate /= 10;
     if (last >= 5) {
