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

libavformat/assenc.c

Go to the documentation of this file.
00001 /*
00002  * SSA/ASS muxer
00003  * Copyright (c) 2008 Michael Niedermayer
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 
00024 typedef struct ASSContext{
00025     unsigned int extra_index;
00026 }ASSContext;
00027 
00028 static int write_header(AVFormatContext *s)
00029 {
00030     ASSContext *ass = s->priv_data;
00031     AVCodecContext *avctx= s->streams[0]->codec;
00032     uint8_t *last= NULL;
00033 
00034     if(s->nb_streams != 1 || avctx->codec_id != CODEC_ID_SSA){
00035         av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
00036         return -1;
00037     }
00038 
00039     while(ass->extra_index < avctx->extradata_size){
00040         uint8_t *p  = avctx->extradata + ass->extra_index;
00041         uint8_t *end= strchr(p, '\n');
00042         if(!end) end= avctx->extradata + avctx->extradata_size;
00043         else     end++;
00044 
00045         put_buffer(s->pb, p, end-p);
00046         ass->extra_index += end-p;
00047 
00048         if(last && !memcmp(last, "[Events]", 8))
00049             break;
00050         last=p;
00051     }
00052 
00053     put_flush_packet(s->pb);
00054 
00055     return 0;
00056 }
00057 
00058 static int write_packet(AVFormatContext *s, AVPacket *pkt)
00059 {
00060     put_buffer(s->pb, pkt->data, pkt->size);
00061 
00062     put_flush_packet(s->pb);
00063 
00064     return 0;
00065 }
00066 
00067 static int write_trailer(AVFormatContext *s)
00068 {
00069     ASSContext *ass = s->priv_data;
00070     AVCodecContext *avctx= s->streams[0]->codec;
00071 
00072     put_buffer(s->pb, avctx->extradata      + ass->extra_index,
00073                       avctx->extradata_size - ass->extra_index);
00074 
00075     put_flush_packet(s->pb);
00076 
00077     return 0;
00078 }
00079 
00080 AVOutputFormat ass_muxer = {
00081     "ass",
00082     NULL_IF_CONFIG_SMALL("SSA/ASS format"),
00083     NULL,
00084     "ass,ssa",
00085     sizeof(ASSContext),
00086     CODEC_ID_NONE,
00087     CODEC_ID_NONE,
00088     write_header,
00089     write_packet,
00090     write_trailer,
00091     .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS
00092 };

Generated on Fri Sep 16 2011 17:17:47 for FFmpeg by  doxygen 1.7.1