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
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  */
22 #include <string.h>
24 #include "avcodec.h"
25 #include "ass.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/mem.h"
30 {
31  avctx->subtitle_header = av_malloc(avctx->extradata_size + 1);
32  if (!avctx->subtitle_header)
33  return AVERROR(ENOMEM);
34  if (avctx->extradata_size)
35  memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
36  avctx->subtitle_header[avctx->extradata_size] = 0;
37  avctx->subtitle_header_size = avctx->extradata_size;
38  return 0;
39 }
41 static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
42  AVPacket *avpkt)
43 {
44  AVSubtitle *sub = data;
46  if (avpkt->size <= 0)
47  return avpkt->size;
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 }
66  .name = "ssa",
67  .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
69  .id = AV_CODEC_ID_ASS,
70  .init = ass_decode_init,
71  .decode = ass_decode_frame,
72 };
73 #endif
77  .name = "ass",
78  .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
80  .id = AV_CODEC_ID_ASS,
81  .init = ass_decode_init,
82  .decode = ass_decode_frame,
83 };
84 #endif
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
Memory handling functions.
int size
Definition: packet.h:364
unsigned num_rects
Definition: avcodec.h:2679
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
Definition: codec.h:190
AVSubtitleRect ** rects
Definition: avcodec.h:2680
static av_cold int ass_decode_init(AVCodecContext *avctx)
Definition: assdec.c:29
#define av_cold
Definition: attributes.h:88
#define av_malloc(s)
int subtitle_header_size
Definition: avcodec.h:2008
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:632
uint8_t * data
Definition: packet.h:363
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:115
const char * name
Name of the codec implementation.
Definition: codec.h:197
common internal API header
static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt)
Definition: assdec.c:41
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:531
int extradata_size
Definition: avcodec.h:633
AVCodec ff_ssa_decoder
AVCodec ff_ass_decoder
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition: avcodec.h:2635
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2670
static float sub(float src0, float src1)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
enum AVSubtitleType type
Definition: avcodec.h:2661
This structure stores compressed data.
Definition: packet.h:340
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:2007