diff --git a/contrib/mpeg_encode/bframe.cpp b/contrib/mpeg_encode/bframe.cpp
index 7513f0b59ac2e4b37fb39c752cff5595da62145b..7ac51ff8d75d36781f657dd86033f39c0fd72f35 100644
--- a/contrib/mpeg_encode/bframe.cpp
+++ b/contrib/mpeg_encode/bframe.cpp
@@ -117,7 +117,7 @@
  *==============*/
 
 #include "all.h"
-#include <sys/param.h>
+//#include <sys/param.h>
 #include <assert.h>
 #include "mtypes.h"
 #include "bitio.h"
diff --git a/contrib/mpeg_encode/block.cpp b/contrib/mpeg_encode/block.cpp
index 2997e54322dfa7a51b9897f2780b89f0c1cf4275..8a2f4ee4f26fcb3d0aa2190fc68ebed505d79d17 100644
--- a/contrib/mpeg_encode/block.cpp
+++ b/contrib/mpeg_encode/block.cpp
@@ -620,7 +620,7 @@ LumMotionError(LumBlock currentBlock,
       distortion /= 256;
       distortion *= LocalDCTDistortScale;
       datarate *= LocalDCTRateScale;
-      diff = (int) sqrt(distortion*distortion + datarate*datarate);
+      diff = (int) sqrt((double)(distortion*distortion + datarate*datarate));
       break;
     }
 
diff --git a/contrib/mpeg_encode/bsearch.cpp b/contrib/mpeg_encode/bsearch.cpp
index 416e36e778e442bc42b80955926f17789bd7417c..ecae2927cfa8095d969ed9d80e0d6d6092538a13 100644
--- a/contrib/mpeg_encode/bsearch.cpp
+++ b/contrib/mpeg_encode/bsearch.cpp
@@ -74,7 +74,7 @@
 /*==============*
  * HEADER FILES *
  *==============*/
-
+#include <string.h>
 #include "all.h"
 #include "mtypes.h"
 #include "frames.h"
diff --git a/contrib/mpeg_encode/combine.cpp b/contrib/mpeg_encode/combine.cpp
index 75c18e6037718cfa5e1a2daa9f992e9950d68872..535bcde4f2a5c350e744caa02b169c14b94d5afc 100644
--- a/contrib/mpeg_encode/combine.cpp
+++ b/contrib/mpeg_encode/combine.cpp
@@ -82,7 +82,7 @@
 #include "mheaders.h"
 #include "fsize.h"
 #include "combine.h"
-#include <unistd.h>
+//#include <unistd.h>
 
 /* note, remove() might not have a prototype in the standard header files,
  * but it really should -- it's not my fault!
diff --git a/contrib/mpeg_encode/frame.cpp b/contrib/mpeg_encode/frame.cpp
index 8698b439e87123ca5d33e1ad4562bb8c656a93d9..c51e074b2179e869aae40eab8408cf7db4dbcf28 100644
--- a/contrib/mpeg_encode/frame.cpp
+++ b/contrib/mpeg_encode/frame.cpp
@@ -43,6 +43,7 @@
  * HEADER FILES *
  *==============*/
 
+#include <string.h>
 #include "all.h"
 #include "mtypes.h"
 #include "frames.h"
diff --git a/contrib/mpeg_encode/frametype.cpp b/contrib/mpeg_encode/frametype.cpp
index 16020db01531976657a46d6c95f16d3266176074..6d945af56c6b0f8d8665a769e67b4d76ae4fb70c 100644
--- a/contrib/mpeg_encode/frametype.cpp
+++ b/contrib/mpeg_encode/frametype.cpp
@@ -41,6 +41,7 @@
  * HEADER FILES *
  *==============*/
 
+#include <string.h>
 #include "all.h"
 #include "prototypes.h"
 #include "frames.h"
diff --git a/contrib/mpeg_encode/headers/byteorder.h b/contrib/mpeg_encode/headers/byteorder.h
index 3dc75f1d31bb17f0dceb9a107e7ef2591c90ba1a..3dd86ccb4a3b2dfba4feebf0c0f5dec013ca3e6d 100644
--- a/contrib/mpeg_encode/headers/byteorder.h
+++ b/contrib/mpeg_encode/headers/byteorder.h
@@ -77,7 +77,9 @@
 #if !defined(WIN32) || defined(__CYGWIN__)
 #include <netinet/in.h>
 #else
+#undef boolean
 #include <winsock.h>
+#define boolean int
 #endif
 
 #endif /* FORCE_LITTLE_ENDIAN */
diff --git a/contrib/mpeg_encode/headers/libpnmrw.h b/contrib/mpeg_encode/headers/libpnmrw.h
index 18a729949ede0e09c11a14c192125e916dd600cf..a18ad7960d640fbd9824c48c876f1a3afb3d641a 100644
--- a/contrib/mpeg_encode/headers/libpnmrw.h
+++ b/contrib/mpeg_encode/headers/libpnmrw.h
@@ -26,12 +26,7 @@
 
 /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
 
-#if __STDC__
 #define ARGS(alist) alist
-#else /*__STDC__*/
-#define ARGS(alist) ()
-#define const
-#endif /*__STDC__*/
 
 
 /* Types. */
diff --git a/contrib/mpeg_encode/iframe.cpp b/contrib/mpeg_encode/iframe.cpp
index 8fc7a7413d1559b4228cb9bdee6dc99c9b642c8e..7ef85fee277fa43af2d8edcf641474401114fcbb 100644
--- a/contrib/mpeg_encode/iframe.cpp
+++ b/contrib/mpeg_encode/iframe.cpp
@@ -138,7 +138,7 @@
 
 
 #include <time.h>
-#include <sys/param.h>
+//#include <sys/param.h>
 #include "all.h"
 #include "mtypes.h"
 #include "frames.h"
diff --git a/contrib/mpeg_encode/mpeg.cpp b/contrib/mpeg_encode/mpeg.cpp
index 8cb53a2b8fa4b4d6d765a0c7ff46e36f0128ed19..dc6b7a8a5a485e28871ea789ea18c655d18bae2d 100644
--- a/contrib/mpeg_encode/mpeg.cpp
+++ b/contrib/mpeg_encode/mpeg.cpp
@@ -130,10 +130,11 @@
  * HEADER FILES *
  *==============*/
 
+#include <string.h>
 #include "all.h"
 #include <time.h>
 #include <errno.h>
-#include <unistd.h>
+//#include <unistd.h>
 #include "mtypes.h"
 #include "frames.h"
 #include "search.h"
diff --git a/contrib/mpeg_encode/param.cpp b/contrib/mpeg_encode/param.cpp
index 5dc505a6a3f7eee88d9b144d4fdd201bf96f5b9f..db24d4a79beed90bd204ab5132c4cd3672ebf635 100644
--- a/contrib/mpeg_encode/param.cpp
+++ b/contrib/mpeg_encode/param.cpp
@@ -938,6 +938,11 @@ ReadMachineNames(FILE *fpointer)
  * SIDE EFFECTS:    info stored for retrieval using GetNthInputFileName
  *
  *===========================================================================*/
+
+#if defined(WIN32) && !defined(__CYGWIN)
+#define popen _popen
+#endif
+
 static void
 ReadInputFileNames(FILE *fpointer,
                    const char *endInput)
diff --git a/contrib/mpeg_encode/psearch.cpp b/contrib/mpeg_encode/psearch.cpp
index bb96f67bab287347a05ac2c57a9c9f93ca1378b8..6bfdfbdba81433c938b0706834f27b0d7f3e5448 100644
--- a/contrib/mpeg_encode/psearch.cpp
+++ b/contrib/mpeg_encode/psearch.cpp
@@ -77,6 +77,7 @@
  * HEADER FILES *
  *==============*/
 
+#include <string.h>
 #include "all.h"
 #include "mtypes.h"
 #include "frames.h"
diff --git a/contrib/mpeg_encode/readframe.cpp b/contrib/mpeg_encode/readframe.cpp
index 3eabffadad296072c26d660a6ecdb2ef056a92a5..b3a7e71eb9739394c3fb036c9f5c37a5d710e39c 100644
--- a/contrib/mpeg_encode/readframe.cpp
+++ b/contrib/mpeg_encode/readframe.cpp
@@ -163,6 +163,10 @@ struct YuvLine {
   #define popen _popen
 #endif
    
+#if defined(WIN32) && !defined(__CYGWIN__)
+  #define popen _popen
+  #define pclose _pclose
+#endif
 
 /*==================*
  * Global VARIABLES *
@@ -1061,7 +1065,7 @@ DoGamma(MpegFrame *mf,
 
   if (!init_done) {
     for(i=0; i<256; i++) 
-      GammaVal[i]=(unsigned char) (pow(((double) i)/255.0,GammaValue)*255.0+0.5);
+      GammaVal[i]=(unsigned char) (pow(((double) i)/255.0,(double)GammaValue)*255.0+0.5);
     init_done=TRUE;
   }