diff options
author | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2010-03-09 00:18:49 +0000 |
---|---|---|
committer | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2010-03-09 00:18:49 +0000 |
commit | 8fdd542ce4c357d38b4601e9a327f499c9a096f1 (patch) | |
tree | 185be31d52cf63791037dbaa3963fd1764000d24 /libavformat/mpegtsenc.c | |
parent | e17d77bb674879505f9f438e610441e1834fb908 (diff) | |
download | ffmpeg-8fdd542ce4c357d38b4601e9a327f499c9a096f1.tar.gz |
In mpegts muxer, write adts header if aac bitstream does not contain it
Originally committed as revision 22355 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/mpegtsenc.c')
-rw-r--r-- | libavformat/mpegtsenc.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 64e6fddcf0..b818964e21 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -24,6 +24,7 @@ #include "libavcodec/mpegvideo.h" #include "avformat.h" #include "mpegts.h" +#include "adts.h" /* write DVB SI sections */ @@ -177,6 +178,7 @@ typedef struct MpegTSWriteStream { int64_t payload_pts; int64_t payload_dts; uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE]; + ADTSContext *adts; } MpegTSWriteStream; static void mpegts_write_pat(AVFormatContext *s) @@ -427,6 +429,15 @@ static int mpegts_write_header(AVFormatContext *s) service->pcr_pid = ts_st->pid; pcr_st = st; } + if (st->codec->codec_id == CODEC_ID_AAC && + st->codec->extradata_size > 0) { + ts_st->adts = av_mallocz(sizeof(*ts_st->adts)); + if (!ts_st->adts) + return AVERROR_NOMEM; + if (ff_adts_decode_extradata(s, ts_st->adts, st->codec->extradata, + st->codec->extradata_size) < 0) + return -1; + } } /* if no video stream, use the first stream as PCR */ @@ -809,6 +820,32 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) buf = data; size = pkt->size+6; } + } else if (st->codec->codec_id == CODEC_ID_AAC) { + if (pkt->size < 2) + return -1; + if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) { + ADTSContext *adts = ts_st->adts; + int new_size; + if (!adts) { + av_log(s, AV_LOG_ERROR, "aac bitstream not in adts format " + "and extradata missing\n"); + return -1; + } + new_size = ADTS_HEADER_SIZE+adts->pce_size+pkt->size; + if ((unsigned)new_size >= INT_MAX) + return -1; + data = av_malloc(new_size); + if (!data) + return AVERROR_NOMEM; + ff_adts_write_frame_header(adts, data, pkt->size, adts->pce_size); + if (adts->pce_size) { + memcpy(data+ADTS_HEADER_SIZE, adts->pce_data, adts->pce_size); + adts->pce_size = 0; + } + memcpy(data+ADTS_HEADER_SIZE+adts->pce_size, pkt->data, pkt->size); + buf = data; + size = new_size; + } } if (st->codec->codec_type != CODEC_TYPE_AUDIO) { |