oggenc: return error value from ogg_build_flac_headers()
[FFMpeg-mirror/lagarith.git] / libavformat / assenc.c
blobd1b93e82ef034aade59f374ab21848ea618f3d84
1 /*
2 * SSA/ASS muxer
3 * Copyright (c) 2008 Michael Niedermayer
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
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.
12 * FFmpeg is distributed in the hope that it will be useful,
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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "avformat.h"
24 typedef struct ASSContext{
25 unsigned int extra_index;
26 }ASSContext;
28 static int write_header(AVFormatContext *s)
30 ASSContext *ass = s->priv_data;
31 AVCodecContext *avctx= s->streams[0]->codec;
32 uint8_t *last= NULL;
34 if(s->nb_streams != 1 || avctx->codec_id != CODEC_ID_SSA){
35 av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
36 return -1;
39 while(ass->extra_index < avctx->extradata_size){
40 uint8_t *p = avctx->extradata + ass->extra_index;
41 uint8_t *end= strchr(p, '\n');
42 if(!end) end= avctx->extradata + avctx->extradata_size;
43 else end++;
45 put_buffer(s->pb, p, end-p);
46 ass->extra_index += end-p;
48 if(last && !memcmp(last, "[Events]", 8))
49 break;
50 last=p;
53 put_flush_packet(s->pb);
55 return 0;
58 static int write_packet(AVFormatContext *s, AVPacket *pkt)
60 put_buffer(s->pb, pkt->data, pkt->size);
62 put_flush_packet(s->pb);
64 return 0;
67 static int write_trailer(AVFormatContext *s)
69 ASSContext *ass = s->priv_data;
70 AVCodecContext *avctx= s->streams[0]->codec;
72 put_buffer(s->pb, avctx->extradata + ass->extra_index,
73 avctx->extradata_size - ass->extra_index);
75 put_flush_packet(s->pb);
77 return 0;
80 AVOutputFormat ass_muxer = {
81 "ass",
82 NULL_IF_CONFIG_SMALL("SSA/ASS format"),
83 NULL,
84 "ass,ssa",
85 sizeof(ASSContext),
86 CODEC_ID_NONE,
87 CODEC_ID_NONE,
88 write_header,
89 write_packet,
90 write_trailer,
91 .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS