00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <string.h>
00023
00024 #include "avcodec.h"
00025 #include "libavutil/avstring.h"
00026 #include "libavutil/internal.h"
00027 #include "libavutil/mem.h"
00028
00029 static av_cold int ass_encode_init(AVCodecContext *avctx)
00030 {
00031 avctx->extradata = av_malloc(avctx->subtitle_header_size);
00032 if (!avctx->extradata)
00033 return AVERROR(ENOMEM);
00034 memcpy(avctx->extradata, avctx->subtitle_header, avctx->subtitle_header_size);
00035 avctx->extradata_size = avctx->subtitle_header_size;
00036 return 0;
00037 }
00038
00039 static int ass_encode_frame(AVCodecContext *avctx,
00040 unsigned char *buf, int bufsize,
00041 const AVSubtitle *sub)
00042 {
00043 int i, len, total_len = 0;
00044
00045 for (i=0; i<sub->num_rects; i++) {
00046 if (sub->rects[i]->type != SUBTITLE_ASS) {
00047 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
00048 return -1;
00049 }
00050
00051 len = av_strlcpy(buf+total_len, sub->rects[i]->ass, bufsize-total_len);
00052
00053 if (len > bufsize-total_len-1) {
00054 av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
00055 return -1;
00056 }
00057
00058 total_len += len;
00059 }
00060
00061 return total_len;
00062 }
00063
00064 AVCodec ff_ass_encoder = {
00065 .name = "ass",
00066 .long_name = NULL_IF_CONFIG_SMALL("SSA (SubStation Alpha) subtitle"),
00067 .type = AVMEDIA_TYPE_SUBTITLE,
00068 .id = AV_CODEC_ID_SSA,
00069 .init = ass_encode_init,
00070 .encode_sub = ass_encode_frame,
00071 };