FFmpeg
Loading...
Searching...
No Matches
libavcodec
assdec.c
Go to the documentation of this file.
1
/*
2
* SSA/ASS decoder
3
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
4
*
5
* This file is part of FFmpeg.
6
*
7
* FFmpeg 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
* FFmpeg 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 FFmpeg; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
#include <string.h>
23
24
#include "
avcodec.h
"
25
#include "
ass.h
"
26
#include "
codec_internal.h
"
27
#include "config_components.h"
28
#include "
libavutil/internal.h
"
29
#include "
libavutil/mem.h
"
30
31
static
av_cold
int
ass_decode_init
(
AVCodecContext
*avctx)
32
{
33
avctx->
subtitle_header
=
av_malloc
(avctx->
extradata_size
+ 1);
34
if
(!avctx->
subtitle_header
)
35
return
AVERROR
(ENOMEM);
36
if
(avctx->
extradata_size
)
37
memcpy(avctx->
subtitle_header
, avctx->
extradata
, avctx->
extradata_size
);
38
avctx->
subtitle_header
[avctx->
extradata_size
] = 0;
39
avctx->
subtitle_header_size
= avctx->
extradata_size
;
40
return
0;
41
}
42
43
static
int
ass_decode_frame
(
AVCodecContext
*avctx,
AVSubtitle
*sub,
44
int
*got_sub_ptr,
const
AVPacket
*avpkt)
45
{
46
if
(avpkt->
size
<= 0)
47
return
avpkt->
size
;
48
49
sub->
rects
=
av_malloc
(
sizeof
(*sub->
rects
));
50
if
(!sub->
rects
)
51
return
AVERROR
(ENOMEM);
52
sub->
rects
[0] =
av_mallocz
(
sizeof
(*sub->
rects
[0]));
53
if
(!sub->
rects
[0])
54
return
AVERROR
(ENOMEM);
55
sub->
num_rects
= 1;
56
sub->
rects
[0]->
type
=
SUBTITLE_ASS
;
57
sub->
rects
[0]->
ass
=
av_strdup
(avpkt->
data
);
58
if
(!sub->
rects
[0]->
ass
)
59
return
AVERROR
(ENOMEM);
60
*got_sub_ptr = 1;
61
return
avpkt->
size
;
62
}
63
64
#if CONFIG_SSA_DECODER
65
const
FFCodec
ff_ssa_decoder
= {
66
.p.name =
"ssa"
,
67
CODEC_LONG_NAME
(
"ASS (Advanced SubStation Alpha) subtitle"
),
68
.p.type =
AVMEDIA_TYPE_SUBTITLE
,
69
.p.id =
AV_CODEC_ID_ASS
,
70
.init =
ass_decode_init
,
71
FF_CODEC_DECODE_SUB_CB
(
ass_decode_frame
),
72
};
73
#endif
74
75
#if CONFIG_ASS_DECODER
76
const
FFCodec
ff_ass_decoder
= {
77
.p.name =
"ass"
,
78
CODEC_LONG_NAME
(
"ASS (Advanced SubStation Alpha) subtitle"
),
79
.p.type =
AVMEDIA_TYPE_SUBTITLE
,
80
.p.id =
AV_CODEC_ID_ASS
,
81
.init =
ass_decode_init
,
82
FF_CODEC_DECODE_SUB_CB
(
ass_decode_frame
),
83
};
84
#endif
ff_ssa_decoder
const FFCodec ff_ssa_decoder
ff_ass_decoder
const FFCodec ff_ass_decoder
ass.h
avcodec.h
Libavcodec external API header.
codec_internal.h
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition
codec_internal.h:359
FF_CODEC_DECODE_SUB_CB
#define FF_CODEC_DECODE_SUB_CB(func)
Definition
codec_internal.h:378
SUBTITLE_ASS
@ SUBTITLE_ASS
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition
avcodec.h:2055
AV_CODEC_ID_ASS
@ AV_CODEC_ID_ASS
Definition
codec_id.h:588
AVERROR
#define AVERROR(e)
Definition
error.h:45
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition
avutil.h:203
ass_decode_init
static av_cold int ass_decode_init(AVCodecContext *avctx)
Definition
assdec.c:31
ass_decode_frame
static int ass_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Definition
assdec.c:43
av_cold
#define av_cold
Definition
attributes.h:117
internal.h
common internal API header
mem.h
Memory handling functions.
av_strdup
#define av_strdup(s)
Definition
ops_static.c:55
av_malloc
#define av_malloc(s)
Definition
ops_static.c:52
AVCodecContext
main external API structure.
Definition
avcodec.h:443
AVCodecContext::subtitle_header_size
int subtitle_header_size
Header containing style information for text subtitles.
Definition
avcodec.h:1743
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition
avcodec.h:1744
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition
avcodec.h:526
AVCodecContext::extradata_size
int extradata_size
Definition
avcodec.h:527
AVPacket
This structure stores compressed data.
Definition
packet.h:580
AVPacket::size
int size
Definition
packet.h:604
AVPacket::data
uint8_t * data
Definition
packet.h:603
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition
avcodec.h:2084
AVSubtitleRect::type
enum AVSubtitleType type
Definition
avcodec.h:2075
AVSubtitle
Definition
avcodec.h:2087
AVSubtitle::num_rects
unsigned num_rects
Definition
avcodec.h:2091
AVSubtitle::rects
AVSubtitleRect ** rects
Definition
avcodec.h:2092
FFCodec
Definition
codec_internal.h:129
av_mallocz
#define av_mallocz(s)
Definition
tableprint_vlc.h:31
Generated on Sun Aug 16 2026 20:20:44 for FFmpeg by
1.13.2