3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
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
26 #include "libavutil/avstring.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/mem.h"
30 static av_cold int ass_encode_init(AVCodecContext *avctx)
32 avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
33 if (!avctx->extradata)
34 return AVERROR(ENOMEM);
35 memcpy(avctx->extradata, avctx->subtitle_header, avctx->subtitle_header_size);
36 avctx->extradata_size = avctx->subtitle_header_size;
37 avctx->extradata[avctx->extradata_size] = 0;
41 static int ass_encode_frame(AVCodecContext *avctx,
42 unsigned char *buf, int bufsize,
43 const AVSubtitle *sub)
45 int i, len, total_len = 0;
47 for (i=0; i<sub->num_rects; i++) {
48 const char *ass = sub->rects[i]->ass;
50 if (sub->rects[i]->type != SUBTITLE_ASS) {
51 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
52 return AVERROR(EINVAL);
55 len = av_strlcpy(buf+total_len, ass, bufsize-total_len);
57 if (len > bufsize-total_len-1) {
58 av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
59 return AVERROR_BUFFER_TOO_SMALL;
68 #if CONFIG_SSA_ENCODER
69 AVCodec ff_ssa_encoder = {
71 .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
72 .type = AVMEDIA_TYPE_SUBTITLE,
73 .id = AV_CODEC_ID_ASS,
74 .init = ass_encode_init,
75 .encode_sub = ass_encode_frame,
79 #if CONFIG_ASS_ENCODER
80 AVCodec ff_ass_encoder = {
82 .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
83 .type = AVMEDIA_TYPE_SUBTITLE,
84 .id = AV_CODEC_ID_ASS,
85 .init = ass_encode_init,
86 .encode_sub = ass_encode_frame,