Index: libs/libmythtv/dtvrecorder.cpp
===================================================================
--- libs/libmythtv/dtvrecorder.cpp	(revision 17644)
+++ libs/libmythtv/dtvrecorder.cpp	(working copy)
@@ -532,8 +532,7 @@
                 hasKeyFrame = true;
                 hasFrame = true;
             }
-
-            if (_h264_kf_seq.IsOnFrame())
+            else if (_h264_kf_seq.IsOnFrame())
                 hasFrame = true;
         }
     } // for (; i < TSPacket::SIZE; i++)
Index: libs/libmythtv/mpeg/h264utils.h
===================================================================
--- libs/libmythtv/mpeg/h264utils.h	(revision 17644)
+++ libs/libmythtv/mpeg/h264utils.h	(working copy)
@@ -35,6 +35,10 @@
 
 #include <stdint.h>
 
+extern "C" {
+#include "golomb.h"
+}
+
 namespace H264
 {
 
@@ -174,6 +178,8 @@
 
   private:
     void KeyframePredicate(const uint8_t new_first_NAL_byte); /* throw() */
+    void decode_Header(GetBitContext * gb);
+    void decode_SPS(GetBitContext * gb);
 
     bool    errored;
     bool    state_changed;
@@ -182,14 +188,19 @@
     int64_t  sync_stream_offset;
 
     uint8_t first_NAL_byte;
+    int     log2_max_frame_num;
+    int     frame_num, prev_frame_num;
 
     bool    saw_AU_delimiter;
     bool    saw_first_VCL_NAL_unit;
     bool    saw_sps;
+    bool    separate_colour_plane_flag;
 
     bool    did_evaluate_once;
     bool    keyframe;
     int64_t keyframe_sync_stream_offset;
+
+    GetBitContext gb;
 };
 
 } // namespace H264
Index: libs/libmythtv/mpeg/h264utils.cpp
===================================================================
--- libs/libmythtv/mpeg/h264utils.cpp	(revision 17644)
+++ libs/libmythtv/mpeg/h264utils.cpp	(working copy)
@@ -42,6 +42,7 @@
 extern "C" {
 // from libavcodec
 extern const uint8_t *ff_find_start_code(const uint8_t * p, const uint8_t *end, uint32_t * state);
+#include "avcodec.h"
 }
 
 namespace H264
@@ -62,9 +63,14 @@
 
     first_NAL_byte = H264::NALUnitType::UNKNOWN;
 
+    log2_max_frame_num = -1;
+    frame_num = 0;
+    prev_frame_num = -1;
+
     saw_AU_delimiter = false;
     saw_first_VCL_NAL_unit = false;
     saw_sps = false;
+    separate_colour_plane_flag = false;
 
     did_evaluate_once = false;
     keyframe = false;
@@ -154,12 +160,35 @@
         if ((sync_accumulator & 0xffffff00) == 0x00000100)
         {
             uint8_t k = *(local_bytes-1);
+            uint8_t NAL_type = k & 0x1f;
             sync_stream_offset = stream_offset;
             keyframe = false;
 
             KeyframePredicate(k);
             first_NAL_byte = k;
 
+            if (NAL_type == NALUnitType::SPS ||
+                NAL_type == NALUnitType::SLICE ||
+                NAL_type == NALUnitType::SLICE_DPA) {
+            /*
+              bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE
+              bytes larger then the actual read bits
+            */
+                if (local_bytes + 20 + FF_INPUT_BUFFER_PADDING_SIZE <
+                    local_bytes_end) {
+                    init_get_bits(&gb, local_bytes,
+                                  8 * (local_bytes_end - local_bytes));
+                    
+                    if (NAL_type == NALUnitType::SPS)
+                        decode_SPS(&gb);
+                    else
+                        decode_Header(&gb);
+                }
+                
+            }
+            else if (NAL_type == NALUnitType::SLICE_IDR)
+                frame_num = 0;
+
             return local_bytes - bytes;
         }
     }
@@ -175,4 +204,66 @@
     return saw_first_VCL_NAL_unit;
 }
 
+void KeyframeSequencer::decode_Header(GetBitContext * gb)
+{
+    uint first_mb_in_slice;
+    uint slice_type;
+    uint pic_parameter_set_id;
+    
+    if (log2_max_frame_num < 1)
+    {
+        std::cerr
+            << "KeyframeSequencer::decode_Header: SPS has not been parsed!\n";
+        return;
+    }
+
+    prev_frame_num = frame_num;
+
+    first_mb_in_slice = get_ue_golomb(gb);
+    slice_type = get_ue_golomb(gb);
+    pic_parameter_set_id = get_ue_golomb(gb);
+    
+    if (separate_colour_plane_flag)
+        get_bits(gb, 2);  // colour_plane_id
+    
+    frame_num = get_bits(gb, log2_max_frame_num);
+}
+
+/*
+ * Just the parts we need -- libavcodec used for example
+ */
+void KeyframeSequencer::decode_SPS(GetBitContext * gb)
+{
+    int profile_idc, chroma_format_idc;
+    int idx;
+
+    profile_idc = get_bits(gb, 8); // profile_idc
+    get_bits1(gb);   // constraint_set0_flag
+    get_bits1(gb);   // constraint_set1_flag
+    get_bits1(gb);   // constraint_set2_flag
+    get_bits1(gb);   // constraint_set3_flag
+    get_bits(gb, 4); // reserved
+    get_bits(gb, 8); // level_idc
+    get_ue_golomb(gb);  // sps_id
+
+    if(profile_idc >= 100){ // high profile
+        if((chroma_format_idc = get_ue_golomb(gb)) == 3) // chroma_format_idc
+            separate_colour_plane_flag = (get_bits1(gb) == 1);
+        get_ue_golomb(gb);  // bit_depth_luma_minus8
+        get_ue_golomb(gb);  // bit_depth_chroma_minus8
+        get_bits1(gb);      // qpprime_y_zero_transform_bypass_flag
+
+        if (get_bits1(gb))      // seq_scaling_matrix_present_flag
+        {
+            for (idx = 0; idx < ((chroma_format_idc != 3) ? 8 : 12); ++idx)
+            {
+                get_bits1(gb);  // scaling_list
+            }
+        }
+    }
+
+    log2_max_frame_num = get_ue_golomb(gb) + 4;
+}
+
 } // namespace H264
+
