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 != 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 put_buffer(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 put_flush_packet(s->pb);
00054
00055 return 0;
00056 }
00057
00058 static int write_packet(AVFormatContext *s, AVPacket *pkt)
00059 {
00060 put_buffer(s->pb, pkt->data, pkt->size);
00061
00062 put_flush_packet(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 put_buffer(s->pb, avctx->extradata + ass->extra_index,
00073 avctx->extradata_size - ass->extra_index);
00074
00075 put_flush_packet(s->pb);
00076
00077 return 0;
00078 }
00079
00080 AVOutputFormat ass_muxer = {
00081 "ass",
00082 NULL_IF_CONFIG_SMALL("SSA/ASS format"),
00083 NULL,
00084 "ass,ssa",
00085 sizeof(ASSContext),
00086 CODEC_ID_NONE,
00087 CODEC_ID_NONE,
00088 write_header,
00089 write_packet,
00090 write_trailer,
00091 .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS
00092 };