• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/assenc.c

Go to the documentation of this file.
00001 /*
00002  * SSA/ASS encoder
00003  * Copyright (c) 2010  Aurelien Jacobs <aurel@gnuage.org>
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 };
Generated on Thu Jan 24 2013 17:08:50 for Libav by doxygen 1.7.1