Reported upstream: https://trac.ffmpeg.org/ticket/3900

Index: ffmpeg-2.4.2/libavformat/mpegtsenc.c
===================================================================
--- ffmpeg-2.4.2.orig/libavformat/mpegtsenc.c	2014-10-05 06:15:43.000000000 +0400
+++ ffmpeg-2.4.2/libavformat/mpegtsenc.c	2014-10-06 14:35:35.275800645 +0400
@@ -1190,27 +1190,31 @@
 
 int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
 {
-    if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
-        if (!st->nb_frames) {
-            av_log(s, AV_LOG_ERROR, "H.264 bitstream malformed, "
-                   "no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it "
-                   "('-bsf:v h264_mp4toannexb' option with ffmpeg)\n");
-            return AVERROR_INVALIDDATA;
-        }
-        av_log(s, AV_LOG_WARNING, "H.264 bitstream error, startcode missing\n");
+    if ((pkt->size > 4 && AV_RB32(pkt->data) == 0x00000001) || (pkt->size >= 4 && AV_RB24(pkt->data) == 0x000001))
+        return 0;
+
+    if (!st->nb_frames) {
+        av_log(s, AV_LOG_ERROR, "H.264 bitstream malformed, "
+               "no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it "
+               "('-bsf:v h264_mp4toannexb' option with ffmpeg)\n");
+        return AVERROR_INVALIDDATA;
     }
+    av_log(s, AV_LOG_WARNING, "H.264 bitstream error, startcode missing\n");
+
     return 0;
 }
 
 static int check_hevc_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
 {
-    if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
-        if (!st->nb_frames) {
-            av_log(s, AV_LOG_ERROR, "HEVC bitstream malformed, no startcode found\n");
-            return AVERROR_PATCHWELCOME;
-        }
-        av_log(s, AV_LOG_WARNING, "HEVC bitstream error, startcode missing\n");
+    if ((pkt->size > 4 && AV_RB32(pkt->data) == 0x00000001) || (pkt->size >= 4 && AV_RB24(pkt->data) == 0x000001))
+        return 0;
+
+    if (!st->nb_frames) {
+        av_log(s, AV_LOG_ERROR, "HEVC bitstream malformed, no startcode found\n");
+        return AVERROR_PATCHWELCOME;
     }
+    av_log(s, AV_LOG_WARNING, "HEVC bitstream error, startcode missing\n");
+
     return 0;
 }
 
