Libav
assenc.c
Go to the documentation of this file.
1 /*
2  * SSA/ASS muxer
3  * Copyright (c) 2008 Michael Niedermayer
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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.
11  *
12  * Libav 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.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "avformat.h"
23 
24 typedef struct ASSContext{
25  unsigned int extra_index;
26 }ASSContext;
27 
29 {
30  ASSContext *ass = s->priv_data;
31  AVCodecParameters *par = s->streams[0]->codecpar;
32  uint8_t *last= NULL;
33 
34  if(s->nb_streams != 1 || par->codec_id != AV_CODEC_ID_SSA){
35  av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
36  return -1;
37  }
38 
39  while(ass->extra_index < par->extradata_size){
40  uint8_t *p = par->extradata + ass->extra_index;
41  uint8_t *end= strchr(p, '\n');
42  if(!end) end= par->extradata + par->extradata_size;
43  else end++;
44 
45  avio_write(s->pb, p, end-p);
46  ass->extra_index += end-p;
47 
48  if(last && !memcmp(last, "[Events]", 8))
49  break;
50  last=p;
51  }
52 
53  avio_flush(s->pb);
54 
55  return 0;
56 }
57 
59 {
60  avio_write(s->pb, pkt->data, pkt->size);
61  return 0;
62 }
63 
65 {
66  ASSContext *ass = s->priv_data;
67  AVCodecParameters *par = s->streams[0]->codecpar;
68 
69  avio_write(s->pb, par->extradata + ass->extra_index,
70  par->extradata_size - ass->extra_index);
71 
72  return 0;
73 }
74 
76  .name = "ass",
77  .long_name = NULL_IF_CONFIG_SMALL("SSA (SubStation Alpha) subtitle"),
78  .mime_type = "text/x-ssa",
79  .extensions = "ass,ssa",
80  .priv_data_size = sizeof(ASSContext),
81  .subtitle_codec = AV_CODEC_ID_SSA,
86 };
static int write_header(AVFormatContext *s)
Definition: assenc.c:28
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
AVOutputFormat ff_ass_muxer
Definition: assenc.c:75
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3475
Format I/O context.
Definition: avformat.h:940
uint8_t
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1008
uint8_t * data
Definition: avcodec.h:1346
static int flags
Definition: log.c:50
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:996
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:419
const char * name
Definition: avformat.h:450
unsigned int extra_index
Definition: assenc.c:25
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:420
NULL
Definition: eval.c:55
AVIOContext * pb
I/O context.
Definition: avformat.h:982
Main libavformat public API header.
void * priv_data
Format private data.
Definition: avformat.h:968
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3497
AVCodecParameters * codecpar
Definition: avformat.h:831
This structure stores compressed data.
Definition: avcodec.h:1323