FFmpeg
Loading...
Searching...
No Matches
vf_subtitles.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Baptiste Coudurier
3 * Copyright (c) 2011 Stefano Sabatini
4 * Copyright (c) 2012 Clément Bœsch
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/**
24 * @file
25 * Libass subtitles burning filter.
26 *
27 * @see{http://www.matroska.org/technical/specs/subtitles/ssa.html}
28 */
29
30#include <ass/ass.h>
31
32#include "config_components.h"
33#if CONFIG_SUBTITLES_FILTER
34# include "libavcodec/avcodec.h"
36# include "libavformat/avformat.h"
37#endif
38#include "libavutil/avstring.h"
39#include "libavutil/mem.h"
40#include "libavutil/opt.h"
41
42#include "filters.h"
43#include "drawutils.h"
44#include "avfilter.h"
45#include "formats.h"
46#include "video.h"
47
48#define FF_ASS_FEATURE_WRAP_UNICODE (LIBASS_VERSION >= 0x01600010)
49
50typedef struct AssContext {
51 const AVClass *class;
52 ASS_Library *library;
53 ASS_Renderer *renderer;
54 ASS_Track *track;
55 char *filename;
56 char *script;
57 char *fontsdir;
58 char *charenc;
61 int alpha;
62 uint8_t rgba_map[4];
63 int pix_step[4]; ///< steps per pixel for each plane of the main output
69
70#define OFFSET(x) offsetof(AssContext, x)
71#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
72
73#define COMMON_OPTIONS \
74 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
75 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
76 {"original_size", "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS }, \
77 {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
78 {"alpha", "enable processing of alpha channel", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, \
79
80#define SHAPING_OPTIONS \
81 {"shaping", "set shaping engine", OFFSET(shaping), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, FLAGS, .unit = "shaping_mode"}, \
82 {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS, .unit = "shaping_mode"}, \
83 {"simple", "simple shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX, FLAGS, .unit = "shaping_mode"}, \
84 {"complex", "complex shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX, FLAGS, .unit = "shaping_mode"}, \
85
86/* libass supports a log level ranging from 0 to 7 */
87static const int ass_libavfilter_log_level_map[] = {
88 [0] = AV_LOG_FATAL, /* MSGL_FATAL */
89 [1] = AV_LOG_ERROR, /* MSGL_ERR */
90 [2] = AV_LOG_WARNING, /* MSGL_WARN */
91 [3] = AV_LOG_WARNING, /* <undefined> */
92 [4] = AV_LOG_INFO, /* MSGL_INFO */
93 [5] = AV_LOG_INFO, /* <undefined> */
94 [6] = AV_LOG_VERBOSE, /* MSGL_V */
95 [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
96};
97
98static enum AVColorSpace ass_get_color_space(ASS_YCbCrMatrix ass_matrix, enum AVColorSpace inlink_space) {
99 switch (ass_matrix) {
100 case YCBCR_NONE: return inlink_space;
101 case YCBCR_SMPTE240M_TV:
102 case YCBCR_SMPTE240M_PC: return AVCOL_SPC_SMPTE240M;
103 case YCBCR_FCC_TV:
104 case YCBCR_FCC_PC: return AVCOL_SPC_FCC;
105 case YCBCR_BT709_TV:
106 case YCBCR_BT709_PC: return AVCOL_SPC_BT709;
107 case YCBCR_BT601_TV:
108 case YCBCR_BT601_PC:
109 case YCBCR_DEFAULT:
110 case YCBCR_UNKNOWN:
111 default: return AVCOL_SPC_SMPTE170M;
112 }
113}
114
115static enum AVColorRange ass_get_color_range(ASS_YCbCrMatrix ass_matrix, enum AVColorRange inlink_range) {
116 switch (ass_matrix) {
117 case YCBCR_NONE: return inlink_range;
118 case YCBCR_SMPTE240M_PC:
119 case YCBCR_FCC_PC:
120 case YCBCR_BT709_PC:
121 case YCBCR_BT601_PC: return AVCOL_RANGE_JPEG;
122 case YCBCR_SMPTE240M_TV:
123 case YCBCR_FCC_TV:
124 case YCBCR_BT709_TV:
125 case YCBCR_BT601_TV:
126 case YCBCR_DEFAULT:
127 case YCBCR_UNKNOWN:
128 default: return AVCOL_RANGE_MPEG;
129 }
130}
131
132static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
133{
134 const int ass_level_clip = av_clip(ass_level, 0,
136 const int level = ass_libavfilter_log_level_map[ass_level_clip];
137
138 av_vlog(ctx, level, fmt, args);
139 av_log(ctx, level, "\n");
140}
141
143{
144 AssContext *ass = ctx->priv;
145
146 ass->library = ass_library_init();
147 if (!ass->library) {
148 av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
149 return AVERROR(EINVAL);
150 }
151 ass_set_message_cb(ass->library, ass_log, ctx);
152
153 ass_set_fonts_dir(ass->library, ass->fontsdir);
154 ass_set_extract_fonts(ass->library, 1);
155
156 ass->renderer = ass_renderer_init(ass->library);
157 if (!ass->renderer) {
158 av_log(ctx, AV_LOG_ERROR, "Could not initialize libass renderer.\n");
159 return AVERROR(EINVAL);
160 }
161
162 return 0;
163}
164
166{
167 AssContext *ass = ctx->priv;
168
169 if (ass->track)
170 ass_free_track(ass->track);
171 if (ass->renderer)
172 ass_renderer_done(ass->renderer);
173 if (ass->library)
174 ass_library_done(ass->library);
175}
176
178 AVFilterFormatsConfig **cfg_in,
179 AVFilterFormatsConfig **cfg_out)
180{
181 return ff_set_common_formats2(ctx, cfg_in, cfg_out,
183}
184
185static int config_input(AVFilterLink *inlink)
186{
187 AVFilterContext *ctx = inlink->dst;
188 AssContext *ass = ctx->priv;
189 int ret;
190
191 ret = ff_draw_init2(&ass->draw, inlink->format,
192 ass_get_color_space(ass->track->YCbCrMatrix, inlink->colorspace),
193 ass_get_color_range(ass->track->YCbCrMatrix, inlink->color_range),
194 inlink->alpha_mode, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
195 if (ret < 0) {
196 av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
197 return ret;
198 }
199
200 ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
201 if (ass->original_w && ass->original_h) {
202 ass_set_pixel_aspect(ass->renderer, (double)inlink->w / inlink->h /
203 ((double)ass->original_w / ass->original_h));
204 ass_set_storage_size(ass->renderer, ass->original_w, ass->original_h);
205 } else
206 ass_set_storage_size(ass->renderer, inlink->w, inlink->h);
207
208 if (ass->shaping != -1)
209 ass_set_shaper(ass->renderer, ass->shaping);
210
211 return 0;
212}
213
214/* libass stores an RGBA color in the format RRGGBBTT, where TT is the transparency level */
215#define AR(c) ( (c)>>24)
216#define AG(c) (((c)>>16)&0xFF)
217#define AB(c) (((c)>>8) &0xFF)
218#define AA(c) ((0xFF-(c)) &0xFF)
219
220static void overlay_ass_image(AssContext *ass, AVFrame *picref,
221 const ASS_Image *image)
222{
223 for (; image; image = image->next) {
224 uint8_t rgba_color[] = {AR(image->color), AG(image->color), AB(image->color), AA(image->color)};
226 ff_draw_color(&ass->draw, &color, rgba_color);
227 ff_blend_mask(&ass->draw, &color,
228 picref->data, picref->linesize,
229 picref->width, picref->height,
230 image->bitmap, image->stride, image->w, image->h,
231 3, 0, image->dst_x, image->dst_y);
232 }
233}
234
235static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
236{
237 AVFilterContext *ctx = inlink->dst;
238 AVFilterLink *outlink = ctx->outputs[0];
239 AssContext *ass = ctx->priv;
240 int detect_change = 0;
241 double time_ms = picref->pts * av_q2d(inlink->time_base) * 1000;
242 ASS_Image *image = ass_render_frame(ass->renderer, ass->track,
243 time_ms, &detect_change);
244
245 if (detect_change)
246 av_log(ctx, AV_LOG_DEBUG, "Change happened at time ms:%f\n", time_ms);
247
248 overlay_ass_image(ass, picref, image);
249
250 return ff_filter_frame(outlink, picref);
251}
252
253static const AVFilterPad ass_inputs[] = {
254 {
255 .name = "default",
256 .type = AVMEDIA_TYPE_VIDEO,
258 .filter_frame = filter_frame,
259 .config_props = config_input,
260 },
261};
262
263#if CONFIG_ASS_FILTER
264
265static const AVOption ass_options[] = {
268 {"script", "set the ASS script to render instead of reading a file", OFFSET(script), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS | AV_OPT_FLAG_RUNTIME_PARAM },
269 {NULL},
270};
271
273
274static int read_track(AVFilterContext *ctx)
275{
276 AssContext *ass = ctx->priv;
277 ASS_Track *track = ass->script ? ass_read_memory(ass->library, ass->script, strlen(ass->script), NULL)
278 : ass_read_file(ass->library, ass->filename, NULL);
279
280 if (!track) {
281 av_log(ctx, AV_LOG_ERROR, "Could not create a libass track from %s\n",
282 ass->filename ? ass->filename : "the script");
283 return AVERROR(EINVAL);
284 }
285 if (ass->track)
286 ass_free_track(ass->track);
287 ass->track = track;
288 return 0;
289}
290
291static av_cold int init_ass(AVFilterContext *ctx)
292{
293 AssContext *ass = ctx->priv;
294 int ret;
295
296 if (!ass->filename == !ass->script) {
297 av_log(ctx, AV_LOG_ERROR, "Exactly one of filename and script must be set\n");
298 return AVERROR(EINVAL);
299 }
300 ret = init(ctx);
301 if (ret < 0)
302 return ret;
303
304 /* Initialize fonts */
305 ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
306
307 return read_track(ctx);
308}
309
310static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg,
311 char *res, int res_len, int flags)
312{
313 int ret = ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
314
315 if (ret < 0 || (ret = read_track(ctx)) < 0)
316 return ret;
317 return config_input(ctx->inputs[0]);
318}
319
320const FFFilter ff_vf_ass = {
321 .p.name = "ass",
322 .p.description = NULL_IF_CONFIG_SMALL("Render ASS subtitles onto input video using the libass library."),
323 .p.priv_class = &ass_class,
324 .priv_size = sizeof(AssContext),
325 .init = init_ass,
326 .uninit = uninit,
330 .process_command = process_command,
331};
332#endif
333
334#if CONFIG_SUBTITLES_FILTER
335
336static const AVOption subtitles_options[] = {
338 {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
339 {"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
340 {"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
341 {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
342#if FF_ASS_FEATURE_WRAP_UNICODE
343 {"wrap_unicode", "break lines according to the Unicode Line Breaking Algorithm", OFFSET(wrap_unicode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, FLAGS },
344#endif
346 {NULL},
347};
348
349static const char * const font_mimetypes[] = {
350 "font/ttf",
351 "font/otf",
352 "font/sfnt",
353 "font/woff",
354 "font/woff2",
355 "application/font-sfnt",
356 "application/font-woff",
357 "application/x-truetype-font",
358 "application/vnd.ms-opentype",
359 "application/x-font-ttf",
360 NULL
361};
362
363static int attachment_is_font(AVStream * st)
364{
365 const AVDictionaryEntry *tag = NULL;
366 int n;
367
368 tag = av_dict_get(st->metadata, "mimetype", NULL, AV_DICT_MATCH_CASE);
369
370 if (tag) {
371 for (n = 0; font_mimetypes[n]; n++) {
372 if (av_strcasecmp(font_mimetypes[n], tag->value) == 0)
373 return 1;
374 }
375 }
376 return 0;
377}
378
379AVFILTER_DEFINE_CLASS(subtitles);
380
381static av_cold int init_subtitles(AVFilterContext *ctx)
382{
383 int j, ret, sid;
384 int k = 0;
386 AVFormatContext *fmt = NULL;
388 const AVCodec *dec;
389 const AVCodecDescriptor *dec_desc;
390 AVStream *st;
392 AssContext *ass = ctx->priv;
393
394 if (!ass->filename) {
395 av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
396 return AVERROR(EINVAL);
397 }
398
399 /* Init libass */
400 ret = init(ctx);
401 if (ret < 0)
402 return ret;
403 ass->track = ass_new_track(ass->library);
404 if (!ass->track) {
405 av_log(ctx, AV_LOG_ERROR, "Could not create a libass track\n");
406 return AVERROR(EINVAL);
407 }
408
409 /* Open subtitles file */
410 ret = avformat_open_input(&fmt, ass->filename, NULL, NULL);
411 if (ret < 0) {
412 av_log(ctx, AV_LOG_ERROR, "Unable to open %s\n", ass->filename);
413 goto end;
414 }
416 if (ret < 0)
417 goto end;
418
419 /* Locate subtitles stream */
420 if (ass->stream_index < 0)
421 ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0);
422 else {
423 ret = -1;
424 if (ass->stream_index < fmt->nb_streams) {
425 for (j = 0; j < fmt->nb_streams; j++) {
427 if (ass->stream_index == k) {
428 ret = j;
429 break;
430 }
431 k++;
432 }
433 }
434 }
435 }
436
437 if (ret < 0) {
438 av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n",
439 ass->filename);
440 goto end;
441 }
442 sid = ret;
443 st = fmt->streams[sid];
444
445 /* Load attached fonts */
446 for (j = 0; j < fmt->nb_streams; j++) {
447 AVStream *st = fmt->streams[j];
449 attachment_is_font(st)) {
450 const AVDictionaryEntry *tag = NULL;
451 tag = av_dict_get(st->metadata, "filename", NULL,
453
454 if (tag) {
455 av_log(ctx, AV_LOG_DEBUG, "Loading attached font: %s\n",
456 tag->value);
457 ass_add_font(ass->library, tag->value,
458 st->codecpar->extradata,
460 } else {
462 "Font attachment has no filename, ignored.\n");
463 }
464 }
465 }
466
467 /* Initialize fonts */
468 ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
469
470 /* Open decoder */
472 if (!dec) {
473 av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n",
476 goto end;
477 }
479 if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
481 "Only text based subtitles are currently supported\n");
483 goto end;
484 }
485 if (ass->charenc)
486 av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
487
489 if (!dec_ctx) {
490 ret = AVERROR(ENOMEM);
491 goto end;
492 }
493
495 if (ret < 0)
496 goto end;
497
498 /*
499 * This is required by the decoding process in order to rescale the
500 * timestamps: in the current API the decoded subtitles have their pts
501 * expressed in AV_TIME_BASE, and thus the lavc internals need to know the
502 * stream time base in order to achieve the rescaling.
503 *
504 * That API is old and needs to be reworked to match behaviour with A/V.
505 */
506 dec_ctx->pkt_timebase = st->time_base;
507
509 if (ret < 0)
510 goto end;
511
512#if FF_ASS_FEATURE_WRAP_UNICODE
513 /* Don't overwrite wrap automatically for native ASS */
514 if (ass->wrap_unicode == -1)
516 if (ass->wrap_unicode) {
517 ret = ass_track_set_feature(ass->track, ASS_FEATURE_WRAP_UNICODE, 1);
518 if (ret < 0)
520 "libass wasn't built with ASS_FEATURE_WRAP_UNICODE support\n");
521 }
522#endif
523
524 if (ass->force_style) {
525 char **list = NULL;
526 char *temp = NULL;
527 char *ptr = av_strtok(ass->force_style, ",", &temp);
528 int i = 0;
529 while (ptr) {
530 av_dynarray_add(&list, &i, ptr);
531 if (!list) {
532 ret = AVERROR(ENOMEM);
533 goto end;
534 }
535 ptr = av_strtok(NULL, ",", &temp);
536 }
537 av_dynarray_add(&list, &i, NULL);
538 if (!list) {
539 ret = AVERROR(ENOMEM);
540 goto end;
541 }
542 ass_set_style_overrides(ass->library, list);
543 av_free(list);
544 }
545 /* Decode subtitles and push them into the renderer (libass) */
546 if (dec_ctx->subtitle_header)
547 ass_process_codec_private(ass->track,
548 dec_ctx->subtitle_header,
549 dec_ctx->subtitle_header_size);
550 while (av_read_frame(fmt, &pkt) >= 0) {
551 int i, got_subtitle;
552 AVSubtitle sub = {0};
553
554 if (pkt.stream_index == sid) {
555 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
556 if (ret < 0) {
557 av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
558 av_err2str(ret));
559 } else if (got_subtitle) {
562 for (i = 0; i < sub.num_rects; i++) {
563 char *ass_line = sub.rects[i]->ass;
564 if (!ass_line)
565 break;
566 ass_process_chunk(ass->track, ass_line, strlen(ass_line),
568 }
569 }
570 }
572 avsubtitle_free(&sub);
573 }
574
575end:
579 return ret;
580}
581
583 .p.name = "subtitles",
584 .p.description = NULL_IF_CONFIG_SMALL("Render text subtitles onto input video using the libass library."),
585 .p.priv_class = &subtitles_class,
586 .priv_size = sizeof(AssContext),
587 .init = init_subtitles,
588 .uninit = uninit,
592};
593#endif
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_vf_ass
const FFFilter ff_vf_subtitles
static AVFormatContext * ctx
Libavcodec external API header.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1073
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition avfilter.c:911
Main libavfilter public API header.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags)
Definition avformat.c:507
Main libavformat public API header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FLAGS
Definition cmdutils.c:596
AVDictionary * codec_opts
Definition cmdutils.c:56
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Definition codec_par.c:206
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVCodecContext * dec_ctx
static AVPacket * pkt
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition drawutils.c:179
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, enum AVAlphaMode alpha, unsigned flags)
Init a draw context.
Definition drawutils.c:96
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition drawutils.c:688
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
Definition drawutils.c:574
misc drawing utilities
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
Definition drawutils.h:64
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int64_t duration
Definition ffplay.c:399
static int64_t start_time
Definition ffplay.c:398
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition formats.c:1200
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition opt.h:376
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition avcodec.c:144
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition options.c:149
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition allcodecs.c:995
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition avcodec.c:421
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition codec_desc.h:116
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition options.c:164
@ AV_CODEC_ID_ASS
Definition codec_id.h:591
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition decode.c:939
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1588
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition demux.c:2616
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:377
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:233
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:60
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition dict.h:74
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition error.h:54
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition log.h:204
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
Definition log.c:459
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
Definition mem.c:433
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition avutil.h:204
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition avstring.c:179
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition avstring.c:208
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
static av_cold void uninit(AVBitStreamFilterContext *ctx)
const char * arg
Definition jacosubdec.c:65
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition filters.h:59
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
static const AVClass ass_class
Definition assenc.c:225
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
#define COMMON_OPTIONS
Definition libvpxenc.c:1986
Memory handling functions.
uint32_t tag
Definition movenc.c:2128
AVOptions.
AVColorRange
Visual content value range.
Definition pixfmt.h:753
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:771
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:788
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:711
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:713
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:718
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:716
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition pixfmt.h:719
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
This struct describes the properties of a single codec described by an AVCodecID.
Definition codec_desc.h:38
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition codec_desc.h:54
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
AVCodec.
Definition codec.h:175
An instance of a filter.
Definition avfilter.h:279
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
Format I/O context.
Definition avformat.h:1337
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1393
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1405
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:581
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
int width
Definition frame.h:551
int height
Definition frame.h:551
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:524
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
AVDictionary * metadata
Definition avformat.h:848
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
char * ass
0 terminated ASS/SSA compatible event line.
Definition avcodec.h:2099
uint32_t end_display_time
Definition avcodec.h:2105
unsigned num_rects
Definition avcodec.h:2106
AVSubtitleRect ** rects
Definition avcodec.h:2107
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition avcodec.h:2108
ASS_Renderer * renderer
char * force_style
char * fontsdir
int pix_step[4]
steps per pixel for each plane of the main output
char * filename
char * charenc
ASS_Library * library
ASS_Track * track
FFDrawContext draw
uint8_t rgba_map[4]
char * script
uint8_t level
Definition svq3.c:208
#define av_free(p)
#define av_log(a,...)
else temp
Definition vf_mcdeint.c:275
#define AA(c)
#define AR(c)
#define AG(c)
static void overlay_ass_image(AssContext *ass, AVFrame *picref, const ASS_Image *image)
static const int ass_libavfilter_log_level_map[]
static int config_input(AVFilterLink *inlink)
#define SHAPING_OPTIONS
static const AVFilterPad ass_inputs[]
static enum AVColorSpace ass_get_color_space(ASS_YCbCrMatrix ass_matrix, enum AVColorSpace inlink_space)
static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static av_cold void uninit(AVFilterContext *ctx)
#define OFFSET(x)
#define AB(c)
static enum AVColorRange ass_get_color_range(ASS_YCbCrMatrix ass_matrix, enum AVColorRange inlink_range)
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37