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.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 AssContext {
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  int alpha;
58  uint8_t rgba_map[4];
59  int pix_step[4]; ///< steps per pixel for each plane of the main output
61  int shaping;
63 } AssContext;
64 
65 #define OFFSET(x) offsetof(AssContext, x)
66 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
67 
68 #define COMMON_OPTIONS \
69  {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
70  {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
71  {"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 }, \
72  {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
73  {"alpha", "enable processing of alpha channel", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, \
74 
75 /* libass supports a log level ranging from 0 to 7 */
76 static const int ass_libavfilter_log_level_map[] = {
77  [0] = AV_LOG_FATAL, /* MSGL_FATAL */
78  [1] = AV_LOG_ERROR, /* MSGL_ERR */
79  [2] = AV_LOG_WARNING, /* MSGL_WARN */
80  [3] = AV_LOG_WARNING, /* <undefined> */
81  [4] = AV_LOG_INFO, /* MSGL_INFO */
82  [5] = AV_LOG_INFO, /* <undefined> */
83  [6] = AV_LOG_VERBOSE, /* MSGL_V */
84  [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
85 };
86 
87 static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
88 {
89  const int ass_level_clip = av_clip(ass_level, 0,
91  const int level = ass_libavfilter_log_level_map[ass_level_clip];
92 
93  av_vlog(ctx, level, fmt, args);
94  av_log(ctx, level, "\n");
95 }
96 
98 {
99  AssContext *ass = ctx->priv;
100 
101  if (!ass->filename) {
102  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
103  return AVERROR(EINVAL);
104  }
105 
106  ass->library = ass_library_init();
107  if (!ass->library) {
108  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
109  return AVERROR(EINVAL);
110  }
111  ass_set_message_cb(ass->library, ass_log, ctx);
112 
113  ass_set_fonts_dir(ass->library, ass->fontsdir);
114  ass_set_extract_fonts(ass->library, 1);
115 
116  ass->renderer = ass_renderer_init(ass->library);
117  if (!ass->renderer) {
118  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass renderer.\n");
119  return AVERROR(EINVAL);
120  }
121 
122  return 0;
123 }
124 
126 {
127  AssContext *ass = ctx->priv;
128 
129  if (ass->track)
130  ass_free_track(ass->track);
131  if (ass->renderer)
132  ass_renderer_done(ass->renderer);
133  if (ass->library)
134  ass_library_done(ass->library);
135 }
136 
138 {
140 }
141 
143 {
144  AssContext *ass = inlink->dst->priv;
145 
146  ff_draw_init(&ass->draw, inlink->format, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
147 
148  ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
149  if (ass->original_w && ass->original_h) {
150  ass_set_pixel_aspect(ass->renderer, (double)inlink->w / inlink->h /
151  ((double)ass->original_w / ass->original_h));
152  ass_set_storage_size(ass->renderer, ass->original_w, ass->original_h);
153  } else
154  ass_set_storage_size(ass->renderer, inlink->w, inlink->h);
155 
156  if (ass->shaping != -1)
157  ass_set_shaper(ass->renderer, ass->shaping);
158 
159  return 0;
160 }
161 
162 /* libass stores an RGBA color in the format RRGGBBTT, where TT is the transparency level */
163 #define AR(c) ( (c)>>24)
164 #define AG(c) (((c)>>16)&0xFF)
165 #define AB(c) (((c)>>8) &0xFF)
166 #define AA(c) ((0xFF-(c)) &0xFF)
167 
168 static void overlay_ass_image(AssContext *ass, AVFrame *picref,
169  const ASS_Image *image)
170 {
171  for (; image; image = image->next) {
172  uint8_t rgba_color[] = {AR(image->color), AG(image->color), AB(image->color), AA(image->color)};
174  ff_draw_color(&ass->draw, &color, rgba_color);
175  ff_blend_mask(&ass->draw, &color,
176  picref->data, picref->linesize,
177  picref->width, picref->height,
178  image->bitmap, image->stride, image->w, image->h,
179  3, 0, image->dst_x, image->dst_y);
180  }
181 }
182 
184 {
185  AVFilterContext *ctx = inlink->dst;
186  AVFilterLink *outlink = ctx->outputs[0];
187  AssContext *ass = ctx->priv;
188  int detect_change = 0;
189  double time_ms = picref->pts * av_q2d(inlink->time_base) * 1000;
190  ASS_Image *image = ass_render_frame(ass->renderer, ass->track,
191  time_ms, &detect_change);
192 
193  if (detect_change)
194  av_log(ctx, AV_LOG_DEBUG, "Change happened at time ms:%f\n", time_ms);
195 
196  overlay_ass_image(ass, picref, image);
197 
198  return ff_filter_frame(outlink, picref);
199 }
200 
201 static const AVFilterPad ass_inputs[] = {
202  {
203  .name = "default",
204  .type = AVMEDIA_TYPE_VIDEO,
206  .filter_frame = filter_frame,
207  .config_props = config_input,
208  },
209 };
210 
211 static const AVFilterPad ass_outputs[] = {
212  {
213  .name = "default",
214  .type = AVMEDIA_TYPE_VIDEO,
215  },
216 };
217 
218 #if CONFIG_ASS_FILTER
219 
220 static const AVOption ass_options[] = {
222  {"shaping", "set shaping engine", OFFSET(shaping), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, FLAGS, "shaping_mode"},
223  {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"},
224  {"simple", "simple shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"},
225  {"complex", "complex shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"},
226  {NULL},
227 };
228 
230 
231 static av_cold int init_ass(AVFilterContext *ctx)
232 {
233  AssContext *ass = ctx->priv;
234  int ret = init(ctx);
235 
236  if (ret < 0)
237  return ret;
238 
239  /* Initialize fonts */
240  ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
241 
242  ass->track = ass_read_file(ass->library, ass->filename, NULL);
243  if (!ass->track) {
245  "Could not create a libass track when reading file '%s'\n",
246  ass->filename);
247  return AVERROR(EINVAL);
248  }
249  return 0;
250 }
251 
252 const AVFilter ff_vf_ass = {
253  .name = "ass",
254  .description = NULL_IF_CONFIG_SMALL("Render ASS subtitles onto input video using the libass library."),
255  .priv_size = sizeof(AssContext),
256  .init = init_ass,
257  .uninit = uninit,
261  .priv_class = &ass_class,
262 };
263 #endif
264 
265 #if CONFIG_SUBTITLES_FILTER
266 
267 static const AVOption subtitles_options[] = {
269  {"charenc", "set input character encoding", OFFSET(charenc), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
270  {"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
271  {"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS},
272  {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
273  {NULL},
274 };
275 
276 static const char * const font_mimetypes[] = {
277  "application/x-truetype-font",
278  "application/vnd.ms-opentype",
279  "application/x-font-ttf",
280  NULL
281 };
282 
283 static int attachment_is_font(AVStream * st)
284 {
285  const AVDictionaryEntry *tag = NULL;
286  int n;
287 
288  tag = av_dict_get(st->metadata, "mimetype", NULL, AV_DICT_MATCH_CASE);
289 
290  if (tag) {
291  for (n = 0; font_mimetypes[n]; n++) {
292  if (av_strcasecmp(font_mimetypes[n], tag->value) == 0)
293  return 1;
294  }
295  }
296  return 0;
297 }
298 
299 AVFILTER_DEFINE_CLASS(subtitles);
300 
301 static av_cold int init_subtitles(AVFilterContext *ctx)
302 {
303  int j, ret, sid;
304  int k = 0;
306  AVFormatContext *fmt = NULL;
308  const AVCodec *dec;
309  const AVCodecDescriptor *dec_desc;
310  AVStream *st;
311  AVPacket pkt;
312  AssContext *ass = ctx->priv;
313 
314  /* Init libass */
315  ret = init(ctx);
316  if (ret < 0)
317  return ret;
318  ass->track = ass_new_track(ass->library);
319  if (!ass->track) {
320  av_log(ctx, AV_LOG_ERROR, "Could not create a libass track\n");
321  return AVERROR(EINVAL);
322  }
323 
324  /* Open subtitles file */
325  ret = avformat_open_input(&fmt, ass->filename, NULL, NULL);
326  if (ret < 0) {
327  av_log(ctx, AV_LOG_ERROR, "Unable to open %s\n", ass->filename);
328  goto end;
329  }
331  if (ret < 0)
332  goto end;
333 
334  /* Locate subtitles stream */
335  if (ass->stream_index < 0)
337  else {
338  ret = -1;
339  if (ass->stream_index < fmt->nb_streams) {
340  for (j = 0; j < fmt->nb_streams; j++) {
342  if (ass->stream_index == k) {
343  ret = j;
344  break;
345  }
346  k++;
347  }
348  }
349  }
350  }
351 
352  if (ret < 0) {
353  av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n",
354  ass->filename);
355  goto end;
356  }
357  sid = ret;
358  st = fmt->streams[sid];
359 
360  /* Load attached fonts */
361  for (j = 0; j < fmt->nb_streams; j++) {
362  AVStream *st = fmt->streams[j];
364  attachment_is_font(st)) {
365  const AVDictionaryEntry *tag = NULL;
366  tag = av_dict_get(st->metadata, "filename", NULL,
368 
369  if (tag) {
370  av_log(ctx, AV_LOG_DEBUG, "Loading attached font: %s\n",
371  tag->value);
372  ass_add_font(ass->library, tag->value,
373  st->codecpar->extradata,
374  st->codecpar->extradata_size);
375  } else {
377  "Font attachment has no filename, ignored.\n");
378  }
379  }
380  }
381 
382  /* Initialize fonts */
383  ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
384 
385  /* Open decoder */
387  if (!dec) {
388  av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n",
391  goto end;
392  }
393  dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
394  if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
396  "Only text based subtitles are currently supported\n");
398  goto end;
399  }
400  if (ass->charenc)
401  av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
402 
404  if (!dec_ctx) {
405  ret = AVERROR(ENOMEM);
406  goto end;
407  }
408 
410  if (ret < 0)
411  goto end;
412 
413  /*
414  * This is required by the decoding process in order to rescale the
415  * timestamps: in the current API the decoded subtitles have their pts
416  * expressed in AV_TIME_BASE, and thus the lavc internals need to know the
417  * stream time base in order to achieve the rescaling.
418  *
419  * That API is old and needs to be reworked to match behaviour with A/V.
420  */
422 
424  if (ret < 0)
425  goto end;
426 
427  if (ass->force_style) {
428  char **list = NULL;
429  char *temp = NULL;
430  char *ptr = av_strtok(ass->force_style, ",", &temp);
431  int i = 0;
432  while (ptr) {
433  av_dynarray_add(&list, &i, ptr);
434  if (!list) {
435  ret = AVERROR(ENOMEM);
436  goto end;
437  }
438  ptr = av_strtok(NULL, ",", &temp);
439  }
440  av_dynarray_add(&list, &i, NULL);
441  if (!list) {
442  ret = AVERROR(ENOMEM);
443  goto end;
444  }
445  ass_set_style_overrides(ass->library, list);
446  av_free(list);
447  }
448  /* Decode subtitles and push them into the renderer (libass) */
450  ass_process_codec_private(ass->track,
453  while (av_read_frame(fmt, &pkt) >= 0) {
454  int i, got_subtitle;
455  AVSubtitle sub = {0};
456 
457  if (pkt.stream_index == sid) {
458  ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
459  if (ret < 0) {
460  av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
461  av_err2str(ret));
462  } else if (got_subtitle) {
463  const int64_t start_time = av_rescale_q(sub.pts, AV_TIME_BASE_Q, av_make_q(1, 1000));
464  const int64_t duration = sub.end_display_time;
465  for (i = 0; i < sub.num_rects; i++) {
466  char *ass_line = sub.rects[i]->ass;
467  if (!ass_line)
468  break;
469  ass_process_chunk(ass->track, ass_line, strlen(ass_line),
471  }
472  }
473  }
476  }
477 
478 end:
481  avformat_close_input(&fmt);
482  return ret;
483 }
484 
485 const 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,
494  .priv_class = &subtitles_class,
495 };
496 #endif
AVSubtitle
Definition: avcodec.h:2289
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:424
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:424
AVCodec
AVCodec.
Definition: codec.h:202
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
FFDrawColor
Definition: drawutils.h:48
level
uint8_t level
Definition: svq3.c:204
ass_outputs
static const AVFilterPad ass_outputs[]
Definition: vf_subtitles.c:211
av_clip
#define av_clip
Definition: common.h:96
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
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
AssContext::alpha
int alpha
Definition: vf_subtitles.c:57
color
Definition: vf_paletteuse.c:599
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_subtitles.c:142
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
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1268
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:424
AVFrame::width
int width
Definition: frame.h:389
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:805
AVOption
AVOption.
Definition: opt.h:247
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:1683
ass_log
static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
Definition: vf_subtitles.c:87
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
AVDictionary
Definition: dict.c:30
AR
#define AR(c)
Definition: vf_subtitles.c:163
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1412
video.h
AssContext::track
ASS_Track * track
Definition: vf_subtitles.c:51
AA
#define AA(c)
Definition: vf_subtitles.c:166
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:338
formats.h
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)
Find the "best" stream in the file.
Definition: utils.c:500
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:355
AssContext::original_h
int original_h
Definition: vf_subtitles.c:60
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_subtitles.c:137
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:517
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:425
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
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:699
AssContext::fontsdir
char * fontsdir
Definition: vf_subtitles.c:53
duration
int64_t duration
Definition: movenc.c:64
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:207
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:40
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:141
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
AssContext::rgba_map
uint8_t rgba_map[4]
Definition: vf_subtitles.c:58
AssContext::force_style
char * force_style
Definition: vf_subtitles.c:55
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:186
FF_DRAW_PROCESS_ALPHA
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
Definition: drawutils.h:60
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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:141
ff_draw_init
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:79
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
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:1200
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1095
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
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:965
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:222
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:156
AVCodecContext::subtitle_header_size
int subtitle_header_size
Definition: avcodec.h:1684
parseutils.h
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
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1006
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:137
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:921
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1256
codec_opts
AVDictionary * codec_opts
Definition: cmdutils.c:71
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:2388
AssContext::renderer
ASS_Renderer * renderer
Definition: vf_subtitles.c:50
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:117
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:336
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:121
start_time
static int64_t start_time
Definition: ffplay.c:330
AssContext::filename
char * filename
Definition: vf_subtitles.c:52
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1724
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:92
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:59
AssContext
Definition: vf_subtitles.c:47
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:203
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
internal.h
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:326
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:443
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: codec_par.c:147
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:630
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
FFDrawContext
Definition: drawutils.h:35
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
COMMON_OPTIONS
#define COMMON_OPTIONS
Definition: vf_subtitles.c:68
ff_draw_color
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:141
avcodec.h
AssContext::library
ASS_Library * library
Definition: vf_subtitles.c:49
AVFilter
Filter definition.
Definition: avfilter.h:165
AssContext::charenc
char * charenc
Definition: vf_subtitles.c:54
tag
uint32_t tag
Definition: movenc.c:1596
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:935
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
ff_vf_subtitles
const AVFilter ff_vf_subtitles
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:102
ass_libavfilter_log_level_map
static const int ass_libavfilter_log_level_map[]
Definition: vf_subtitles.c:76
avformat.h
AssContext::original_w
int original_w
Definition: vf_subtitles.c:60
AssContext::stream_index
int stream_index
Definition: vf_subtitles.c:56
AV_DICT_MATCH_CASE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:67
AG
#define AG(c)
Definition: vf_subtitles.c:164
AVCodecContext
main external API structure.
Definition: avcodec.h:383
AVFrame::height
int height
Definition: frame.h:389
ff_vf_ass
const AVFilter ff_vf_ass
AssContext::draw
FFDrawContext draw
Definition: vf_subtitles.c:62
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_subtitles.c:97
temp
else temp
Definition: vf_mcdeint.c:248
AVPacket::stream_index
int stream_index
Definition: packet.h:375
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
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:168
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AB
#define AB(c)
Definition: vf_subtitles.c:165
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:79
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
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:70
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_subtitles.c:125
imgutils.h
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:362
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AssContext::shaping
int shaping
Definition: vf_subtitles.c:61
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Definition: vf_subtitles.c:183
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3521
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
drawutils.h
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
FLAGS
#define FLAGS
Definition: vf_subtitles.c:66
dec_ctx
static AVCodecContext * dec_ctx
Definition: filtering_audio.c:44
OFFSET
#define OFFSET(x)
Definition: vf_subtitles.c:65
ass_inputs
static const AVFilterPad ass_inputs[]
Definition: vf_subtitles.c:201
AVFILTERPAD_FLAG_NEEDS_WRITABLE
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition: internal.h:69