Index: programs/programs.pro
===================================================================
--- programs/programs.pro	(revision 20649)
+++ programs/programs.pro	(working copy)
@@ -18,4 +18,3 @@
     SUBDIRS += mythtranscode
 }
 
-mingw: SUBDIRS -= mythtranscode mythtranscode/replex
Index: programs/mythtranscode/replex/replex.pro
===================================================================
--- programs/mythtranscode/replex/replex.pro	(revision 20649)
+++ programs/mythtranscode/replex/replex.pro	(working copy)
@@ -23,6 +23,8 @@
 LIBS += -lmythavcodec-$$LIBVERSION -lmythavformat-$$LIBVERSION -lmythavutil-$$LIBVERSION
 LIBS += $$EXTRA_LIBS
 
+mingw:LIBS += -lws2_32
+
 isEmpty(QMAKE_EXTENSION_SHLIB) {
   QMAKE_EXTENSION_SHLIB=so
 }
Index: programs/mythtranscode/replex/replex.c
===================================================================
--- programs/mythtranscode/replex/replex.c	(revision 20649)
+++ programs/mythtranscode/replex/replex.c	(working copy)
@@ -2390,6 +2390,9 @@
 				perror("Error opening output file");
 				exit(1);
 			}
+#ifdef USING_MINGW
+			_setmode(rx.fd_out, _O_BINARY);
+#endif		
 			fprintf(stderr,"Output File is: %s\n", 
 				filename);
 		} else {
@@ -2460,6 +2463,9 @@
 			perror("Error opening output file");
 			exit(1);
 		}
+#ifdef USING_MINGW
+		_setmode(rx.dmx_out[0], _O_BINARY);
+#endif		
 		fprintf(stderr,"Video output File is: %s\n", 
 			fname);
 		
@@ -2477,6 +2483,9 @@
 				perror("Error opening output file");
 				exit(1);
 			}
+#ifdef USING_MINGW
+			_setmode(rx.dmx_out[i+1], _O_BINARY);
+#endif		
 			fprintf(stderr,"Audio%d output File is: %s\n",i,fname);
 		}
 		
Index: programs/mythtranscode/mythtranscode.pro
===================================================================
--- programs/mythtranscode/mythtranscode.pro	(revision 20649)
+++ programs/mythtranscode/mythtranscode.pro	(working copy)
@@ -9,6 +9,8 @@
 target.path = $${PREFIX}/bin
 INSTALLS = target
 
+mingw:LIBS += -lws2_32 
+
 QMAKE_CLEAN += $(TARGET)
 
 # Input
Index: programs/mythtranscode/main.cpp
===================================================================
--- programs/mythtranscode/main.cpp	(revision 20649)
+++ programs/mythtranscode/main.cpp	(working copy)
@@ -812,7 +812,8 @@
     if (gContext->GetNumSetting("TruncateDeletesSlowly", 0))
         return slowDelete(filename);
 
-    return unlink(filename.toLocal8Bit().constData());
+    QFile ftarget(filename.toLocal8Bit().constData());
+    return !ftarget.remove();
 }
 
 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)
@@ -854,14 +855,16 @@
         const QString newfile = cnf;
         const QByteArray anewfile = newfile.toLocal8Bit();
 
-        if (rename(fname.constData(), aoldfile.constData()) == -1)
+        QFile srcQFile(fname.constData());
+        if (!srcQFile.rename(aoldfile.constData()))
         {
             VERBOSE(VB_IMPORTANT,
                     QString("mythtranscode: Error Renaming '%1' to '%2'")
                     .arg(filename).arg(oldfile) + ENO);
         }
 
-        if (rename(atmpfile.constData(), anewfile.constData()) == -1)
+        QFile tmpQFile(atmpfile.constData());        
+        if (!tmpQFile.rename(anewfile.constData()))
         {
             VERBOSE(VB_IMPORTANT,
                     QString("mythtranscode: Error Renaming '%1' to '%2'")
@@ -966,7 +969,7 @@
                 QFile checkFile(oldfileprev);
 
                 if ((oldfileprev != newfileprev) && (checkFile.exists()))
-                    rename(aoldfileprev.constData(), anewfileprev.constData());
+                    checkFile.rename(anewfileprev.constData());
             }
         }
 
Index: programs/mythtranscode/transcode.cpp
===================================================================
--- programs/mythtranscode/transcode.cpp	(revision 20649)
+++ programs/mythtranscode/transcode.cpp	(working copy)
@@ -1201,8 +1201,17 @@
         fifow->FIFODrain();
     }
     delete newFrame;
+    // HACK? - destructor apparently never called (Qt3/Qt4 deleteLater issue?)
+    // Pointers not reset; shouldn't dtor segfault if it was working properly?
     if (player_ctx)
         delete player_ctx;
+    // HACK - delete ringbuffer else outfile is open when we try to rename it
+    // As before, destructor is supposed to take care of these deletes for us!
+    if (nvr)
+        delete nvr;
+    if (outRingBuffer)
+        delete outRingBuffer;
+
     return REENCODE_OK;
 }
 
Index: programs/mythtranscode/mpeg2fix.h
===================================================================
--- programs/mythtranscode/mpeg2fix.h	(revision 20649)
+++ programs/mythtranscode/mpeg2fix.h	(working copy)
@@ -131,6 +131,7 @@
 
   private:
     multiplex_t *mplex;
+    int fd_out;
 };
 
 class MPEG2fixup
Index: programs/mythtranscode/mpeg2fix.cpp
===================================================================
--- programs/mythtranscode/mpeg2fix.cpp	(revision 20649)
+++ programs/mythtranscode/mpeg2fix.cpp	(working copy)
@@ -448,7 +448,7 @@
 
 MPEG2replex::MPEG2replex() :
     done(0),      otype(0),
-    ext_count(0), mplex(0)
+    ext_count(0), mplex(0), fd_out(0)
 {
     memset(&vrbuf, 0, sizeof(vrbuf));
     memset(extrbuf, 0, sizeof(extrbuf));
@@ -474,6 +474,8 @@
         if (index_extrbuf[i].size)
             ring_destroy(&index_extrbuf[i]);
     }
+    if (fd_out)
+	    close(fd_out);
 }
 
 int MPEG2replex::WaitBuffers()
@@ -530,7 +532,6 @@
 
 
     int video_delay = 0, audio_delay = 0;
-    int fd_out;
 
     memset(&mx, 0, sizeof(mx));
     memset(ext_ok, 0, sizeof(ext_ok));
@@ -538,6 +539,9 @@
     mx.priv = (void *)this;
 
     fd_out = open(outfile, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
+#ifdef USING_MINGW
+    _setmode(fd_out, _O_BINARY);
+#endif
 
     //await buffer fill
     pthread_mutex_lock(&mutex);
@@ -1010,6 +1014,9 @@
         VERBOSE(MPF_IMPORTANT, QString("Couldn't open file %1").arg(filename));
         return;
     }
+#ifdef USING_MINGW
+    _setmode(fh, _O_BINARY);
+#endif
 
     write(fh, info->display_fbuf->buf[0],
           info->sequence->width * info->sequence->height);
@@ -1027,6 +1034,9 @@
         VERBOSE(MPF_IMPORTANT, QString("Couldn't open file %1").arg(filename));
         return;
     }
+#ifdef USING_MINGW
+    _setmode(fh, _O_BINARY);
+#endif
 
     write(fh, data, size);
     close(fh);
Index: libs/libmythtv/NuppelVideoRecorder.cpp
===================================================================
--- libs/libmythtv/NuppelVideoRecorder.cpp	(revision 20649)
+++ libs/libmythtv/NuppelVideoRecorder.cpp	(working copy)
@@ -10,8 +10,10 @@
 #elif HAVE_SOUNDCARD_H
     #include <soundcard.h>
 #endif
+#ifndef USING_MINGW
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#endif
 #include <cerrno>
 #include <cmath>
 
@@ -778,6 +780,7 @@
  */
 bool NuppelVideoRecorder::MJPEGInit(void)
 {
+#ifndef USING_MINGW
     bool we_opened_fd = false;
     int init_fd = fd;
     if (init_fd < 0)
@@ -819,7 +822,7 @@
             hmjpg_maxw = 640;
         return true;
     }
-
+#endif // !USING_MINGW
     VERBOSE(VB_IMPORTANT, LOC_ERR + "MJPEG not supported by device");
     return false;
 }
@@ -966,6 +969,7 @@
 
 void NuppelVideoRecorder::ProbeV4L2(void)
 {
+#ifndef USING_MINGW
     usingv4l2 = true;
 
     struct v4l2_capability vcap;
@@ -995,6 +999,7 @@
     QString driver = (char *)vcap.driver;
     if (driver == "go7007")
         go7007 = true;
+#endif // !USING_MINGW    
 }
 
 void NuppelVideoRecorder::StartRecording(void)
@@ -1073,6 +1078,7 @@
 
 void NuppelVideoRecorder::DoV4L(void)
 {
+#ifndef USING_MINGW
     struct video_capability vc;
     struct video_mmap mm;
     struct video_mbuf vm;
@@ -1255,10 +1261,12 @@
 
     recording = false;
     close(fd);
+#endif // !USING_MINGW    
 }
 
 void NuppelVideoRecorder::DoV4L2(void)
 {
+#ifndef USING_MINGW
     struct v4l2_format     vfmt;
     struct v4l2_buffer     vbuf;
     struct v4l2_requestbuffers vrbuf;
@@ -1612,10 +1620,12 @@
     recording = false;
     close(fd);
     close(channelfd);
+#endif // !USING_MINGW
 }
 
 void NuppelVideoRecorder::DoMJPEG(void)
 {
+#ifndef USING_MINGW
     struct mjpeg_params bparm;
 
     if (ioctl(fd, MJPIOC_G_PARAMS, &bparm) < 0)
@@ -1748,6 +1758,7 @@
             
     recording = false;
     close(fd);
+#endif // !USING_MINGW    
 }
 
 int NuppelVideoRecorder::SpawnChildren(void)
@@ -2647,6 +2658,7 @@
 
 void NuppelVideoRecorder::doVbiThread(void)
 {
+#ifndef USING_MINGW    
     //VERBOSE(VB_IMPORTANT, LOC + "vbi begin");
     struct VBIData vbicallbackdata;
     struct vbi *pal_tt = NULL;
@@ -2793,6 +2805,7 @@
         cc_close(ntsc_cc);
 
     //VERBOSE(VB_RECORD, LOC + "vbi end");
+#endif // !USING_MINGW
 }
 
 
Index: libs/libmythtv/libmythtv.pro
===================================================================
--- libs/libmythtv/libmythtv.pro	(revision 20649)
+++ libs/libmythtv/libmythtv.pro	(working copy)
@@ -583,7 +583,6 @@
     DEFINES += USING_D3D
 
     HEADERS += videoout_d3d.h
-    SOURCES -= NuppelVideoRecorder.cpp
     SOURCES += videoout_d3d.cpp
 
     LIBS += -lpthread
