3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
5 * This file is part of Libav.
7 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/avstring.h"
25 static av_cold int ass_encode_init(AVCodecContext *avctx)
27 avctx->extradata = av_malloc(avctx->subtitle_header_size);
28 if (!avctx->extradata)
29 return AVERROR(ENOMEM);
30 memcpy(avctx->extradata, avctx->subtitle_header, avctx->subtitle_header_size);
31 avctx->extradata_size = avctx->subtitle_header_size;
35 static int ass_encode_frame(AVCodecContext *avctx,
36 unsigned char *buf, int bufsize, void *data)
38 AVSubtitle *sub = data;
39 int i, len, total_len = 0;
41 for (i=0; i<sub->num_rects; i++) {
42 if (sub->rects[i]->type != SUBTITLE_ASS) {
43 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
47 len = av_strlcpy(buf+total_len, sub->rects[i]->ass, bufsize-total_len);
49 if (len > bufsize-total_len-1) {
50 av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
60 AVCodec ff_ass_encoder = {
62 .long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
63 .type = AVMEDIA_TYPE_SUBTITLE,
65 .init = ass_encode_init,
66 .encode = ass_encode_frame,