[FFmpeg-devel] [PATCH]Only test the first frame for malformed bitstreams
Carl Eugen Hoyos
cehoyos at ag.or.at
Mon Mar 25 00:03:25 CET 2013
Hi!
Currently, the mpegts, the flv and the mov muxer test every h264 / aac frame
for a missing bitstream filter, making remuxing of broken streams impossible.
Testing only the first frame should be sufficient to inform the user of a
missing bitstream filter.
Attached patches fix tickets #1758 and #2380, I tested the remuxed files
successfully with WMP and QT.
Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 7016774..617b9a7 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1093,7 +1093,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
const uint8_t *p = buf, *buf_end = p+size;
uint32_t state = -1;
- if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
+ if (!st->codec->frame_number && (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001)) {
av_log(s, AV_LOG_ERROR, "H.264 bitstream malformed, "
"no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)\n");
return AVERROR(EINVAL);
-------------- next part --------------
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 502da0f..c09df48 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -491,7 +491,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1)
if ((ret = ff_avc_parse_nal_units_buf(pkt->data, &data, &size)) < 0)
return ret;
- } else if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
+ } else if (!enc->frame_number && enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
(AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
av_log(s, AV_LOG_ERROR, "Malformed AAC bitstream detected: "
"use audio bitstream filter 'aac_adtstoasc' to fix it "
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 42496b5..b609e26 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3183,7 +3183,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
} else {
size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
}
- } else if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
+ } else if (!enc->frame_number && enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
(AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n");
return -1;
More information about the ffmpeg-devel
mailing list