FFmpeg: libavcodec/webvttenc.c Source File
Go to the documentation of this file. 1 /*
2 * WebVTT subtitle encoder
3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
4 * Copyright (c) 2014 Aman Gupta <ffmpeg@tmm1.net>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <stdarg.h>
30
31 #define WEBVTT_STACK_SIZE 64
41
42 #ifdef __GNUC__
43 __attribute__ ((__format__ (__printf__, 2, 3)))
44 #endif
46 {
47 va_list vargs;
50 va_end(vargs);
51 }
52
54 {
56 return -1;
57 s->stack[
s->stack_ptr++] =
c;
58 return 0;
59 }
60
62 {
63 if (
s->stack_ptr <= 0)
64 return 0;
65 return s->stack[--
s->stack_ptr];
66 }
67
69 {
71 for (
i =
s->stack_ptr-1;
i >= 0;
i--)
73 break;
75 }
76
78 {
80 }
81
83 {
84 if (close) {
87 return;
88 while (
s->stack_ptr !=
i)
92 }
93
95 {
97 if (st) {
101 }
105 }
109 }
110 }
111 }
112
114 {
117 }
118
120 {
122 }
123
125 {
126 if (style == 's') // strikethrough unsupported
127 return;
128
130 if (!close)
132 }
133
135 {
138 }
139
141 {
143 }
144
156 };
157
160 {
164
166
167 for (
i=0;
i<
sub->num_rects;
i++) {
168 const char *ass =
sub->rects[
i]->ass;
169
173 }
174
176 if (!dialog)
181 }
182
186 return 0;
187
188 if (
s->buffer.len > bufsize) {
191 }
192 memcpy(buf,
s->buffer.str,
s->buffer.len);
193
194 return s->buffer.len;
195 }
196
198 {
202 return 0;
203 }
204
206 {
212 }
213
224 };
#define AV_BPRINT_SIZE_UNLIMITED
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static void webvtt_print(WebVTTContext *s, const char *str,...)
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
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 float sub(float src0, float src1)
static char webvtt_stack_pop(WebVTTContext *s)
ASSDialog * ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
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.
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 av_cold int webvtt_encode_init(AVCodecContext *avctx)
#define WEBVTT_STACK_SIZE
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
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.
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
const AVCodec ff_webvtt_encoder
static int webvtt_stack_find(WebVTTContext *s, const char c)
static int webvtt_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
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 webvtt_text_cb(void *priv, const char *text, int len)
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).
int underline
whether text is underlined (1) or not (0)
static const ASSCodesCallbacks webvtt_callbacks
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...
static int webvtt_stack_push(WebVTTContext *s, const char c)
int italic
whether text is italic (1) or not (0)
static void webvtt_cancel_overrides_cb(void *priv, const char *style)
#define ASS_DEFAULT_UNDERLINE
static void webvtt_end_cb(void *priv)
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
#define i(width, name, range_min, range_max)
static void webvtt_style_cb(void *priv, char style, int close)
const char * name
Name of the codec implementation.
#define ASS_DEFAULT_ITALIC
ASSSplitContext * ass_ctx
static void webvtt_new_line_cb(void *priv, int forced)
main external API structure.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
static void webvtt_stack_push_pop(WebVTTContext *s, const char c, int close)
fields extracted from the [Events] section
static void webvtt_style_apply(WebVTTContext *s, const char *style)
static int webvtt_encode_close(AVCodecContext *avctx)
#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 void webvtt_close_tag(WebVTTContext *s, char tag)
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:38:00 for FFmpeg by
doxygen
1.8.17