diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c
index 490e6925f5f065c7de239015774dd4af1a4707c0..51ab7ea07c0ae7ef0cbe3d50900458048880cde9 100644
--- a/libavcodec/libspeexdec.c
+++ b/libavcodec/libspeexdec.c
@@ -22,15 +22,16 @@
 #include <speex/speex_header.h>
 #include <speex/speex_stereo.h>
 #include <speex/speex_callbacks.h>
-#include "avcodec.h"
+
+#include "libavutil/audioconvert.h"
 #include "libavutil/common.h"
+#include "avcodec.h"
 
 typedef struct {
     AVFrame frame;
     SpeexBits bits;
     SpeexStereoState stereo;
     void *dec_state;
-    SpeexHeader *header;
     int frame_size;
 } LibSpeexContext;
 
@@ -39,16 +40,20 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
 {
     LibSpeexContext *s = avctx->priv_data;
     const SpeexMode *mode;
+    SpeexHeader *header = NULL;
     int spx_mode;
 
-    if (avctx->extradata_size >= 80)
-        s->header = speex_packet_to_header(avctx->extradata, avctx->extradata_size);
-
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
-    if (s->header) {
-        avctx->channels    = s->header->nb_channels;
-        s->frame_size      = s->header->frame_size;
-        spx_mode           = s->header->mode;
+    if (avctx->extradata && avctx->extradata_size >= 80) {
+        header = speex_packet_to_header(avctx->extradata,
+                                        avctx->extradata_size);
+        if (!header)
+            av_log(avctx, AV_LOG_WARNING, "Invalid Speex header\n");
+    }
+    if (header) {
+        avctx->channels    = header->nb_channels;
+        spx_mode           = header->mode;
+        speex_header_free(header);
     } else {
         switch (avctx->sample_rate) {
         case 8000:  spx_mode = 0; break;
@@ -69,6 +74,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
     avctx->sample_rate = 8000 << spx_mode;
+    s->frame_size      =  160 << spx_mode;
 
     if (avctx->channels < 1 || avctx->channels > 2) {
         /* libspeex can handle mono or stereo if initialized as stereo */
@@ -76,6 +82,8 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
                                     "Decoding as stereo.\n", avctx->channels);
         avctx->channels = 2;
     }
+    avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
+                                                   AV_CH_LAYOUT_MONO;
 
     speex_bits_init(&s->bits);
     s->dec_state = speex_decoder_init(mode);
@@ -84,10 +92,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    if (!s->header) {
-        speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &s->frame_size);
-    }
-
     if (avctx->channels == 2) {
         SpeexCallback callback;
         callback.callback_id = SPEEX_INBAND_STEREO;
@@ -120,10 +124,12 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
     }
     output = (int16_t *)s->frame.data[0];
 
-    /* if there is not enough data left for the smallest possible frame,
-       reset the libspeex buffer using the current packet, otherwise ignore
-       the current packet and keep decoding frames from the libspeex buffer. */
-    if (speex_bits_remaining(&s->bits) < 43) {
+    /* if there is not enough data left for the smallest possible frame or the
+       next 5 bits are a terminator code, reset the libspeex buffer using the
+       current packet, otherwise ignore the current packet and keep decoding
+       frames from the libspeex buffer. */
+    if (speex_bits_remaining(&s->bits) < 5 ||
+        speex_bits_peek_unsigned(&s->bits, 5) == 0x1F) {
         /* check for flush packet */
         if (!buf || !buf_size) {
             *got_frame_ptr = 0;
@@ -153,7 +159,6 @@ static av_cold int libspeex_decode_close(AVCodecContext *avctx)
 {
     LibSpeexContext *s = avctx->priv_data;
 
-    speex_header_free(s->header);
     speex_bits_destroy(&s->bits);
     speex_decoder_destroy(s->dec_state);
 
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 461ecaf88f3b63fdff61995476e98a5755ea805f..f4cc0f26520f2ff7ab916c172b82f0eb9f062202 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -531,6 +531,7 @@ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
 int ff_mpeg_update_thread_context(AVCodecContext *dst,
                                   const AVCodecContext *src)
 {
+    int i;
     MpegEncContext *s = dst->priv_data, *s1 = src->priv_data;
 
     if (dst == src)
@@ -574,6 +575,10 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
     memcpy(&s->last_picture, &s1->last_picture,
            (char *) &s1->last_picture_ptr - (char *) &s1->last_picture);
 
+    // reset s->picture[].f.extended_data to s->picture[].f.data
+    for (i = 0; i < s->picture_count; i++)
+        s->picture[i].f.extended_data = s->picture[i].f.data;
+
     s->last_picture_ptr    = REBASE_PICTURE(s1->last_picture_ptr,    s, s1);
     s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
     s->next_picture_ptr    = REBASE_PICTURE(s1->next_picture_ptr,    s, s1);
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 7e5e6d0b6ff8dd4be5a24159e8738aa781da6b1b..c4bdcb78a6e8abae5950a1a86a694ca13a8bd93a 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -276,24 +276,10 @@ fail:
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
-    int exact;
-    // common timebase computation:
-    AVRational tb1 = ctx->inputs[MAIN   ]->time_base;
-    AVRational tb2 = ctx->inputs[OVERLAY]->time_base;
-    AVRational *tb = &ctx->outputs[0]->time_base;
-    exact = av_reduce(&tb->num, &tb->den,
-                      av_gcd((int64_t)tb1.num * tb2.den,
-                             (int64_t)tb2.num * tb1.den),
-                      (int64_t)tb1.den * tb2.den, INT_MAX);
-    av_log(ctx, AV_LOG_VERBOSE,
-           "main_tb:%d/%d overlay_tb:%d/%d -> tb:%d/%d exact:%d\n",
-           tb1.num, tb1.den, tb2.num, tb2.den, tb->num, tb->den, exact);
-    if (!exact)
-        av_log(ctx, AV_LOG_WARNING,
-               "Timestamp conversion inexact, timestamp information loss may occurr\n");
 
     outlink->w = ctx->inputs[MAIN]->w;
     outlink->h = ctx->inputs[MAIN]->h;
+    outlink->time_base = ctx->inputs[MAIN]->time_base;
 
     return 0;
 }
@@ -448,7 +434,8 @@ static int try_start_frame(AVFilterContext *ctx, AVFilterBufferRef *mainpic)
      * before the main frame, we can drop the current overlay. */
     while (1) {
         next_overpic = ff_bufqueue_peek(&over->queue_over, 0);
-        if (!next_overpic || next_overpic->pts > mainpic->pts)
+        if (!next_overpic || av_compare_ts(next_overpic->pts, ctx->inputs[OVERLAY]->time_base,
+                                           mainpic->pts     , ctx->inputs[MAIN]->time_base) > 0)
             break;
         ff_bufqueue_get(&over->queue_over);
         avfilter_unref_buffer(over->overpicref);
@@ -457,7 +444,8 @@ static int try_start_frame(AVFilterContext *ctx, AVFilterBufferRef *mainpic)
     /* If there is no next frame and no EOF and the overlay frame is before
      * the main frame, we can not know yet if it will be superseded. */
     if (!over->queue_over.available && !over->overlay_eof &&
-        (!over->overpicref || over->overpicref->pts < mainpic->pts))
+        (!over->overpicref || av_compare_ts(over->overpicref->pts, ctx->inputs[OVERLAY]->time_base,
+                                            mainpic->pts         , ctx->inputs[MAIN]->time_base) < 0))
         return AVERROR(EAGAIN);
     /* At this point, we know that the current overlay frame extends to the
      * time of the main frame. */
@@ -525,8 +513,6 @@ static int start_frame_main(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 
     if ((ret = flush_frames(ctx)) < 0)
         return ret;
-    inpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[MAIN]->time_base,
-                                 ctx->outputs[0]->time_base);
     if ((ret = try_start_frame(ctx, inpicref)) < 0) {
         if (ret != AVERROR(EAGAIN))
             return ret;
@@ -583,8 +569,6 @@ static int end_frame_over(AVFilterLink *inlink)
 
     if ((ret = flush_frames(ctx)) < 0)
         return ret;
-    inpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[OVERLAY]->time_base,
-                                 ctx->outputs[0]->time_base);
     ff_bufqueue_add(ctx, &over->queue_over, inpicref);
     ret = try_push_frame(ctx);
     return ret == AVERROR(EAGAIN) ? 0 : ret;
diff --git a/libavformat/h264dec.c b/libavformat/h264dec.c
index 7e525e0bc95363993cd390c60cb28d3bc65695f1..9c67ab9545d814c0460114db10d31b2235cfe17e 100644
--- a/libavformat/h264dec.c
+++ b/libavformat/h264dec.c
@@ -54,7 +54,7 @@ static int h264_probe(AVProbeData *p)
             case     1:   sli++; break;
             case     5:   idr++; break;
             case     7:
-                if(p->buf[i+2]&0x03)
+                if (p->buf[i + 2] & 0x03)
                     return 0;
                 sps++;
                 break;
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index a03648e200e8e986e01be8b661effadf1eae50db..96cc5fb24ccc037089ccf37184385985aa8d7273 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -183,7 +183,7 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
     if (size < 0)
         return size;
 
-    buf = av_mallocz(size);
+    buf = av_malloc(size);
     if (!buf)
         return AVERROR(ENOMEM);
 
@@ -193,6 +193,9 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
         av_free(buf);
         return size;
     }
+
+    av_samples_set_silence(audio_data, 0, nb_samples, nb_channels, sample_fmt);
+
     return 0;
 }
 
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index 2a7de202afed38f435c34b3b2113ff3bec2b2548..17300d1e95dcb9542af6439eb5481cb873003266 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -194,6 +194,7 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
  * Allocate a samples buffer for nb_samples samples, and fill data pointers and
  * linesize accordingly.
  * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
+ * Allocated data will be initialized to silence.
  *
  * @see enum AVSampleFormat
  * The documentation for AVSampleFormat describes the data layout.
diff --git a/libavutil/version.h b/libavutil/version.h
index 3361069bdfdbee5662d996cab942e4f6cd325099..501d3cd2f55a32e9fcffbf5176f849d89ccf3636 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -40,7 +40,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR 51
 #define LIBAVUTIL_VERSION_MINOR 73
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MICRO 102
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \