Index: libs/libmythtv/NuppelVideoRecorder.cpp
===================================================================
--- libs/libmythtv/NuppelVideoRecorder.cpp	(revision 10269)
+++ libs/libmythtv/NuppelVideoRecorder.cpp	(working copy)
@@ -68,7 +68,6 @@
     inputchannel = 1;
     compression = 1;
     compressaudio = 1;
-    rawmode = 0;
     usebttv = 1;
     w = 352;
     h = 240;
@@ -2856,11 +2877,9 @@
 void NuppelVideoRecorder::WriteVideo(VideoFrame *frame, bool skipsync, 
                                      bool forcekey)
 {
-    int tmp = 0, r = 0, out_len = OUT_LEN;
+    int tmp = 0, out_len = OUT_LEN;
     struct rtframeheader frameheader;
-    int xaa, freecount = 0, compressthis;
-    int raw = 0;
-    int timeperframe = 40;
+    int raw = 0, compressthis = compression;
     uint8_t *planes[3];
     int len = frame->size;
     int fnum = frame->frameNumber;
@@ -2871,11 +2890,8 @@
 
     planes[0] = buf;
     planes[1] = planes[0] + frame->width * frame->height;
-    if (picture_format == PIX_FMT_YUV422P)
-        planes[2] = planes[1] + (frame->width * frame->height) / 2;
-    else
-        planes[2] = planes[1] + (frame->width * frame->height) / 4;
-    compressthis = compression;
+    planes[2] = planes[1] + (frame->width * frame->height) /
+                (picture_format == PIX_FMT_YUV422P ? 2 : 4);
 
     if (lf == 0) 
     {   // this will be triggered every new file
@@ -2886,35 +2902,6 @@
         forcekey = true;
     }
 
-    // count free buffers -- FIXME this can be done with less CPU time!!
-    for (xaa = 0; xaa < video_buffer_count; xaa++) 
-    {
-        if (videobuffer[xaa]->freeToBuffer) 
-            freecount++;
-    }
-
-    if (freecount < (video_buffer_count / 3)) 
-        compressthis = 0; // speed up the encode process
-    
-    if (freecount < 5 || rawmode)
-        raw = 1; // speed up the encode process
-    
-    if (raw==1 || compressthis==0) 
-    {
-        if (ringBuffer->IsIOBound())
-        {
-            /* need to compress, the disk can't handle any more bandwidth*/
-            raw=0;
-            compressthis=1;
-        }
-    }
-
-    if (transcoding)
-    {
-        raw = 0;
-        compressthis = 1;
-    }
-
     // see if it's time for a seeker header, sync information and a keyframe
     frameheader.keyframe  = frameofgop;             // no keyframe defaulted
 
@@ -2986,6 +2973,33 @@
     }
     else
     {
+        int freecount = 0;
+        freecount = act_video_buffer > act_video_encode ?
+                    video_buffer_count - (act_video_buffer - act_video_encode) :
+                    act_video_encode - act_video_buffer;
+
+        if (freecount < (video_buffer_count / 3)) 
+            compressthis = 0; // speed up the encode process
+    
+        if (freecount < 5)
+            raw = 1; // speed up the encode process
+    
+        if (raw==1 || compressthis==0) 
+        {
+            if (ringBuffer->IsIOBound())
+            {
+                /* need to compress, the disk can't handle any more bandwidth*/
+                raw=0;
+                compressthis=1;
+            }
+        }
+
+        if (transcoding)
+        {
+            raw = 0;
+            compressthis = 1;
+        }
+
         if (!raw) 
         {
             if (wantkeyframe)
@@ -2996,7 +3010,9 @@
             tmp = len;
 
         // here is lzo compression afterwards
-        if (compressthis) {
+        if (compressthis)
+        {
+            int r = 0;
             if (raw) 
                 r = lzo1x_1_compress((unsigned char*)buf, len, 
                                      out, (lzo_uint *)&out_len, wrkmem);
@@ -3011,34 +3027,6 @@
         }
     }
 
-    dropped = (((fnum-lf)>>1) - 1); // should be += 0 ;-)
-    
-    if (dropped>0)
-    {
-        if (ntsc_framerate)
-            timeperframe = (int)(1000 / (30 * framerate_multiplier));
-        else
-            timeperframe = (int)(1000 / (25 * framerate_multiplier));
-    }
-   
-    // if we have lost frames we insert "copied" frames until we have the
-    // exact count because of that we should have no problems with audio 
-    // sync, as long as we don't loose audio samples :-/
-  
-    while (0 && dropped > 0) 
-    {
-        frameheader.timecode = lasttimecode + timeperframe;
-        lasttimecode = frameheader.timecode;
-        frameheader.keyframe  = frameofgop;             // no keyframe defaulted
-        frameheader.packetlength =  0;   // no additional data needed
-        frameheader.frametype    = 'V';  // last frame (or nullframe if first)
-        frameheader.comptype    = 'L';
-        WriteFrameheader(&frameheader);
-        // we don't calculate sizes for lost frames for compression computation
-        dropped--;
-        frameofgop++;
-    }
-
     frameheader.frametype = 'V'; // video frame
     frameheader.timecode  = timecode;
     lasttimecode = frameheader.timecode;
Index: libs/libmythtv/NuppelVideoRecorder.h
===================================================================
--- libs/libmythtv/NuppelVideoRecorder.h	(revision 10269)
+++ libs/libmythtv/NuppelVideoRecorder.h	(working copy)
@@ -138,7 +138,6 @@
     
     int fd; // v4l input file handle
     signed char *strm;
-    long dropped;
     unsigned int lf, tf;
     int M1, M2, Q;
     int w, h;
@@ -154,8 +153,6 @@
     int audio_samplerate; // rate we request from sounddevice
     int effectivedsp; // actual measured rate
 
-    int quiet;
-    int rawmode;
     int usebttv;
     float video_aspect;
 
