00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avformat.h"
00023
00024 typedef struct ASSContext{
00025 unsigned int extra_index;
00026 }ASSContext;
00027
00028 static int write_header(AVFormatContext *s)
00029 {
00030 ASSContext *ass = s->priv_data;
00031 AVCodecContext *avctx= s->streams[0]->codec;
00032 uint8_t *last= NULL;
00033
00034 if(s->nb_streams != 1 || avctx->codec_id != AV_CODEC_ID_SSA){
00035 av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
00036 return -1;
00037 }
00038
00039 while(ass->extra_index < avctx->extradata_size){
00040 uint8_t *p = avctx->extradata + ass->extra_index;
00041 uint8_t *end= strchr(p, '\n');
00042 if(!end) end= avctx->extradata + avctx->extradata_size;
00043 else end++;
00044
00045 avio_write(s->pb, p, end-p);
00046 ass->extra_index += end-p;
00047
00048 if(last && !memcmp(last, "[Events]", 8))
00049 break;
00050 last=p;
00051 }
00052
00053 avio_flush(s->pb);
00054
00055 return 0;
00056 }
00057
00058 static int write_packet(AVFormatContext *s, AVPacket *pkt)
00059 {
00060 avio_write(s->pb, pkt->data, pkt->size);
00061
00062 avio_flush(s->pb);
00063
00064 return 0;
00065 }
00066
00067 static int write_trailer(AVFormatContext *s)
00068 {
00069 ASSContext *ass = s->priv_data;
00070 AVCodecContext *avctx= s->streams[0]->codec;
00071
00072 avio_write(s->pb, avctx->extradata + ass->extra_index,
00073 avctx->extradata_size - ass->extra_index);
00074
00075 return 0;
00076 }
00077
00078 AVOutputFormat ff_ass_muxer = {
00079 .name = "ass",
00080 .long_name = NULL_IF_CONFIG_SMALL("SSA (SubStation Alpha) subtitle"),
00081 .mime_type = "text/x-ssa",
00082 .extensions = "ass,ssa",
00083 .priv_data_size = sizeof(ASSContext),
00084 .subtitle_codec = AV_CODEC_ID_SSA,
00085 .write_header = write_header,
00086 .write_packet = write_packet,
00087 .write_trailer = write_trailer,
00088 .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS,
00089 };