FFmpeg
Loading...
Searching...
No Matches
assenc.c
Go to the documentation of this file.
1/*
2 * SSA/ASS encoder
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 "config_components.h"
23
24#include <string.h>
25
26#include "avcodec.h"
27#include "ass.h"
28#include "codec_internal.h"
29#include "libavutil/avstring.h"
30#include "libavutil/internal.h"
31#include "libavutil/mem.h"
32
34{
35 avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
36 if (!avctx->extradata)
37 return AVERROR(ENOMEM);
38 memcpy(avctx->extradata, avctx->subtitle_header, avctx->subtitle_header_size);
40 avctx->extradata[avctx->extradata_size] = 0;
41 return 0;
42}
43
45 unsigned char *buf, int bufsize,
46 const AVSubtitle *sub)
47{
48 size_t len;
49
50 if (sub->num_rects != 1) {
51 av_log(avctx, AV_LOG_ERROR, "Only one rect per AVSubtitle is supported in ASS.\n");
53 }
54
55 if (sub->rects[0]->type != SUBTITLE_ASS) {
56 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
57 return AVERROR(EINVAL);
58 }
59
60 len = av_strlcpy(buf, sub->rects[0]->ass, bufsize);
61
62 if (len >= bufsize) {
63 av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
65 }
66
67 return len;
68}
69
70#if CONFIG_SSA_ENCODER
71const FFCodec ff_ssa_encoder = {
72 .p.name = "ssa",
73 CODEC_LONG_NAME("ASS (Advanced SubStation Alpha) subtitle"),
74 .p.type = AVMEDIA_TYPE_SUBTITLE,
75 .p.id = AV_CODEC_ID_ASS,
76 .init = ass_encode_init,
78};
79#endif
80
81#if CONFIG_ASS_ENCODER
82const FFCodec ff_ass_encoder = {
83 .p.name = "ass",
84 CODEC_LONG_NAME("ASS (Advanced SubStation Alpha) subtitle"),
85 .p.type = AVMEDIA_TYPE_SUBTITLE,
86 .p.id = AV_CODEC_ID_ASS,
87 .init = ass_encode_init,
89};
90#endif
const FFCodec ff_ass_encoder
const FFCodec ff_ssa_encoder
Libavcodec external API header.
#define FF_CODEC_ENCODE_SUB_CB(func)
#define CODEC_LONG_NAME(str)
@ SUBTITLE_ASS
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition avcodec.h:2055
@ AV_CODEC_ID_ASS
Definition codec_id.h:588
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition error.h:53
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition avstring.c:85
static av_cold int ass_encode_init(AVCodecContext *avctx)
Definition assenc.c:33
static int ass_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
Definition assenc.c:44
#define av_cold
Definition attributes.h:117
common internal API header
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
main external API structure.
Definition avcodec.h:443
int subtitle_header_size
Header containing style information for text subtitles.
Definition avcodec.h:1743
uint8_t * subtitle_header
Definition avcodec.h:1744
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
int extradata_size
Definition avcodec.h:527
char * ass
0 terminated ASS/SSA compatible event line.
Definition avcodec.h:2084
enum AVSubtitleType type
Definition avcodec.h:2075
unsigned num_rects
Definition avcodec.h:2091
AVSubtitleRect ** rects
Definition avcodec.h:2092
#define av_log(a,...)
int len