Libav
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
libavformat
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
28
static
int
write_header
(
AVFormatContext
*s)
29
{
30
ASSContext
*ass = s->
priv_data
;
31
AVCodecContext
*avctx= s->
streams
[0]->
codec
;
32
uint8_t
*last=
NULL
;
33
34
if
(s->
nb_streams
!= 1 || avctx->
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
< avctx->
extradata_size
){
40
uint8_t
*p = avctx->
extradata
+ ass->
extra_index
;
41
uint8_t
*end= strchr(p,
'\n'
);
42
if
(!end) end= avctx->
extradata
+ avctx->
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
58
static
int
write_packet
(
AVFormatContext
*s,
AVPacket
*pkt)
59
{
60
avio_write
(s->
pb
, pkt->
data
, pkt->
size
);
61
return
0;
62
}
63
64
static
int
write_trailer
(
AVFormatContext
*s)
65
{
66
ASSContext
*ass = s->
priv_data
;
67
AVCodecContext
*avctx= s->
streams
[0]->
codec
;
68
69
avio_write
(s->
pb
, avctx->
extradata
+ ass->
extra_index
,
70
avctx->
extradata_size
- ass->
extra_index
);
71
72
return
0;
73
}
74
75
AVOutputFormat
ff_ass_muxer
= {
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
,
82
.
write_header
=
write_header
,
83
.
write_packet
=
write_packet
,
84
.
write_trailer
=
write_trailer
,
85
.
flags
=
AVFMT_GLOBALHEADER
|
AVFMT_NOTIMESTAMPS
,
86
};
write_header
static int write_header(AVFormatContext *s)
Definition:
assenc.c:28
write_packet
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition:
assenc.c:58
AVPacket::size
int size
Definition:
avcodec.h:974
ff_ass_muxer
AVOutputFormat ff_ass_muxer
Definition:
assenc.c:75
AVFormatContext
Format I/O context.
Definition:
avformat.h:871
uint8_t
uint8_t
Definition:
audio_convert.c:194
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition:
avcodec.h:1162
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition:
avformat.h:935
AVPacket::data
uint8_t * data
Definition:
avcodec.h:973
flags
static int flags
Definition:
log.c:44
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition:
aviobuf.c:165
write_trailer
static int write_trailer(AVFormatContext *s)
Definition:
assenc.c:64
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition:
log.h:123
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition:
internal.h:142
av_log
void av_log(void *avcl, int level, const char *fmt,...)
Definition:
log.c:148
AVStream::codec
AVCodecContext * codec
Codec context associated with this stream.
Definition:
avformat.h:702
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition:
avformat.h:923
avio_flush
int void avio_flush(AVIOContext *s)
Definition:
aviobuf.c:180
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition:
avformat.h:406
AVOutputFormat::name
const char * name
Definition:
avformat.h:437
ASSContext::extra_index
unsigned int extra_index
Definition:
assenc.c:25
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition:
avformat.h:407
NULL
NULL
Definition:
eval.c:55
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition:
avcodec.h:1065
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition:
avformat.h:913
AVCodecContext
main external API structure.
Definition:
avcodec.h:1054
ASSContext
Definition:
assdec.c:30
AVCodecContext::extradata_size
int extradata_size
Definition:
avcodec.h:1163
AV_CODEC_ID_SSA
Definition:
avcodec.h:442
avformat.h
Main libavformat public API header.
AVOutputFormat
Definition:
avformat.h:436
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition:
avformat.h:899
AVPacket
This structure stores compressed data.
Definition:
avcodec.h:950
Generated on Mon Aug 4 2014 17:22:59 for Libav by
1.8.7