diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 832500b..c9d8923 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
+++ b/mythtv/libs/libmythtv/avformatdecoder.cpp
@@ -2029,143 +2029,12 @@ int AvFormatDecoder::ScanStreams(bool novideo)
             continue;
         }
 
-        AVCodec *codec = avcodec_find_decoder(enc->codec_id);
-        if (!codec)
-        {
-            LOG(VB_GENERAL, LOG_ERR, LOC +
-                QString("Could not find decoder for codec (%1), ignoring.")
-                    .arg(ff_codec_id_string(enc->codec_id)));
-
-            // Nigel's bogus codec-debug. Dump the list of codecs & decoders,
-            // and have one last attempt to find a decoder. This is usually
-            // only caused by build problems, where libavcodec needs a rebuild
-            if (VERBOSE_LEVEL_CHECK(VB_LIBAV, LOG_ANY))
-            {
-                AVCodec *p = av_codec_next(NULL);
-                int      i = 1;
-                while (p)
-                {
-                    QString msg;
-
-                    if (p->name[0] != '\0')
-                        msg = QString("Codec %1:").arg(p->name);
-                    else
-                        msg = QString("Codec %1, null name,").arg(i);
-
-                    if (p->decode == NULL)
-                        msg += "decoder is null";
-
-                    LOG(VB_LIBAV, LOG_INFO, LOC + msg);
-
-                    if (p->id == enc->codec_id)
-                    {
-                        codec = p;
-                        break;
-                    }
-
-                    LOG(VB_LIBAV, LOG_INFO, LOC +
-                        QString("Codec 0x%1 != 0x%2") .arg(p->id, 0, 16)
-                            .arg(enc->codec_id, 0, 16));
-                    p = av_codec_next(p);
-                    ++i;
-                }
-            }
-            if (!codec)
-                continue;
-        }
-        // select vdpau capable decoder if needed
-        else if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
-                 codec_is_vdpau(video_codec_id) && !CODEC_IS_VDPAU(codec))
-        {
-            codec = find_vdpau_decoder(codec, enc->codec_id);
-        }
-
-        if (!enc->codec)
+        if (!InitCodec(enc, i,
+                         &lang_sub_cnt, &subtitleStreamCount,
+                         &lang_aud_cnt, &audioStreamCount))
         {
-            QMutexLocker locker(avcodeclock);
-
-            int open_val = avcodec_open2(enc, codec, NULL);
-            if (open_val < 0)
-            {
-                LOG(VB_GENERAL, LOG_ERR, LOC +
-                    QString("Could not open codec 0x%1, id(%2) type(%3) "
-                            "aborting. reason %4").arg((uint64_t)enc,0,16)
-                        .arg(ff_codec_id_string(enc->codec_id))
-                        .arg(ff_codec_type_string(enc->codec_type))
-                        .arg(open_val));
-                //av_close_input_file(ic); // causes segfault
-                ic = NULL;
-                scanerror = -1;
-                break;
-            }
-            else
-            {
-                LOG(VB_GENERAL, LOG_INFO, LOC +
-                    QString("Opened codec 0x%1, id(%2) type(%3)")
-                        .arg((uint64_t)enc,0,16)
-                        .arg(ff_codec_id_string(enc->codec_id))
-                        .arg(ff_codec_type_string(enc->codec_type)));
-            }
-        }
-
-        if (enc->codec_type == AVMEDIA_TYPE_SUBTITLE)
-        {
-            bool forced = ic->streams[i]->disposition & AV_DISPOSITION_FORCED;
-            int lang = GetSubtitleLanguage(subtitleStreamCount, i);
-            int lang_indx = lang_sub_cnt[lang]++;
-            subtitleStreamCount++;
-
-            tracks[kTrackTypeSubtitle].push_back(
-                StreamInfo(i, lang, lang_indx, ic->streams[i]->id, 0, 0, false, false, forced));
-
-            LOG(VB_PLAYBACK, LOG_INFO, LOC +
-                QString("Subtitle track #%1 is A/V stream #%2 "
-                        "and is in the %3 language(%4).")
-                    .arg(tracks[kTrackTypeSubtitle].size()).arg(i)
-                    .arg(iso639_key_toName(lang)).arg(lang));
-        }
-
-        if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
-        {
-            int lang = GetAudioLanguage(audioStreamCount, i);
-            int channels  = ic->streams[i]->codec->channels;
-            int lang_indx = lang_aud_cnt[lang]++;
-            audioStreamCount++;
-            AudioTrackType type = kAudioTypeNormal;
-
-            if (ic->streams[i]->codec->avcodec_dual_language)
-            {
-                tracks[kTrackTypeAudio].push_back(
-                    StreamInfo(i, lang, lang_indx, ic->streams[i]->id, channels,
-                               false, false, false, type));
-                lang_indx = lang_aud_cnt[lang]++;
-                tracks[kTrackTypeAudio].push_back(
-                    StreamInfo(i, lang, lang_indx, ic->streams[i]->id, channels,
-                               true, false, false, type));
-            }
-            else
-            {
-                int logical_stream_id;
-                if (ringBuffer && ringBuffer->IsDVD())
-                {
-                    logical_stream_id =
-                        ringBuffer->DVD()->GetAudioTrackNum(ic->streams[i]->id);
-                    type = (AudioTrackType)(ringBuffer->DVD()->GetAudioTrackType(ic->streams[i]->id));
-                }
-                else
-                    logical_stream_id = ic->streams[i]->id;
-
-                tracks[kTrackTypeAudio].push_back(
-                   StreamInfo(i, lang, lang_indx, logical_stream_id, channels,
-                              false, false, false, type));
-            }
-
-            LOG(VB_AUDIO, LOG_INFO, LOC +
-                QString("Audio Track #%1, with type %2 is A/V stream #%3 "
-                        "and has %4 channels in the %5 language(%6).")
-                    .arg(tracks[kTrackTypeAudio].size()).arg((int)type).arg(i)
-                    .arg(enc->channels)
-                    .arg(iso639_key_toName(lang)).arg(lang));
+            scanerror = -1;
+            break;
         }
     }
 
@@ -2226,6 +2095,157 @@ int AvFormatDecoder::ScanStreams(bool novideo)
     return scanerror;
 }
 
+bool AvFormatDecoder::InitCodec(AVCodecContext *enc, int currentstream,
+                                  map<int,uint> *lang_sub_cnt,
+                                  uint *subtitleStreamCount,
+                                  map<int,uint> *lang_aud_cnt,
+                                  uint *audioStreamCount)
+{
+    AVCodec *codec = avcodec_find_decoder(enc->codec_id);
+    if (!codec)
+    {
+        LOG(VB_GENERAL, LOG_ERR, LOC +
+            QString("Could not find decoder for codec (%1), ignoring.")
+            .arg(ff_codec_id_string(enc->codec_id)));
+
+        // Nigel's bogus codec-debug. Dump the list of codecs & decoders,
+        // and have one last attempt to find a decoder. This is usually
+        // only caused by build problems, where libavcodec needs a rebuild
+        if (VERBOSE_LEVEL_CHECK(VB_LIBAV, LOG_ANY))
+        {
+            AVCodec *p = av_codec_next(NULL);
+            int      i = 1;
+            while (p)
+            {
+                QString msg;
+
+                if (p->name[0] != '\0')
+                    msg = QString("Codec %1:").arg(p->name);
+                else
+                    msg = QString("Codec %1, null name,").arg(i);
+
+                if (p->decode == NULL)
+                    msg += "decoder is null";
+
+                LOG(VB_LIBAV, LOG_INFO, LOC + msg);
+
+                if (p->id == enc->codec_id)
+                {
+                    codec = p;
+                    break;
+                }
+
+                LOG(VB_LIBAV, LOG_INFO, LOC +
+                    QString("Codec 0x%1 != 0x%2") .arg(p->id, 0, 16)
+                    .arg(enc->codec_id, 0, 16));
+                p = av_codec_next(p);
+                ++i;
+            }
+        }
+        if (!codec)
+            return true;
+    }
+    // select vdpau capable decoder if needed
+    else if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
+             codec_is_vdpau(video_codec_id) && !CODEC_IS_VDPAU(codec))
+    {
+        codec = find_vdpau_decoder(codec, enc->codec_id);
+    }
+
+    if (!enc->codec)
+    {
+        QMutexLocker locker(avcodeclock);
+
+        int open_val = avcodec_open2(enc, codec, NULL);
+        if (open_val < 0)
+        {
+            LOG(VB_GENERAL, LOG_ERR, LOC +
+                QString("Could not open codec 0x%1, id(%2) type(%3) "
+                        "aborting. reason %4").arg((uint64_t)enc,0,16)
+                .arg(ff_codec_id_string(enc->codec_id))
+                .arg(ff_codec_type_string(enc->codec_type))
+                .arg(open_val));
+            //av_close_input_file(ic); // causes segfault
+            ic = NULL;
+            return false;
+        }
+        else
+        {
+            LOG(VB_GENERAL, LOG_INFO, LOC +
+                QString("Opened codec 0x%1, id(%2) type(%3)")
+                .arg((uint64_t)enc,0,16)
+                .arg(ff_codec_id_string(enc->codec_id))
+                .arg(ff_codec_type_string(enc->codec_type)));
+        }
+    }
+
+    if (enc->codec_type == AVMEDIA_TYPE_SUBTITLE)
+    {
+        bool forced = ic->streams[currentstream]->disposition & AV_DISPOSITION_FORCED;
+        int lang = GetSubtitleLanguage(*subtitleStreamCount, currentstream);
+        int lang_indx = (*lang_sub_cnt)[lang]++;
+        *subtitleStreamCount++;
+
+        tracks[kTrackTypeSubtitle].push_back(
+            StreamInfo(currentstream, lang, lang_indx,
+                       ic->streams[currentstream]->id, 0,
+                       0, false, false, forced));
+
+        LOG(VB_PLAYBACK, LOG_INFO, LOC +
+            QString("Subtitle track #%1 is A/V stream #%2 "
+                    "and is in the %3 language(%4).")
+            .arg(tracks[kTrackTypeSubtitle].size()).arg(currentstream)
+            .arg(iso639_key_toName(lang)).arg(lang));
+    }
+
+    if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
+    {
+        int lang = GetAudioLanguage(*audioStreamCount, currentstream);
+        int channels  = ic->streams[currentstream]->codec->channels;
+        int lang_indx = (*lang_aud_cnt)[lang]++;
+        *audioStreamCount++;
+        AudioTrackType type = kAudioTypeNormal;
+
+        if (ic->streams[currentstream]->codec->avcodec_dual_language)
+        {
+            tracks[kTrackTypeAudio].push_back(
+                StreamInfo(currentstream, lang, lang_indx,
+                           ic->streams[currentstream]->id, channels,
+                           false, false, false, type));
+            lang_indx = (*lang_aud_cnt)[lang]++;
+            tracks[kTrackTypeAudio].push_back(
+                StreamInfo(currentstream, lang, lang_indx,
+                           ic->streams[currentstream]->id, channels,
+                           true, false, false, type));
+        }
+        else
+        {
+            int logical_stream_id;
+            if (ringBuffer && ringBuffer->IsDVD())
+            {
+                logical_stream_id =
+                    ringBuffer->DVD()->GetAudioTrackNum(ic->streams[currentstream]->id);
+                type =
+                    (AudioTrackType)(ringBuffer->DVD()->GetAudioTrackType(ic->streams[currentstream]->id));
+            }
+            else
+                logical_stream_id = ic->streams[currentstream]->id;
+
+            tracks[kTrackTypeAudio].push_back(
+                StreamInfo(currentstream, lang, lang_indx, logical_stream_id,
+                           channels, false, false, false, type));
+        }
+
+        LOG(VB_AUDIO, LOG_INFO, LOC +
+            QString("Audio Track #%1, with type %2 is A/V stream #%3 "
+                    "and has %4 channels in the %5 language(%6).")
+            .arg(tracks[kTrackTypeAudio].size()).arg((int)type).arg(currentstream)
+            .arg(enc->channels)
+            .arg(iso639_key_toName(lang)).arg(lang));
+    }
+    return true;
+}
+
 void AvFormatDecoder::UpdateFramesPlayed(void)
 {
     return DecoderBase::UpdateFramesPlayed();
@@ -2948,6 +2968,7 @@ bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)
         uint  width  = dim.width();
         uint  height = dim.height();
         float seqFPS = normalized_fps(stream, context);
+        bool waszero = !(width && height && current_width && current_height);
 
         bool changed = (seqFPS > fps+0.01f) || (seqFPS < fps-0.01f);
         changed |= (width  != (uint)current_width );
@@ -2979,6 +3000,18 @@ bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)
                     QString("avFPS(%1) != seqFPS(%2)")
                         .arg(avFPS).arg(seqFPS));
             }
+
+            // FFmpeg HACK:
+            // resolution was changed ; ffmpeg H264 decoder doesn't handle it
+            // properly. So close and re-open decoder
+            if (!waszero)
+            {
+                LOG(VB_PLAYBACK, LOG_INFO, LOC + "resetting H264 decoder");
+                QMutexLocker locker(avcodeclock);
+                if (stream->codec->codec)
+                    avcodec_close(stream->codec);
+                InitCodec(stream->codec);
+            }
         }
 
         HandleGopStart(pkt, true);
diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
index aa3f9d1..0a650db 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.h
+++ b/mythtv/libs/libmythtv/avformatdecoder.h
@@ -105,12 +105,12 @@ class AvFormatDecoder : public DecoderBase
 
     /// Perform an av_probe_input_format on the passed data to see if we
     /// can decode it with this class.
-    static bool CanHandle(char testbuf[kDecoderProbeBufferSize], 
+    static bool CanHandle(char testbuf[kDecoderProbeBufferSize],
                           const QString &filename,
                           int testbufsize = kDecoderProbeBufferSize);
 
     /// Open our file and set up or audio and video parameters.
-    int OpenFile(RingBuffer *rbuffer, bool novideo, 
+    int OpenFile(RingBuffer *rbuffer, bool novideo,
                  char testbuf[kDecoderProbeBufferSize],
                  int testbufsize = kDecoderProbeBufferSize);
 
@@ -152,6 +152,11 @@ class AvFormatDecoder : public DecoderBase
     virtual int SetTrack(uint type, int trackNo);
 
     int ScanStreams(bool novideo);
+    bool InitCodec(AVCodecContext *enc, int currentstream = 0,
+                     map<int,uint> *lang_sub_cnt = NULL,
+                     uint *subtitleStreamCount = NULL,
+                     map<int,uint> *lang_aud_cnt = NULL,
+                     uint *audioStreamCount = NULL);
     int FindStreamInfo(void);
 
     virtual int  GetNumChapters();
