FFmpeg
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"
35 # include "libavcodec/codec_desc.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 
50 typedef struct AssContext {
51  const AVClass *class;
52  ASS_Library *library;
53  ASS_Renderer *renderer;
54  ASS_Track *track;
55  char *filename;
56  char *fontsdir;
57  char *charenc;
58  char *force_style;
60  int alpha;
61  uint8_t rgba_map[4];
62  int pix_step[4]; ///< steps per pixel for each plane of the main output
64  int shaping;
67 } AssContext;
68 
69 #define OFFSET(x) offsetof(AssContext, x)
70 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
71 
72 #define COMMON_OPTIONS \
73  {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
74  {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
75  {"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 }, \
76  {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
77  {"alpha", "enable processing of alpha channel", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, \
78 
79 #define SHAPING_OPTIONS \
80  {"shaping", "set shaping engine", OFFSET(shaping), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, FLAGS, .unit = "shaping_mode"}, \
81  {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS, .unit = "shaping_mode"}, \
82  {"simple", "simple shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX, FLAGS, .unit = "shaping_mode"}, \
83  {"complex", "complex shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX, FLAGS, .unit = "shaping_mode"}, \
84 
85 /* libass supports a log level ranging from 0 to 7 */
86 static const int ass_libavfilter_log_level_map[] = {
87  [0] = AV_LOG_FATAL, /* MSGL_FATAL */
88  [1] = AV_LOG_ERROR, /* MSGL_ERR */
89  [2] = AV_LOG_WARNING, /* MSGL_WARN */
90  [3] = AV_LOG_WARNING, /* <undefined> */
91  [4] = AV_LOG_INFO, /* MSGL_INFO */
92  [5] = AV_LOG_INFO, /* <undefined> */
93  [6] = AV_LOG_VERBOSE, /* MSGL_V */
94  [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
95 };
96 
97 static enum AVColorSpace ass_get_color_space(ASS_YCbCrMatrix ass_matrix, enum AVColorSpace inlink_space) {
98  switch (ass_matrix) {
99  case YCBCR_NONE: return inlink_space;
100  case YCBCR_SMPTE240M_TV:
101  case YCBCR_SMPTE240M_PC: return AVCOL_SPC_SMPTE240M;
102  case YCBCR_FCC_TV:
103  case YCBCR_FCC_PC: return AVCOL_SPC_FCC;
104  case YCBCR_BT709_TV:
105  case YCBCR_BT709_PC: return AVCOL_SPC_BT709;
106  case YCBCR_BT601_TV:
107  case YCBCR_BT601_PC:
108  case YCBCR_DEFAULT:
109  case YCBCR_UNKNOWN:
110  default: return AVCOL_SPC_SMPTE170M;
111  }
112 }
113 
114 static enum AVColorRange ass_get_color_range(ASS_YCbCrMatrix ass_matrix, enum AVColorRange inlink_range) {
115  switch (ass_matrix) {
116  case YCBCR_NONE: return inlink_range;
117  case YCBCR_SMPTE240M_PC:
118  case YCBCR_FCC_PC:
119  case YCBCR_BT709_PC:
120  case YCBCR_BT601_PC: return AVCOL_RANGE_JPEG;
121  case YCBCR_SMPTE240M_TV:
122  case YCBCR_FCC_TV:
123  case YCBCR_BT709_TV:
124  case YCBCR_BT601_TV:
125  case YCBCR_DEFAULT:
126  case YCBCR_UNKNOWN:
127  default: return AVCOL_RANGE_MPEG;
128  }
129 }
130 
131 static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
132 {
133  const int ass_level_clip = av_clip(ass_level, 0,
135  const int level = ass_libavfilter_log_level_map[ass_level_clip];
136 
137  av_vlog(ctx, level, fmt, args);
138  av_log(ctx, level, "\n");
139 }
140 
142 {
143  AssContext *ass = ctx->priv;
144 
145  if (!ass->filename) {
146  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
147  return AVERROR(EINVAL);
148  }
149 
150  ass->library = ass_library_init();
151  if (!ass->library) {
152  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
153  return AVERROR(EINVAL);
154  }
155  ass_set_message_cb(ass->library, ass_log, ctx);
156 
157  ass_set_fonts_dir(ass->library, ass->fontsdir);
158  ass_set_extract_fonts(ass->library, 1);
159 
160  ass->renderer = ass_renderer_init(ass->library);
161  if (!ass->renderer) {
162  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass renderer.\n");
163  return AVERROR(EINVAL);
164  }
165 
166  return 0;
167 }
168 
170 {
171  AssContext *ass = ctx->priv;
172 
173  if (ass->track)
174  ass_free_track(ass->track);
175  if (ass->renderer)
176  ass_renderer_done(ass->renderer);
177  if (ass->library)
178  ass_library_done(ass->library);
179 }
180 
182  AVFilterFormatsConfig **cfg_in,
183  AVFilterFormatsConfig **cfg_out)
184 {
185  return ff_set_common_formats2(ctx, cfg_in, cfg_out,
187 }
188 
190 {
191  AVFilterContext *ctx = inlink->dst;
192  AssContext *ass = ctx->priv;
193  int ret;
194 
195  ret = ff_draw_init2(&ass->draw, inlink->format,
196  ass_get_color_space(ass->track->YCbCrMatrix, inlink->colorspace),
197  ass_get_color_range(ass->track->YCbCrMatrix, inlink->color_range),
198  inlink->alpha_mode, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
199  if (ret < 0) {
200  av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
201  return ret;
202  }
203 
204  ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
205  if (ass->original_w && ass->original_h) {
206  ass_set_pixel_aspect(ass->renderer, (double)inlink->w / inlink->h /
207  ((double)ass->original_w / ass->original_h));
208  ass_set_storage_size(ass->renderer, ass->original_w, ass->original_h);
209  } else
210  ass_set_storage_size(ass->renderer, inlink->w, inlink->h);
211 
212  if (ass->shaping != -1)
213  ass_set_shaper(ass->renderer, ass->shaping);
214 
215  return 0;
216 }
217 
218 /* libass stores an RGBA color in the format RRGGBBTT, where TT is the transparency level */
219 #define AR(c) ( (c)>>24)
220 #define AG(c) (((c)>>16)&0xFF)
221 #define AB(c) (((c)>>8) &0xFF)
222 #define AA(c) ((0xFF-(c)) &0xFF)
223 
224 static void overlay_ass_image(AssContext *ass, AVFrame *picref,
225  const ASS_Image *image)
226 {
227  for (; image; image = image->next) {
228  uint8_t rgba_color[] = {AR(image->color), AG(image->color), AB(image->color), AA(image->color)};
230  ff_draw_color(&ass->draw, &color, rgba_color);
231  ff_blend_mask(&ass->draw, &color,
232  picref->data, picref->linesize,
233  picref->width, picref->height,
234  image->bitmap, image->stride, image->w, image->h,
235  3, 0, image->dst_x, image->dst_y);
236  }
237 }
238 
240 {
241  AVFilterContext *ctx = inlink->dst;
242  AVFilterLink *outlink = ctx->outputs[0];
243  AssContext *ass = ctx->priv;
244  int detect_change = 0;
245  double time_ms = picref->pts * av_q2d(inlink->time_base) * 1000;
246  ASS_Image *image = ass_render_frame(ass->renderer, ass->track,
247  time_ms, &detect_change);
248 
249  if (detect_change)
250  av_log(ctx, AV_LOG_DEBUG, "Change happened at time ms:%f\n", time_ms);
251 
252  overlay_ass_image(ass, picref, image);
253 
254  return ff_filter_frame(outlink, picref);
255 }
256 
257 static const AVFilterPad ass_inputs[] = {
258  {
259  .name = "default",
260  .type = AVMEDIA_TYPE_VIDEO,
262  .filter_frame = filter_frame,
263  .config_props = config_input,
264  },
265 };
266 
267 #if CONFIG_ASS_FILTER
268 
269 static const AVOption ass_options[] = {
272  {NULL},
273 };
274 
276 
277 static av_cold int init_ass(AVFilterContext *ctx)
278 {
279  AssContext *ass = ctx->priv;
280  int ret = init(ctx);
281 
282  if (ret < 0)
283  return ret;
284 
285  /* Initialize fonts */
286  ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
287 
288  ass->track = ass_read_file(ass->library, ass->filename, NULL);
289  if (!ass->track) {
291  "Could not create a libass track when reading file '%s'\n",
292  ass->filename);
293  return AVERROR(EINVAL);
294  }
295  return 0;
296 }
297 
298 const FFFilter ff_vf_ass = {
299  .p.name = "ass",
300  .p.description = NULL_IF_CONFIG_SMALL("Render ASS subtitles onto input video using the libass library."),
301  .p.priv_class = &ass_class,
302  .priv_size = sizeof(AssContext),
303  .init = init_ass,
304  .uninit = uninit,
308 };
309 #endif
310 
311 #if CONFIG_SUBTITLES_FILTER
312 
313 static const AVOption subtitles_options[] = {
315  {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
316  {"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
317  {"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
318  {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
319 #if FF_ASS_FEATURE_WRAP_UNICODE
320  {"wrap_unicode", "break lines according to the Unicode Line Breaking Algorithm", OFFSET(wrap_unicode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, FLAGS },
321 #endif
323  {NULL},
324 };
325 
326 static const char * const font_mimetypes[] = {
327  "font/ttf",
328  "font/otf",
329  "font/sfnt",
330  "font/woff",
331  "font/woff2",
332  "application/font-sfnt",
333  "application/font-woff",
334  "application/x-truetype-font",
335  "application/vnd.ms-opentype",
336  "application/x-font-ttf",
337  NULL
338 };
339 
340 static int attachment_is_font(AVStream * st)
341 {
342  const AVDictionaryEntry *tag = NULL;
343  int n;
344 
345  tag = av_dict_get(st->metadata, "mimetype", NULL, AV_DICT_MATCH_CASE);
346 
347  if (tag) {
348  for (n = 0; font_mimetypes[n]; n++) {
349  if (av_strcasecmp(font_mimetypes[n], tag->value) == 0)
350  return 1;
351  }
352  }
353  return 0;
354 }
355 
356 AVFILTER_DEFINE_CLASS(subtitles);
357 
358 static av_cold int init_subtitles(AVFilterContext *ctx)
359 {
360  int j, ret, sid;
361  int k = 0;
363  AVFormatContext *fmt = NULL;
365  const AVCodec *dec;
366  const AVCodecDescriptor *dec_desc;
367  AVStream *st;
368  AVPacket pkt;
369  AssContext *ass = ctx->priv;
370 
371  /* Init libass */
372  ret = init(ctx);
373  if (ret < 0)
374  return ret;
375  ass->track = ass_new_track(ass->library);
376  if (!ass->track) {
377  av_log(ctx, AV_LOG_ERROR, "Could not create a libass track\n");
378  return AVERROR(EINVAL);
379  }
380 
381  /* Open subtitles file */
382  ret = avformat_open_input(&fmt, ass->filename, NULL, NULL);
383  if (ret < 0) {
384  av_log(ctx, AV_LOG_ERROR, "Unable to open %s\n", ass->filename);
385  goto end;
386  }
388  if (ret < 0)
389  goto end;
390 
391  /* Locate subtitles stream */
392  if (ass->stream_index < 0)
394  else {
395  ret = -1;
396  if (ass->stream_index < fmt->nb_streams) {
397  for (j = 0; j < fmt->nb_streams; j++) {
399  if (ass->stream_index == k) {
400  ret = j;
401  break;
402  }
403  k++;
404  }
405  }
406  }
407  }
408 
409  if (ret < 0) {
410  av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n",
411  ass->filename);
412  goto end;
413  }
414  sid = ret;
415  st = fmt->streams[sid];
416 
417  /* Load attached fonts */
418  for (j = 0; j < fmt->nb_streams; j++) {
419  AVStream *st = fmt->streams[j];
421  attachment_is_font(st)) {
422  const AVDictionaryEntry *tag = NULL;
423  tag = av_dict_get(st->metadata, "filename", NULL,
425 
426  if (tag) {
427  av_log(ctx, AV_LOG_DEBUG, "Loading attached font: %s\n",
428  tag->value);
429  ass_add_font(ass->library, tag->value,
430  st->codecpar->extradata,
431  st->codecpar->extradata_size);
432  } else {
434  "Font attachment has no filename, ignored.\n");
435  }
436  }
437  }
438 
439  /* Initialize fonts */
440  ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
441 
442  /* Open decoder */
444  if (!dec) {
445  av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n",
448  goto end;
449  }
450  dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
451  if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
453  "Only text based subtitles are currently supported\n");
455  goto end;
456  }
457  if (ass->charenc)
458  av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
459 
461  if (!dec_ctx) {
462  ret = AVERROR(ENOMEM);
463  goto end;
464  }
465 
467  if (ret < 0)
468  goto end;
469 
470  /*
471  * This is required by the decoding process in order to rescale the
472  * timestamps: in the current API the decoded subtitles have their pts
473  * expressed in AV_TIME_BASE, and thus the lavc internals need to know the
474  * stream time base in order to achieve the rescaling.
475  *
476  * That API is old and needs to be reworked to match behaviour with A/V.
477  */
479 
481  if (ret < 0)
482  goto end;
483 
484 #if FF_ASS_FEATURE_WRAP_UNICODE
485  /* Don't overwrite wrap automatically for native ASS */
486  if (ass->wrap_unicode == -1)
488  if (ass->wrap_unicode) {
489  ret = ass_track_set_feature(ass->track, ASS_FEATURE_WRAP_UNICODE, 1);
490  if (ret < 0)
492  "libass wasn't built with ASS_FEATURE_WRAP_UNICODE support\n");
493  }
494 #endif
495 
496  if (ass->force_style) {
497  char **list = NULL;
498  char *temp = NULL;
499  char *ptr = av_strtok(ass->force_style, ",", &temp);
500  int i = 0;
501  while (ptr) {
502  av_dynarray_add(&list, &i, ptr);
503  if (!list) {
504  ret = AVERROR(ENOMEM);
505  goto end;
506  }
507  ptr = av_strtok(NULL, ",", &temp);
508  }
509  av_dynarray_add(&list, &i, NULL);
510  if (!list) {
511  ret = AVERROR(ENOMEM);
512  goto end;
513  }
514  ass_set_style_overrides(ass->library, list);
515  av_free(list);
516  }
517  /* Decode subtitles and push them into the renderer (libass) */
519  ass_process_codec_private(ass->track,
522  while (av_read_frame(fmt, &pkt) >= 0) {
523  int i, got_subtitle;
524  AVSubtitle sub = {0};
525 
526  if (pkt.stream_index == sid) {
527  ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
528  if (ret < 0) {
529  av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
530  av_err2str(ret));
531  } else if (got_subtitle) {
532  const int64_t start_time = av_rescale_q(sub.pts, AV_TIME_BASE_Q, av_make_q(1, 1000));
533  const int64_t duration = sub.end_display_time;
534  for (i = 0; i < sub.num_rects; i++) {
535  char *ass_line = sub.rects[i]->ass;
536  if (!ass_line)
537  break;
538  ass_process_chunk(ass->track, ass_line, strlen(ass_line),
540  }
541  }
542  }
544  avsubtitle_free(&sub);
545  }
546 
547 end:
550  avformat_close_input(&fmt);
551  return ret;
552 }
553 
554 const FFFilter ff_vf_subtitles = {
555  .p.name = "subtitles",
556  .p.description = NULL_IF_CONFIG_SMALL("Render text subtitles onto input video using the libass library."),
557  .p.priv_class = &subtitles_class,
558  .priv_size = sizeof(AssContext),
559  .init = init_subtitles,
560  .uninit = uninit,
564 };
565 #endif
AVSubtitle
Definition: avcodec.h:2087
av_vlog
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:460
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
AVCodec
AVCodec.
Definition: codec.h:169
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
ass_get_color_space
static enum AVColorSpace ass_get_color_space(ASS_YCbCrMatrix ass_matrix, enum AVColorSpace inlink_space)
Definition: vf_subtitles.c:97
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:71
FFDrawColor
Definition: drawutils.h:52
level
uint8_t level
Definition: svq3.c:208
av_clip
#define av_clip
Definition: common.h:100
dec_ctx
static AVCodecContext * dec_ctx
Definition: decode_filter_audio.c:45
AVERROR
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
AVSubtitle::rects
AVSubtitleRect ** rects
Definition: avcodec.h:2092
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:53
av_find_best_stream
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:500
ass_get_color_range
static enum AVColorRange ass_get_color_range(ASS_YCbCrMatrix ass_matrix, enum AVColorRange inlink_range)
Definition: vf_subtitles.c:114
AssContext::alpha
int alpha
Definition: vf_subtitles.c:60
color
Definition: vf_paletteuse.c:513
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1068
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1137
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_subtitles.c:189
av_cold
#define av_cold
Definition: attributes.h:119
int64_t
long long int64_t
Definition: coverity.c:34
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2091
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:208
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1382
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:568
AVFrame::width
int width
Definition: frame.h:538
ff_vf_subtitles
const FFFilter ff_vf_subtitles
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
AVOption
AVOption.
Definition: opt.h:428
filters.h
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1744
ass_log
static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
Definition: vf_subtitles.c:131
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AVDictionary
Definition: dict.c:32
AR
#define AR(c)
Definition: vf_subtitles.c:219
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:219
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1588
video.h
AssContext::track
ASS_Track * track
Definition: vf_subtitles.c:54
AA
#define AA(c)
Definition: vf_subtitles.c:222
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:487
formats.h
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:377
AV_CODEC_ID_ASS
@ AV_CODEC_ID_ASS
Definition: codec_id.h:587
AssContext::original_h
int original_h
Definition: vf_subtitles.c:63
ff_blend_mask
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:557
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:241
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2084
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:40
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:421
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:929
ff_draw_init2
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
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AssContext::fontsdir
char * fontsdir
Definition: vf_subtitles.c:56
ff_video_default_filterpad
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
FFFilter
Definition: filters.h:267
avformat_open_input
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
av_dict_get
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
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:265
AssContext::rgba_map
uint8_t rgba_map[4]
Definition: vf_subtitles.c:61
AssContext::force_style
char * force_style
Definition: vf_subtitles.c:58
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:707
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
av_strtok
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
FF_DRAW_PROCESS_ALPHA
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
Definition: drawutils.h:64
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2093
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1314
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:770
AVCodecParameters::avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:786
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
ass_class
static const AVClass ass_class
Definition: assenc.c:225
avcodec_free_context
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
AVCodecContext::subtitle_header_size
int subtitle_header_size
Header containing style information for text subtitles.
Definition: avcodec.h:1743
list
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 list
Definition: filter_design.txt:25
AVFILTERPAD_FLAG_NEEDS_WRITABLE
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition: filters.h:59
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:827
avcodec_open2
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
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:120
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:988
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:75
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1370
codec_opts
AVDictionary * codec_opts
Definition: cmdutils.c:58
avformat_find_stream_info
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: demux.c:2607
AssContext::renderer
ASS_Renderer * renderer
Definition: vf_subtitles.c:53
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:88
av_dynarray_add
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:329
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
start_time
static int64_t start_time
Definition: ffplay.c:328
AssContext::filename
char * filename
Definition: vf_subtitles.c:55
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:554
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:98
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AssContext::pix_step
int pix_step[4]
steps per pixel for each plane of the main output
Definition: vf_subtitles.c:62
AssContext
Definition: vf_subtitles.c:50
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2090
AssContext::wrap_unicode
int wrap_unicode
Definition: vf_subtitles.c:66
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:233
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition: pixfmt.h:708
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:406
ff_draw_supported_pixel_formats
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:670
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:700
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:204
FFDrawContext
Definition: drawutils.h:36
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:46
COMMON_OPTIONS
#define COMMON_OPTIONS
Definition: vf_subtitles.c:72
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
ff_draw_color
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:179
avcodec.h
AssContext::library
ASS_Library * library
Definition: vf_subtitles.c:52
AssContext::charenc
char * charenc
Definition: vf_subtitles.c:57
tag
uint32_t tag
Definition: movenc.c:2054
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:747
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:116
ass_libavfilter_log_level_map
static const int ass_libavfilter_log_level_map[]
Definition: vf_subtitles.c:86
avformat.h
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:264
AssContext::original_w
int original_w
Definition: vf_subtitles.c:63
AssContext::stream_index
int stream_index
Definition: vf_subtitles.c:59
AV_DICT_MATCH_CASE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:74
AG
#define AG(c)
Definition: vf_subtitles.c:220
AVCodecContext
main external API structure.
Definition: avcodec.h:443
AVFrame::height
int height
Definition: frame.h:538
AssContext::draw
FFDrawContext draw
Definition: vf_subtitles.c:65
AVCOL_SPC_FCC
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:705
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
avfilter.h
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_subtitles.c:141
temp
else temp
Definition: vf_mcdeint.c:271
AVPacket::stream_index
int stream_index
Definition: packet.h:605
AVFilterContext
An instance of a filter.
Definition: avfilter.h:273
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
overlay_ass_image
static void overlay_ass_image(AssContext *ass, AVFrame *picref, const ASS_Image *image)
Definition: vf_subtitles.c:224
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:271
mem.h
AB
#define AB(c)
Definition: vf_subtitles.c:221
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:57
AVPacket
This structure stores compressed data.
Definition: packet.h:580
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:326
av_dict_set
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
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_subtitles.c:169
AVFrame::linesize
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:511
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AssContext::shaping
int shaping
Definition: vf_subtitles.c:64
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Definition: vf_subtitles.c:239
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3878
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
avstring.h
AV_OPT_TYPE_STRING
@ 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
ff_vf_ass
const FFFilter ff_vf_ass
drawutils.h
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: filters.h:478
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:702
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:742
codec_desc.h
SHAPING_OPTIONS
#define SHAPING_OPTIONS
Definition: vf_subtitles.c:79
FLAGS
#define FLAGS
Definition: vf_subtitles.c:70
duration
static int64_t duration
Definition: ffplay.c:329
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_subtitles.c:181
OFFSET
#define OFFSET(x)
Definition: vf_subtitles.c:69
ass_inputs
static const AVFilterPad ass_inputs[]
Definition: vf_subtitles.c:257