diff --git a/configure b/configure
index b90ae6e..99b5788 100755
--- a/configure
+++ b/configure
@@ -3819,38 +3819,47 @@ done
 
 # these are off by default, so fail if requested and not available
 enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32
-enabled fontconfig && require_pkg_config fontconfig "fontconfig/fontconfig.h" FcInit
+enabled fontconfig && require fontconfig fontconfig/fontconfig.h FcInit -lfontconfig -lfreetype -lexpat -liconv
 enabled frei0r     && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
-enabled gnutls     && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
+enabled gnutls     && { check_lib gnutls/gnutls.h gnutls_global_init -lgnutls -lhogweed -lnettle -lgmp -lws2_32 -lcrypt32 ||
+                        die "ERROR: gnutls not found"; }
 enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
 enabled libaacplus && require  "libaacplus >= 2.0.0" aacplus.h aacplusEncOpen -laacplus
-enabled libass     && require_pkg_config libass ass/ass.h ass_library_init
 enabled libbluray  && require libbluray libbluray/bluray.h bd_open -lbluray
-enabled libcdio    && require2 libcdio "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio
+enabled libcdio    && require2 libcdio "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio -lwinmm
 enabled libcelt    && require libcelt celt/celt.h celt_decode -lcelt0 &&
                       { check_lib celt/celt.h celt_decoder_create_custom -lcelt0 ||
                         die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
-enabled libcaca    && require_pkg_config caca caca.h caca_create_canvas
+enabled libcaca    && require  caca caca.h caca_create_canvas -lcaca
 enabled libfaac    && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
 enabled libfdk_aac && require  libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac
 flite_libs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lflite_cmu_us_kal16 -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish -lflite_cmulex -lflite"
 enabled libflite   && require2 libflite "flite/flite.h" flite_init $flite_libs
-enabled libfreetype && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType
-enabled libgsm     && require  libgsm gsm/gsm.h gsm_create -lgsm
+enabled libfreetype && { add_cflags -I/mingw/include/freetype2 &&
+                         require2 freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType -lfreetype; }
+enabled libass     && require  libass ass/ass.h ass_library_init -lass -lfribidi -lfontconfig -lexpat -liconv
+enabled libgsm     && require  libgsm gsm.h gsm_create -lgsm
 enabled libilbc    && require  libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc
-enabled libmodplug && require  libmodplug libmodplug/modplug.h ModPlug_Load -lmodplug
+enabled libmodplug && require  libmodplug libmodplug/modplug.h ModPlug_Load -lmodplug -lstdc++
 enabled libmp3lame && require  "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
 enabled libnut     && require  libnut libnut.h nut_demuxer_init -lnut
 enabled libopencore_amrnb  && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
 enabled libopencore_amrwb  && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
-enabled libopencv  && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
+enabled libopencv  && { { add_ldflags -L/mingw/share/opencv/3rdparty/lib &&
+                          check_lib opencv/cxcore.h cvCreateImageHeader -lopencv_imgproc220 -lopencv_core220 -lopencv_lapack -lstdc++; } ||
+                        die "ERROR: libopencv version must be 2.2"; }
 enabled libopenjpeg && { check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg ||
                          check_lib openjpeg.h opj_version -lopenjpeg ||
                          die "ERROR: libopenjpeg not found"; }
-enabled libopus    && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
+enabled libopus    && { add_cflags -I/mingw/include/opus &&
+                        require opus opus_multistream.h opus_multistream_decoder_create -lopus; }
 enabled libpulse && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new
-enabled librtmp    && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
-enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
+enabled librtmp    && { check_lib librtmp/rtmp.h RTMP_Socket -lrtmp -lpolarssl -lwinmm -lws2_32 ||
+                        check_lib librtmp/rtmp.h RTMP_Socket -lrtmp -lgnutls -lhogweed -lnettle -lgmp -lwinmm -lws2_32 -lcrypt32 ||
+                        check_lib librtmp/rtmp.h RTMP_Socket -lrtmp -lssl -lcrypto -lwinmm -lws2_32 -lgdi32 ||
+                        die "ERROR: librtmp not found or RTMP_Socket() missing, librtmp version must be >= 2.2.f"; }
+enabled libschroedinger && { add_cflags -I/mingw/include/schroedinger-1.0 &&
+                             require schroedinger-1.0 schroedinger/schro.h schro_init -lschroedinger-1.0 -lorc-0.4; }
 enabled libsoxr    && require  libsoxr soxr.h soxr_create -lsoxr
 enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
 enabled libstagefright_h264  && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h
@@ -3907,7 +3916,7 @@ if check_pkg_config sdl SDL_events.h SDL_PollEvent; then
 else
   if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
     sdl_cflags=$("${SDL_CONFIG}" --cflags)
-    sdl_libs=$("${SDL_CONFIG}" --libs)
+    sdl_libs=$("${SDL_CONFIG}" --static-libs)
     check_func_headers SDL_version.h SDL_Linked_Version $sdl_cflags $sdl_libs &&
     check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
     enable sdl &&
diff --git a/ffmpeg.c b/ffmpeg.c
index 73b5dff..3acc61b 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1188,26 +1188,33 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
                                           ost->st->time_base, AV_TIME_BASE_Q));
     }
 
-    secs = pts / AV_TIME_BASE;
-    us = pts % AV_TIME_BASE;
-    mins = secs / 60;
-    secs %= 60;
-    hours = mins / 60;
-    mins %= 60;
+    if (progress_avio) {
+        secs = pts / AV_TIME_BASE;
+        us = pts % AV_TIME_BASE;
+        mins = secs / 60;
+        secs %= 60;
+        hours = mins / 60;
+        mins %= 60;
+    }
 
     bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
 
     snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
              "size=%8.0fkB time=", total_size / 1024.0);
-    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-             "%02d:%02d:%02d.%02d ", hours, mins, secs,
-             (100 * us) / AV_TIME_BASE);
+    if (progress_avio)
+        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+                 "%02d:%02d:%02d.%02d ", hours, mins, secs,
+                 (100 * us) / AV_TIME_BASE);
+    else
+        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+                 "%0.2f ", (double)pts / AV_TIME_BASE);
     snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
              "bitrate=%6.1fkbits/s", bitrate);
     av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size);
     av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts);
-    av_bprintf(&buf_script, "out_time=%02d:%02d:%02d.%06d\n",
-               hours, mins, secs, us);
+    if (progress_avio)
+        av_bprintf(&buf_script, "out_time=%02d:%02d:%02d.%06d\n",
+                   hours, mins, secs, us);
 
     if (nb_frames_dup || nb_frames_drop)
         snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c
index f3cfb91..7a051a8 100644
--- a/libavcodec/libgsm.c
+++ b/libavcodec/libgsm.c
@@ -27,7 +27,7 @@
 
 // The idiosyncrasies of GSM-in-WAV are explained at http://kbs.cs.tu-berlin.de/~jutta/toast.html
 
-#include <gsm/gsm.h>
+#include <gsm.h>
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 8765e56..33b1296 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -353,6 +353,11 @@ static av_cold int X264_init(AVCodecContext *avctx)
                 OPT_STR(param, val);
             p= strchr(p, ':');
             p+=!!p;
+
+            if (strcmp(param, "bframes") == 0)
+                avctx->max_b_frames = x4->params.i_bframe;
+            if (strcmp(param, "weightp") == 0)
+                x4->weightp = x4->params.analyse.i_weighted_pred;
         }
     }
 
@@ -371,6 +376,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
         x4->params.i_keyint_max         = avctx->gop_size;
     if (avctx->max_b_frames >= 0)
         x4->params.i_bframe             = avctx->max_b_frames;
+    else
+        x4->params.i_bframe             = 0;
     if (avctx->scenechange_threshold >= 0)
         x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
     if (avctx->qmin >= 0)
@@ -416,6 +423,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
         x4->params.rc.i_lookahead = x4->rc_lookahead;
     if (x4->weightp >= 0)
         x4->params.analyse.i_weighted_pred = x4->weightp;
+    else
+        x4->params.analyse.i_weighted_pred = 0;
     if (x4->weightb >= 0)
         x4->params.analyse.b_weighted_bipred = x4->weightb;
     if (x4->cplxblur >= 0)
diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index dae8ac8..9abf6cd 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -457,6 +457,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)  {
     xvid_enc_create.num_zones = 0;
 
     xvid_enc_create.num_threads = avctx->thread_count;
+    xvid_enc_create.num_slices = avctx->slices;
 
     xvid_enc_create.plugins = plugins;
     xvid_enc_create.num_plugins = 0;
diff --git a/libavutil/common.h b/libavutil/common.h
index 0f36309..b0b04a2 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -426,3 +426,9 @@ static av_always_inline av_const int av_popcount64_c(uint64_t x)
 #ifndef av_popcount64
 #   define av_popcount64    av_popcount64_c
 #endif
+
+#ifdef TEST
+#ifdef __MINGW32__
+#undef main /* We don't want SDL to override our main() */
+#endif
+#endif
diff --git a/libavutil/lls.c b/libavutil/lls.c
index dcefc2c..3a20835 100644
--- a/libavutil/lls.c
+++ b/libavutil/lls.c
@@ -120,6 +120,7 @@ double av_evaluate_lls(LLSModel *m, double *param, int order)
 
 #include <stdio.h>
 #include <limits.h>
+#include "common.h"
 #include "lfg.h"
 
 int main(void)
diff --git a/libavutil/md5.c b/libavutil/md5.c
index f8f08f1..87d2a12 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -31,6 +31,7 @@
  */
 
 #include <stdint.h>
+#include "common.h"
 #include "bswap.h"
 #include "intreadwrite.h"
 #include "md5.h"
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 48078e3..c3d6c1e 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -219,6 +219,7 @@ static int set_string_number(void *obj, const AVOption *o, const char *val, void
             read_number(o, dst, NULL, NULL, &intnum);
             if      (cmd == '+') d = intnum | (int64_t)d;
             else if (cmd == '-') d = intnum &~(int64_t)d;
+            else if (buf[0] == '0' && buf[1] == 'x') d = strtoul(buf, NULL, 16);
         } else {
             read_number(o, dst, &num, &den, &intnum);
             if      (cmd == '+') d = notfirst*num*intnum/den + d;
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index c674704..5f1b985 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -31,6 +31,7 @@
 #include <math.h>
 #include <time.h>
 #include <string.h>
+#include "common.h"
 #include "avassert.h"
 #include "timer.h"
 #include "random_seed.h"
diff --git a/libavutil/time.c b/libavutil/time.c
index 27feb0b..7eb6077 100644
--- a/libavutil/time.c
+++ b/libavutil/time.c
@@ -55,15 +55,15 @@ int64_t av_gettime(void)
 
 int av_usleep(unsigned usec)
 {
-#if HAVE_NANOSLEEP
+#if HAVE_SLEEP
+    Sleep(usec / 1000);
+    return 0;
+#elif HAVE_NANOSLEEP
     struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 };
     while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
     return 0;
 #elif HAVE_USLEEP
     return usleep(usec);
-#elif HAVE_SLEEP
-    Sleep(usec / 1000);
-    return 0;
 #else
     return AVERROR(ENOSYS);
 #endif
diff --git a/tests/Makefile b/tests/Makefile
index f1472f3..dfa15fa 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -150,7 +150,7 @@ FATE_UTILS = base64 tiny_psnr
 
 TOOL = ffmpeg
 
-fate:: $(FATE)
+fate test:: $(FATE)
 
 $(FATE) $(FATE_TESTS-no): $(FATE_UTILS:%=tests/%$(HOSTEXESUF))
 	@echo "TEST    $(@:fate-%=%)"
