mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/assenc: mux all extradata at once
Before this commit, the code was muxing up to the 2nd line after "[Events]" (assuming it to be the "Format:" line). The remaining are generally "Comment:" directives which can stay in that place. mkvextract behaves that way so it seems there is no reason for that extra complexity.
This commit is contained in:
parent
e60770679b
commit
08e2b0da2c
|
@ -30,7 +30,6 @@ typedef struct DialogueLine {
|
||||||
} DialogueLine;
|
} DialogueLine;
|
||||||
|
|
||||||
typedef struct ASSContext{
|
typedef struct ASSContext{
|
||||||
unsigned int extra_index;
|
|
||||||
int write_ts; // 0: ssa (timing in payload), 1: ass (matroska like)
|
int write_ts; // 0: ssa (timing in payload), 1: ass (matroska like)
|
||||||
int expected_readorder;
|
int expected_readorder;
|
||||||
DialogueLine *dialogue_cache;
|
DialogueLine *dialogue_cache;
|
||||||
|
@ -42,7 +41,6 @@ static int write_header(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
ASSContext *ass = s->priv_data;
|
ASSContext *ass = s->priv_data;
|
||||||
AVCodecContext *avctx= s->streams[0]->codec;
|
AVCodecContext *avctx= s->streams[0]->codec;
|
||||||
uint8_t *last= NULL;
|
|
||||||
|
|
||||||
if (s->nb_streams != 1 || (avctx->codec_id != AV_CODEC_ID_SSA &&
|
if (s->nb_streams != 1 || (avctx->codec_id != AV_CODEC_ID_SSA &&
|
||||||
avctx->codec_id != AV_CODEC_ID_ASS)) {
|
avctx->codec_id != AV_CODEC_ID_ASS)) {
|
||||||
|
@ -51,21 +49,11 @@ static int write_header(AVFormatContext *s)
|
||||||
}
|
}
|
||||||
ass->write_ts = avctx->codec_id == AV_CODEC_ID_ASS;
|
ass->write_ts = avctx->codec_id == AV_CODEC_ID_ASS;
|
||||||
avpriv_set_pts_info(s->streams[0], 64, 1, 100);
|
avpriv_set_pts_info(s->streams[0], 64, 1, 100);
|
||||||
|
if (avctx->extradata_size > 0) {
|
||||||
while(ass->extra_index < avctx->extradata_size){
|
avio_write(s->pb, avctx->extradata, avctx->extradata_size);
|
||||||
uint8_t *p = avctx->extradata + ass->extra_index;
|
if (avctx->extradata[avctx->extradata_size - 1] != '\n')
|
||||||
uint8_t *end= strchr(p, '\n');
|
avio_write(s->pb, "\r\n", 2);
|
||||||
if(!end) end= avctx->extradata + avctx->extradata_size;
|
|
||||||
else end++;
|
|
||||||
|
|
||||||
avio_write(s->pb, p, end-p);
|
|
||||||
ass->extra_index += end-p;
|
|
||||||
|
|
||||||
if(last && !memcmp(last, "[Events]", 8))
|
|
||||||
break;
|
|
||||||
last=p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
avio_flush(s->pb);
|
avio_flush(s->pb);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -191,13 +179,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
|
|
||||||
static int write_trailer(AVFormatContext *s)
|
static int write_trailer(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
ASSContext *ass = s->priv_data;
|
|
||||||
AVCodecContext *avctx= s->streams[0]->codec;
|
|
||||||
|
|
||||||
purge_dialogues(s, 1);
|
purge_dialogues(s, 1);
|
||||||
avio_write(s->pb, avctx->extradata + ass->extra_index,
|
|
||||||
avctx->extradata_size - ass->extra_index);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue