[FFmpeg-cvslog] avformat/mpegtsenc: Do not create invalid files from annex b streams without SPS/PPS
Michael Niedermayer
git at videolan.org
Thu Feb 12 23:22:40 CET 2015
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Feb 12 22:31:47 2015 +0100| [33650e0e42d6e8e0daf5e403e317a2ce0bf36acb] | committer: Michael Niedermayer
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 at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=33650e0e42d6e8e0daf5e403e317a2ce0bf36acb
---
libavformat/mpegtsenc.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 8a7b29d..a56ca0e 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) {
More information about the ffmpeg-cvslog
mailing list