diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2015-02-12 22:31:47 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-02-12 23:13:15 +0100 |
commit | 33650e0e42d6e8e0daf5e403e317a2ce0bf36acb (patch) | |
tree | e50e27d71483ebd8d4dd8fa365a101327b8bbca4 | |
parent | b6f577dbb2afde4111a1820435ab2c5afbf78e12 (diff) | |
download | ffmpeg-33650e0e42d6e8e0daf5e403e317a2ce0bf36acb.tar.gz |
avformat/mpegtsenc: Do not create invalid files from annex b streams without SPS/PPS
use global headers to create SPS/PPS when they are available
Fixes Ticket4248
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/mpegtsenc.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 8a7b29d45c..a56ca0eaa5 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1270,26 +1270,35 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) if (st->codec->codec_id == AV_CODEC_ID_H264) { const uint8_t *p = buf, *buf_end = p + size; uint32_t state = -1; + int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codec->extradata_size : 0; int ret = ff_check_h264_startcode(s, st, pkt); if (ret < 0) return ret; + if (extradd && AV_RB24(st->codec->extradata) > 1) + extradd = 0; + do { p = avpriv_find_start_code(p, buf_end, &state); av_dlog(s, "nal %d\n", state & 0x1f); + if ((state & 0x1f) == 7) + extradd = 0; } while (p < buf_end && (state & 0x1f) != 9 && (state & 0x1f) != 5 && (state & 0x1f) != 1); + if ((state & 0x1f) != 5) + extradd = 0; if ((state & 0x1f) != 9) { // AUD NAL - data = av_malloc(pkt->size + 6); + data = av_malloc(pkt->size + 6 + extradd); if (!data) return AVERROR(ENOMEM); - memcpy(data + 6, pkt->data, pkt->size); + memcpy(data + 6, st->codec->extradata, extradd); + memcpy(data + 6 + extradd, pkt->data, pkt->size); AV_WB32(data, 0x00000001); data[4] = 0x09; data[5] = 0xf0; // any slice type (0xe) + rbsp stop one bit buf = data; - size = pkt->size + 6; + size = pkt->size + 6 + extradd; } } else if (st->codec->codec_id == AV_CODEC_ID_AAC) { if (pkt->size < 2) { |