[FFmpeg-devel] [PATCH]Do not mux invalid hevc into transport streams
Carl Eugen Hoyos
cehoyos at ag.or.at
Thu Aug 7 10:23:38 CEST 2014
Hi!
Attached patch checks if the hevc stream contains a startcode when muxed into
transport streams.
Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index c286249..4259318 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1157,6 +1157,18 @@ int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPack
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");
+ }
+ return 0;
+}
+
static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
{
AVStream *st = s->streams[pkt->stream_index];
@@ -1252,6 +1264,10 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
ts_st->amux->pb = NULL;
buf = data;
}
+ } else if (st->codec->codec_id == AV_CODEC_ID_HEVC) {
+ int ret = check_hevc_startcode(s, st, pkt);
+ if (ret < 0)
+ return ret;
}
if (pkt->dts != AV_NOPTS_VALUE) {
More information about the ffmpeg-devel
mailing list