FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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.h"
33 #if CONFIG_SUBTITLES_FILTER
34 # include "libavcodec/avcodec.h"
35 # include "libavformat/avformat.h"
36 #endif
37 #include "libavutil/avstring.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/parseutils.h"
41 #include "drawutils.h"
42 #include "avfilter.h"
43 #include "internal.h"
44 #include "formats.h"
45 #include "video.h"
46 
47 typedef struct {
48  const AVClass *class;
49  ASS_Library *library;
50  ASS_Renderer *renderer;
51  ASS_Track *track;
52  char *filename;
53  char *fontsdir;
54  char *charenc;
55  char *force_style;
57  uint8_t rgba_map[4];
58  int pix_step[4]; ///< steps per pixel for each plane of the main output
59  int original_w, original_h;
60  int shaping;
62 } AssContext;
63 
64 #define OFFSET(x) offsetof(AssContext, x)
65 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
66 
67 #define COMMON_OPTIONS \
68  {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
69  {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
70  {"original_size", "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
71  {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
72 
73 /* libass supports a log level ranging from 0 to 7 */
74 static const int ass_libavfilter_log_level_map[] = {
75  [0] = AV_LOG_FATAL, /* MSGL_FATAL */
76  [1] = AV_LOG_ERROR, /* MSGL_ERR */
77  [2] = AV_LOG_WARNING, /* MSGL_WARN */
78  [3] = AV_LOG_WARNING, /* <undefined> */
79  [4] = AV_LOG_INFO, /* MSGL_INFO */
80  [5] = AV_LOG_INFO, /* <undefined> */
81  [6] = AV_LOG_VERBOSE, /* MSGL_V */
82  [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
83 };
84 
85 static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
86 {
87  const int ass_level_clip = av_clip(ass_level, 0,
89  const int level = ass_libavfilter_log_level_map[ass_level_clip];
90 
91  av_vlog(ctx, level, fmt, args);
92  av_log(ctx, level, "\n");
93 }
94 
96 {
97  AssContext *ass = ctx->priv;
98 
99  if (!ass->filename) {
100  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
101  return AVERROR(EINVAL);
102  }
103 
104  ass->library = ass_library_init();
105  if (!ass->library) {
106  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
107  return AVERROR(EINVAL);
108  }
109  ass_set_message_cb(ass->library, ass_log, ctx);
110 
111  ass_set_fonts_dir(ass->library, ass->fontsdir);
112 
113  ass->renderer = ass_renderer_init(ass->library);
114  if (!ass->renderer) {
115  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass renderer.\n");
116  return AVERROR(EINVAL);
117  }
118 
119  return 0;
120 }
121 
123 {
124  AssContext *ass = ctx->priv;
125 
126  if (ass->track)
127  ass_free_track(ass->track);
128  if (ass->renderer)
129  ass_renderer_done(ass->renderer);
130  if (ass->library)
131  ass_library_done(ass->library);
132 }
133 
135 {
137 }
138 
139 static int config_input(AVFilterLink *inlink)
140 {
141  AssContext *ass = inlink->dst->priv;
142 
143  ff_draw_init(&ass->draw, inlink->format, 0);
144 
145  ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
146  if (ass->original_w && ass->original_h)
147  ass_set_aspect_ratio(ass->renderer, (double)inlink->w / inlink->h,
148  (double)ass->original_w / ass->original_h);
149  if (ass->shaping != -1)
150  ass_set_shaper(ass->renderer, ass->shaping);
151 
152  return 0;
153 }
154 
155 /* libass stores an RGBA color in the format RRGGBBTT, where TT is the transparency level */
156 #define AR(c) ( (c)>>24)
157 #define AG(c) (((c)>>16)&0xFF)
158 #define AB(c) (((c)>>8) &0xFF)
159 #define AA(c) ((0xFF-(c)) &0xFF)
160 
161 static void overlay_ass_image(AssContext *ass, AVFrame *picref,
162  const ASS_Image *image)
163 {
164  for (; image; image = image->next) {
165  uint8_t rgba_color[] = {AR(image->color), AG(image->color), AB(image->color), AA(image->color)};
167  ff_draw_color(&ass->draw, &color, rgba_color);
168  ff_blend_mask(&ass->draw, &color,
169  picref->data, picref->linesize,
170  picref->width, picref->height,
171  image->bitmap, image->stride, image->w, image->h,
172  3, 0, image->dst_x, image->dst_y);
173  }
174 }
175 
176 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
177 {
178  AVFilterContext *ctx = inlink->dst;
179  AVFilterLink *outlink = ctx->outputs[0];
180  AssContext *ass = ctx->priv;
181  int detect_change = 0;
182  double time_ms = picref->pts * av_q2d(inlink->time_base) * 1000;
183  ASS_Image *image = ass_render_frame(ass->renderer, ass->track,
184  time_ms, &detect_change);
185 
186  if (detect_change)
187  av_log(ctx, AV_LOG_DEBUG, "Change happened at time ms:%f\n", time_ms);
188 
189  overlay_ass_image(ass, picref, image);
190 
191  return ff_filter_frame(outlink, picref);
192 }
193 
194 static const AVFilterPad ass_inputs[] = {
195  {
196  .name = "default",
197  .type = AVMEDIA_TYPE_VIDEO,
198  .filter_frame = filter_frame,
199  .config_props = config_input,
200  .needs_writable = 1,
201  },
202  { NULL }
203 };
204 
205 static const AVFilterPad ass_outputs[] = {
206  {
207  .name = "default",
208  .type = AVMEDIA_TYPE_VIDEO,
209  },
210  { NULL }
211 };
212 
213 #if CONFIG_ASS_FILTER
214 
215 static const AVOption ass_options[] = {
217  {"shaping", "set shaping engine", OFFSET(shaping), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, FLAGS, "shaping_mode"},
218  {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"},
219  {"simple", "simple shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"},
220  {"complex", "complex shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"},
221  {NULL},
222 };
223 
225 
226 static av_cold int init_ass(AVFilterContext *ctx)
227 {
228  AssContext *ass = ctx->priv;
229  int ret = init(ctx);
230 
231  if (ret < 0)
232  return ret;
233 
234  /* Initialize fonts */
235  ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
236 
237  ass->track = ass_read_file(ass->library, ass->filename, NULL);
238  if (!ass->track) {
239  av_log(ctx, AV_LOG_ERROR,
240  "Could not create a libass track when reading file '%s'\n",
241  ass->filename);
242  return AVERROR(EINVAL);
243  }
244  return 0;
245 }
246 
247 AVFilter ff_vf_ass = {
248  .name = "ass",
249  .description = NULL_IF_CONFIG_SMALL("Render ASS subtitles onto input video using the libass library."),
250  .priv_size = sizeof(AssContext),
251  .init = init_ass,
252  .uninit = uninit,
254  .inputs = ass_inputs,
255  .outputs = ass_outputs,
256  .priv_class = &ass_class,
257 };
258 #endif
259 
260 #if CONFIG_SUBTITLES_FILTER
261 
262 static const AVOption subtitles_options[] = {
264  {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
265  {"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
266  {"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
267  {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
268  {NULL},
269 };
270 
271 static const char * const font_mimetypes[] = {
272  "application/x-truetype-font",
273  "application/vnd.ms-opentype",
274  "application/x-font-ttf",
275  NULL
276 };
277 
278 static int attachment_is_font(AVStream * st)
279 {
280  const AVDictionaryEntry *tag = NULL;
281  int n;
282 
283  tag = av_dict_get(st->metadata, "mimetype", NULL, AV_DICT_MATCH_CASE);
284 
285  if (tag) {
286  for (n = 0; font_mimetypes[n]; n++) {
287  if (av_strcasecmp(font_mimetypes[n], tag->value) == 0)
288  return 1;
289  }
290  }
291  return 0;
292 }
293 
294 AVFILTER_DEFINE_CLASS(subtitles);
295 
296 static av_cold int init_subtitles(AVFilterContext *ctx)
297 {
298  int j, ret, sid;
299  int k = 0;
303  AVCodec *dec = NULL;
304  const AVCodecDescriptor *dec_desc;
305  AVStream *st;
306  AVPacket pkt;
307  AssContext *ass = ctx->priv;
308 
309  /* Init libass */
310  ret = init(ctx);
311  if (ret < 0)
312  return ret;
313  ass->track = ass_new_track(ass->library);
314  if (!ass->track) {
315  av_log(ctx, AV_LOG_ERROR, "Could not create a libass track\n");
316  return AVERROR(EINVAL);
317  }
318 
319  /* Open subtitles file */
320  ret = avformat_open_input(&fmt, ass->filename, NULL, NULL);
321  if (ret < 0) {
322  av_log(ctx, AV_LOG_ERROR, "Unable to open %s\n", ass->filename);
323  goto end;
324  }
325  ret = avformat_find_stream_info(fmt, NULL);
326  if (ret < 0)
327  goto end;
328 
329  /* Locate subtitles stream */
330  if (ass->stream_index < 0)
331  ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0);
332  else {
333  ret = -1;
334  if (ass->stream_index < fmt->nb_streams) {
335  for (j = 0; j < fmt->nb_streams; j++) {
337  if (ass->stream_index == k) {
338  ret = j;
339  break;
340  }
341  k++;
342  }
343  }
344  }
345  }
346 
347  if (ret < 0) {
348  av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n",
349  ass->filename);
350  goto end;
351  }
352  sid = ret;
353  st = fmt->streams[sid];
354 
355  /* Load attached fonts */
356  for (j = 0; j < fmt->nb_streams; j++) {
357  AVStream *st = fmt->streams[j];
359  attachment_is_font(st)) {
360  const AVDictionaryEntry *tag = NULL;
361  tag = av_dict_get(st->metadata, "filename", NULL,
363 
364  if (tag) {
365  av_log(ctx, AV_LOG_DEBUG, "Loading attached font: %s\n",
366  tag->value);
367  ass_add_font(ass->library, tag->value,
368  st->codecpar->extradata,
369  st->codecpar->extradata_size);
370  } else {
371  av_log(ctx, AV_LOG_WARNING,
372  "Font attachment has no filename, ignored.\n");
373  }
374  }
375  }
376 
377  /* Initialize fonts */
378  ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
379 
380  /* Open decoder */
382  if (!dec) {
383  av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n",
385  return AVERROR(EINVAL);
386  }
387  dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
388  if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
389  av_log(ctx, AV_LOG_ERROR,
390  "Only text based subtitles are currently supported\n");
391  return AVERROR_PATCHWELCOME;
392  }
393  if (ass->charenc)
394  av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
395  if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,26,100))
396  av_dict_set(&codec_opts, "sub_text_format", "ass", 0);
397 
398  dec_ctx = avcodec_alloc_context3(dec);
399  if (!dec_ctx)
400  return AVERROR(ENOMEM);
401 
402  ret = avcodec_parameters_to_context(dec_ctx, st->codecpar);
403  if (ret < 0)
404  goto end;
405 
406  /*
407  * This is required by the decoding process in order to rescale the
408  * timestamps: in the current API the decoded subtitles have their pts
409  * expressed in AV_TIME_BASE, and thus the lavc internals need to know the
410  * stream time base in order to achieve the rescaling.
411  *
412  * That API is old and needs to be reworked to match behaviour with A/V.
413  */
414  av_codec_set_pkt_timebase(dec_ctx, st->time_base);
415 
416  ret = avcodec_open2(dec_ctx, NULL, &codec_opts);
417  if (ret < 0)
418  goto end;
419 
420  if (ass->force_style) {
421  char **list = NULL;
422  char *temp = NULL;
423  char *ptr = av_strtok(ass->force_style, ",", &temp);
424  int i = 0;
425  while (ptr) {
426  av_dynarray_add(&list, &i, ptr);
427  if (!list) {
428  ret = AVERROR(ENOMEM);
429  goto end;
430  }
431  ptr = av_strtok(NULL, ",", &temp);
432  }
433  av_dynarray_add(&list, &i, NULL);
434  if (!list) {
435  ret = AVERROR(ENOMEM);
436  goto end;
437  }
438  ass_set_style_overrides(ass->library, list);
439  av_free(list);
440  }
441  /* Decode subtitles and push them into the renderer (libass) */
442  if (dec_ctx->subtitle_header)
443  ass_process_codec_private(ass->track,
444  dec_ctx->subtitle_header,
445  dec_ctx->subtitle_header_size);
446  av_init_packet(&pkt);
447  pkt.data = NULL;
448  pkt.size = 0;
449  while (av_read_frame(fmt, &pkt) >= 0) {
450  int i, got_subtitle;
451  AVSubtitle sub = {0};
452 
453  if (pkt.stream_index == sid) {
454  ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
455  if (ret < 0) {
456  av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
457  av_err2str(ret));
458  } else if (got_subtitle) {
459  const int64_t start_time = av_rescale_q(sub.pts, AV_TIME_BASE_Q, av_make_q(1, 1000));
460  const int64_t duration = sub.end_display_time;
461  for (i = 0; i < sub.num_rects; i++) {
462  char *ass_line = sub.rects[i]->ass;
463  if (!ass_line)
464  break;
465  if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,25,100))
466  ass_process_data(ass->track, ass_line, strlen(ass_line));
467  else
468  ass_process_chunk(ass->track, ass_line, strlen(ass_line),
469  start_time, duration);
470  }
471  }
472  }
473  av_packet_unref(&pkt);
474  avsubtitle_free(&sub);
475  }
476 
477 end:
478  av_dict_free(&codec_opts);
479  avcodec_close(dec_ctx);
480  avcodec_free_context(&dec_ctx);
481  avformat_close_input(&fmt);
482  return ret;
483 }
484 
485 AVFilter ff_vf_subtitles = {
486  .name = "subtitles",
487  .description = NULL_IF_CONFIG_SMALL("Render text subtitles onto input video using the libass library."),
488  .priv_size = sizeof(AssContext),
489  .init = init_subtitles,
490  .uninit = uninit,
492  .inputs = ass_inputs,
493  .outputs = ass_outputs,
494  .priv_class = &subtitles_class,
495 };
496 #endif
static void overlay_ass_image(AssContext *ass, AVFrame *picref, const ASS_Image *image)
Definition: vf_subtitles.c:161
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:717
#define NULL
Definition: coverity.c:32
static int config_input(AVFilterLink *inlink)
Definition: vf_subtitles.c:139
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
FFDrawContext draw
Definition: vf_subtitles.c:61
AVOption.
Definition: opt.h:245
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Definition: vf_subtitles.c:176
const char * fmt
Definition: avisynth_c.h:769
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
Main libavfilter public API header.
ASS_Track * track
Definition: vf_subtitles.c:51
else temp
Definition: vf_mcdeint.c:259
static const AVClass ass_class
Definition: assenc.c:223
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3953
void av_codec_set_pkt_timebase(AVCodecContext *avctx, AVRational val)
int size
Definition: avcodec.h:1591
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: avcodec.h:723
unsigned num_rects
Definition: avcodec.h:3933
static AVPacket pkt
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:2588
AVCodec.
Definition: avcodec.h:3573
static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
Definition: vf_subtitles.c:85
AVSubtitleRect ** rects
Definition: avcodec.h:3934
Format I/O context.
Definition: avformat.h:1327
const char * name
Pad name.
Definition: internal.h:59
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1180
static int query_formats(AVFilterContext *ctx)
Definition: vf_subtitles.c:134
static int64_t start_time
Definition: ffplay.c:330
uint8_t
#define av_cold
Definition: attributes.h:82
ASS_Library * library
Definition: vf_subtitles.c:49
AVOptions.
int subtitle_header_size
Definition: avcodec.h:3295
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:268
#define LIBAVCODEC_VERSION_INT
Definition: version.h:34
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1395
int64_t duration
Definition: movenc.c:63
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:4140
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:40
uint8_t * data
Definition: avcodec.h:1590
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
uint32_t tag
Definition: movenc.c:1376
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:53
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
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
Definition: utils.c:3878
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:2958
#define AA(c)
Definition: vf_subtitles.c:159
int width
width and height of the video frame
Definition: frame.h:236
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:69
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
void * priv
private data for use by the filter
Definition: avfilter.h:322
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3949
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:221
#define AV_VERSION_INT(a, b, c)
Definition: version.h:41
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2971
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3971
uint32_t end_display_time
Definition: avcodec.h:3932
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:3935
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:675
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1383
int stream_index
Definition: vf_subtitles.c:56
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:213
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:156
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
AVFormatContext * ctx
Definition: movenc.c:48
int n
Definition: avisynth_c.h:684
AVDictionary * metadata
Definition: avformat.h:947
Opaque data information usually sparse.
Definition: avutil.h:199
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
#define FF_ARRAY_ELEMS(a)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:3081
Stream structure.
Definition: avformat.h:878
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
char * fontsdir
Definition: vf_subtitles.c:53
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:608
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
Libavcodec external API header.
misc drawing utilities
#define AG(c)
Definition: vf_subtitles.c:157
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:171
ASS_Renderer * renderer
Definition: vf_subtitles.c:50
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:254
static const int ass_libavfilter_log_level_map[]
Definition: vf_subtitles.c:74
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
main external API structure.
Definition: avcodec.h:1659
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:3062
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:563
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:2693
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:70
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
char * filename
Definition: vf_subtitles.c:52
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:379
const char * name
Filter name.
Definition: avfilter.h:148
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:176
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:1208
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:319
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1644
#define AB(c)
Definition: vf_subtitles.c:158
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:659
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
uint8_t level
Definition: svq3.c:206
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:184
static av_cold int init(AVFilterContext *ctx)
Definition: vf_subtitles.c:95
Main libavformat public API header.
AVDictionary * codec_opts
Definition: cmdutils.c:69
#define OFFSET(x)
Definition: vf_subtitles.c:64
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: utils.c:3283
#define FLAGS
Definition: vf_subtitles.c:65
static AVCodecContext * dec_ctx
static const AVFilterPad ass_inputs[]
Definition: vf_subtitles.c:194
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: utils.c:4109
#define COMMON_OPTIONS
Definition: vf_subtitles.c:67
#define av_free(p)
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:324
char * value
Definition: dict.h:87
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_subtitles.c:122
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:339
char * force_style
Definition: vf_subtitles.c:55
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3924
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:471
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3967
An instance of a filter.
Definition: avfilter.h:307
int height
Definition: frame.h:236
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:170
AVCodecParameters * codecpar
Definition: avformat.h:1230
char * charenc
Definition: vf_subtitles.c:54
int stream_index
Definition: avcodec.h:1592
internal API functions
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:915
This structure stores compressed data.
Definition: avcodec.h:1567
static const AVFilterPad ass_outputs[]
Definition: vf_subtitles.c:205
int original_w
Definition: vf_subtitles.c:59
#define AR(c)
Definition: vf_subtitles.c:156
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:3294
int original_h
Definition: vf_subtitles.c:59