FFmpeg: libavcodec/srtenc.c Source File
Go to the documentation of this file. 1 /*
2 * SubRip subtitle 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 <stdarg.h>
31
32
33 #define SRT_STACK_SIZE 64
34
43
44
45 #ifdef __GNUC__
46 __attribute__ ((__format__ (__printf__, 2, 3)))
47 #endif
49 {
50 va_list vargs;
53 va_end(vargs);
54 }
55
57 {
59 return -1;
60 s->stack[
s->stack_ptr++] =
c;
61 return 0;
62 }
63
65 {
66 if (
s->stack_ptr <= 0)
67 return 0;
68 return s->stack[--
s->stack_ptr];
69 }
70
72 {
74 for (
i =
s->stack_ptr-1;
i >= 0;
i--)
76 break;
78 }
79
81 {
83 }
84
86 {
87 if (close) {
90 return;
91 while (
s->stack_ptr !=
i)
95 }
96
98 {
100 if (st) {
112 (
c & 0xFF0000) >> 16 |
c & 0xFF00 | (
c & 0xFF) << 16);
115 }
119 }
123 }
127 }
130 s->alignment_applied = 1;
131 }
132 }
133 }
134
135
137 {
143 }
144
146 {
149 }
150
152 {
154 }
155
157 {
159 if (!close)
161 }
162
164 {
165 if (color_id > 1)
166 return;
168 if (
color != 0xFFFFFFFF)
169 srt_print(priv,
"<font color=\"#%06x\">",
171 }
172
174 {
178 }
179
181 {
185 }
186
188 {
190 if (!
s->alignment_applied && alignment >= 0) {
192 s->alignment_applied = 1;
193 }
194 }
195
197 {
200 }
201
202 static void srt_move_cb(
void *priv,
int x1,
int y1,
int x2,
int y2,
204 {
205 // TODO: add a AV_PKT_DATA_SUBTITLE_POSITION side data when a new subtitles
206 // encoding API passing the AVPacket is available.
207 }
208
210 {
212 }
213
225 };
226
230 };
231
235 {
239
241
242 for (
i=0;
i<
sub->num_rects;
i++) {
243 const char *ass =
sub->rects[
i]->ass;
244
248 }
249
251 if (!dialog)
253 s->alignment_applied = 0;
258 }
259
263 return 0;
264
265 if (
s->buffer.len > bufsize) {
268 }
269 memcpy(buf,
s->buffer.str,
s->buffer.len);
270
271 return s->buffer.len;
272 }
273
276 {
278 }
279
282 {
284 }
285
287 {
291 return 0;
292 }
293
294 #if CONFIG_SRT_ENCODER
295 /* deprecated encoder */
306 };
307 #endif
308
309 #if CONFIG_SUBRIP_ENCODER
320 };
321 #endif
322
323 #if CONFIG_TEXT_ENCODER
334 };
335 #endif
static void srt_new_line_cb(void *priv, int forced)
#define AV_BPRINT_SIZE_UNLIMITED
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
static int srt_stack_find(SRTContext *s, const char c)
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
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
static void srt_stack_push_pop(SRTContext *s, const char c, int close)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static double cb(void *priv, double x, double y)
static const ASSCodesCallbacks text_callbacks
static float sub(float src0, float src1)
int alignment
position of the text (left, center, top...), defined after the layout of the numpad (1-3 sub,...
static void srt_alignment_cb(void *priv, int alignment)
ASSDialog * ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
#define ASS_DEFAULT_ALIGNMENT
uint8_t * subtitle_header
Header containing style information for text subtitles.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
static av_cold int srt_encode_init(AVCodecContext *avctx)
char * style
name of the ASSStyle to use with this dialog
@ SUBTITLE_ASS
Formatted text, the ass field must be set by the decoder and is authoritative.
static int srt_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
char * font_name
font face (case sensitive)
AVCodec p
The public AVCodec.
const FFCodec ff_srt_encoder
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
static char srt_stack_pop(SRTContext *s)
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog().
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const FFCodec ff_text_encoder
static void srt_font_size_cb(void *priv, int size)
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
int primary_color
color that a subtitle will normally appear in
static int srt_stack_push(SRTContext *s, const char c)
static int srt_encode_close(AVCodecContext *avctx)
#define FF_CODEC_ENCODE_SUB_CB(func)
This struct can be casted to ASS to access to the split data.
ASSSplitContext * ff_ass_split(const char *buf)
Split a full ASS file or a ASS header from a string buffer and store the split structure in a newly a...
static void srt_cancel_overrides_cb(void *priv, const char *style)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
fields extracted from the [V4(+) Styles] section
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
static void srt_close_tag(SRTContext *s, char tag)
int underline
whether text is underlined (1) or not (0)
void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
ASSSplitContext * ass_ctx
static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2, int t1, int t2)
int italic
whether text is italic (1) or not (0)
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub, const ASSCodesCallbacks *cb)
static void srt_color_cb(void *priv, unsigned int color, unsigned int color_id)
#define ASS_DEFAULT_UNDERLINE
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
static void srt_style_apply(SRTContext *s, const char *style)
#define i(width, name, range_min, range_max)
static void srt_print(SRTContext *s, const char *str,...)
const FFCodec ff_subrip_encoder
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
const char * name
Name of the codec implementation.
#define ASS_DEFAULT_ITALIC
#define ASS_DEFAULT_COLOR
@ AV_CODEC_ID_TEXT
raw UTF-8 text
static void srt_end_cb(void *priv)
#define ASS_DEFAULT_FONT_SIZE
main external API structure.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
static void srt_style_cb(void *priv, char style, int close)
fields extracted from the [Events] section
static void srt_text_cb(void *priv, const char *text, int len)
static void srt_font_name_cb(void *priv, const char *name)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
static const ASSCodesCallbacks srt_callbacks
static int text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
int bold
whether text is bold (1) or not (0)
void(* text)(void *priv, const char *text, int len)
Generated on Wed Aug 24 2022 21:41:48 for FFmpeg by
doxygen
1.8.17