configure: Drop unused helper function test_cflags_cpp()
[libav.git] / libavformat / assenc.c
CommitLineData
88caf345
MN
1/*
2 * SSA/ASS muxer
3 * Copyright (c) 2008 Michael Niedermayer
4 *
2912e87a 5 * This file is part of Libav.
88caf345 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
88caf345
MN
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
88caf345
MN
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
2912e87a 18 * License along with Libav; if not, write to the Free Software
88caf345
MN
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "avformat.h"
23
24typedef struct ASSContext{
25 unsigned int extra_index;
26}ASSContext;
27
28static int write_header(AVFormatContext *s)
29{
30 ASSContext *ass = s->priv_data;
9200514a 31 AVCodecParameters *par = s->streams[0]->codecpar;
88caf345
MN
32 uint8_t *last= NULL;
33
9200514a 34 if(s->nb_streams != 1 || par->codec_id != AV_CODEC_ID_SSA){
88caf345
MN
35 av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
36 return -1;
37 }
38
9200514a
AK
39 while(ass->extra_index < par->extradata_size){
40 uint8_t *p = par->extradata + ass->extra_index;
88caf345 41 uint8_t *end= strchr(p, '\n');
9200514a 42 if(!end) end= par->extradata + par->extradata_size;
88caf345
MN
43 else end++;
44
77eb5504 45 avio_write(s->pb, p, end-p);
88caf345
MN
46 ass->extra_index += end-p;
47
48 if(last && !memcmp(last, "[Events]", 8))
49 break;
50 last=p;
51 }
52
b7f2fdde 53 avio_flush(s->pb);
88caf345
MN
54
55 return 0;
56}
57
58static int write_packet(AVFormatContext *s, AVPacket *pkt)
59{
77eb5504 60 avio_write(s->pb, pkt->data, pkt->size);
88caf345
MN
61 return 0;
62}
63
64static int write_trailer(AVFormatContext *s)
65{
66 ASSContext *ass = s->priv_data;
9200514a 67 AVCodecParameters *par = s->streams[0]->codecpar;
88caf345 68
9200514a
AK
69 avio_write(s->pb, par->extradata + ass->extra_index,
70 par->extradata_size - ass->extra_index);
88caf345 71
88caf345
MN
72 return 0;
73}
74
c6610a21 75AVOutputFormat ff_ass_muxer = {
87d69d32 76 .name = "ass",
0177b7d2 77 .long_name = NULL_IF_CONFIG_SMALL("SSA (SubStation Alpha) subtitle"),
87d69d32
AJ
78 .mime_type = "text/x-ssa",
79 .extensions = "ass,ssa",
80 .priv_data_size = sizeof(ASSContext),
36ef5369 81 .subtitle_codec = AV_CODEC_ID_SSA,
87d69d32
AJ
82 .write_header = write_header,
83 .write_packet = write_packet,
84 .write_trailer = write_trailer,
908dc2a0 85 .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS,
88caf345 86};