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