diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 9e67ee5c618b1b24add4ca89df2370574e5cff4d..b353b88f4c6f52711238644e7b5c8d5affde396f 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -2196,7 +2196,7 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
  * Finds the end of the current frame in the bitstream.
  * @return the position of the first byte of the next frame, or -1
  */
-int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
+int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)
 {
     int i;
     uint32_t state= pc->state;
@@ -2244,6 +2244,9 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
                     return i-3;
                 }
             }
+            if(s && state == PICTURE_START_CODE){
+                ff_fetch_timestamp(s, i-4, 1);
+            }
         }
     }
     pc->state= state;
@@ -2276,7 +2279,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
     }
 
     if(s2->flags&CODEC_FLAG_TRUNCATED){
-        int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size);
+        int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL);
 
         if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
             return buf_size;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 5620f1edab3a3c0e433a9c2ac9f917076e44ea8c..ef40083e90c525c1c66383ab784a377de5247c8a 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -769,7 +769,7 @@ void mpeg1_encode_mb(MpegEncContext *s,
 void ff_mpeg1_encode_init(MpegEncContext *s);
 void ff_mpeg1_encode_slice_header(MpegEncContext *s);
 void ff_mpeg1_clean_buffers(MpegEncContext *s);
-int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size);
+int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s);
 
 extern const uint8_t ff_mpeg4_y_dc_scale_table[32];
 extern const uint8_t ff_mpeg4_c_dc_scale_table[32];
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 2ccb9fff2c7072b64417a4984e11d6737648cb22..215c86c4001b1e23269f6fbf04a4e7fbe78ae4d0 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -29,7 +29,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
 {
     ParseContext1 *pc = s->priv_data;
     const uint8_t *buf_end;
-    const uint8_t *buf_start= buf;
     uint32_t start_code;
     int frame_rate_index, ext_type, bytes_left;
     int frame_rate_ext_n, frame_rate_ext_d;
@@ -44,8 +43,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
         bytes_left = buf_end - buf;
         switch(start_code) {
         case PICTURE_START_CODE:
-            ff_fetch_timestamp(s, buf-buf_start-4, 1);
-
             if (bytes_left >= 2) {
                 s->pict_type = (buf[1] >> 3) & 7;
             }
@@ -137,7 +134,7 @@ static int mpegvideo_parse(AVCodecParserContext *s,
     if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
         next= buf_size;
     }else{
-        next= ff_mpeg1_find_frame_end(pc, buf, buf_size);
+        next= ff_mpeg1_find_frame_end(pc, buf, buf_size, s);
 
         if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
             *poutbuf = NULL;
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index d738a62b83c2d68526274717f63a29f2a9ece98e..c0a0095309335f226f665163a06645962d1235d3 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -87,7 +87,7 @@ void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove){
     s->dts= s->pts= AV_NOPTS_VALUE;
     s->offset= 0;
     for(i = 0; i < AV_PARSER_PTS_NB; i++) {
-        if (   s->next_frame_offset + off >= s->cur_frame_offset[i]
+        if (   s->cur_offset + off >= s->cur_frame_offset[i]
             &&(s->     frame_offset       <  s->cur_frame_offset[i] || !s->frame_offset)
             //check is disabled  becausue mpeg-ts doesnt send complete PES packets
             && /*s->next_frame_offset + off <*/  s->cur_frame_end[i]){