FFmpeg
dvdsubenc.c
Go to the documentation of this file.
1 /*
2  * DVD subtitle encoding
3  * Copyright (c) 2005 Wolfram Gloger
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #include "avcodec.h"
22 #include "bytestream.h"
23 #include "internal.h"
24 #include "libavutil/avassert.h"
25 #include "libavutil/bprint.h"
26 #include "libavutil/imgutils.h"
27 #include "libavutil/opt.h"
28 
29 typedef struct {
30  AVClass *class;
31  uint32_t global_palette[16];
32  char *palette_str;
35 
36 // ncnt is the nibble counter
37 #define PUTNIBBLE(val)\
38 do {\
39  if (ncnt++ & 1)\
40  *q++ = bitbuf | ((val) & 0x0f);\
41  else\
42  bitbuf = (val) << 4;\
43 } while(0)
44 
45 static void dvd_encode_rle(uint8_t **pq,
46  const uint8_t *bitmap, int linesize,
47  int w, int h,
48  const int cmap[256])
49 {
50  uint8_t *q;
51  unsigned int bitbuf = 0;
52  int ncnt;
53  int x, y, len, color;
54 
55  q = *pq;
56 
57  for (y = 0; y < h; ++y) {
58  ncnt = 0;
59  for(x = 0; x < w; x += len) {
60  color = bitmap[x];
61  for (len=1; x+len < w; ++len)
62  if (bitmap[x+len] != color)
63  break;
64  color = cmap[color];
65  av_assert0(color < 4);
66  if (len < 0x04) {
67  PUTNIBBLE((len << 2)|color);
68  } else if (len < 0x10) {
69  PUTNIBBLE(len >> 2);
70  PUTNIBBLE((len << 2)|color);
71  } else if (len < 0x40) {
72  PUTNIBBLE(0);
73  PUTNIBBLE(len >> 2);
74  PUTNIBBLE((len << 2)|color);
75  } else if (x+len == w) {
76  PUTNIBBLE(0);
77  PUTNIBBLE(0);
78  PUTNIBBLE(0);
80  } else {
81  if (len > 0xff)
82  len = 0xff;
83  PUTNIBBLE(0);
84  PUTNIBBLE(len >> 6);
85  PUTNIBBLE(len >> 2);
86  PUTNIBBLE((len << 2)|color);
87  }
88  }
89  /* end of line */
90  if (ncnt & 1)
91  PUTNIBBLE(0);
92  bitmap += linesize;
93  }
94 
95  *pq = q;
96 }
97 
98 static int color_distance(uint32_t a, uint32_t b)
99 {
100  int r = 0, d, i;
101  int alpha_a = 8, alpha_b = 8;
102 
103  for (i = 24; i >= 0; i -= 8) {
104  d = alpha_a * (int)((a >> i) & 0xFF) -
105  alpha_b * (int)((b >> i) & 0xFF);
106  r += d * d;
107  alpha_a = a >> 28;
108  alpha_b = b >> 28;
109  }
110  return r;
111 }
112 
113 /**
114  * Count colors used in a rectangle, quantizing alpha and grouping by
115  * nearest global palette entry.
116  */
117 static void count_colors(AVCodecContext *avctx, unsigned hits[33],
118  const AVSubtitleRect *r)
119 {
120  DVDSubtitleContext *dvdc = avctx->priv_data;
121  unsigned count[256] = { 0 };
122  uint32_t *palette = (uint32_t *)r->data[1];
123  uint32_t color;
124  int x, y, i, j, match, d, best_d, av_uninit(best_j);
125  uint8_t *p = r->data[0];
126 
127  for (y = 0; y < r->h; y++) {
128  for (x = 0; x < r->w; x++)
129  count[*(p++)]++;
130  p += r->linesize[0] - r->w;
131  }
132  for (i = 0; i < 256; i++) {
133  if (!count[i]) /* avoid useless search */
134  continue;
135  color = palette[i];
136  /* 0: transparent, 1-16: semi-transparent, 17-33 opaque */
137  match = color < 0x33000000 ? 0 : color < 0xCC000000 ? 1 : 17;
138  if (match) {
139  best_d = INT_MAX;
140  for (j = 0; j < 16; j++) {
141  d = color_distance(0xFF000000 | color,
142  0xFF000000 | dvdc->global_palette[j]);
143  if (d < best_d) {
144  best_d = d;
145  best_j = j;
146  }
147  }
148  match += best_j;
149  }
150  hits[match] += count[i];
151  }
152 }
153 
154 static void select_palette(AVCodecContext *avctx, int out_palette[4],
155  int out_alpha[4], unsigned hits[33])
156 {
157  DVDSubtitleContext *dvdc = avctx->priv_data;
158  int i, j, bright, mult;
159  uint32_t color;
160  int selected[4] = { 0 };
161  uint32_t pseudopal[33] = { 0 };
162  uint32_t refcolor[3] = { 0x00000000, 0xFFFFFFFF, 0xFF000000 };
163 
164  /* Bonus for transparent: if the rectangle fits tightly the text, the
165  background color can be quite rare, but it would be ugly without it */
166  hits[0] *= 16;
167  /* Bonus for bright colors */
168  for (i = 0; i < 16; i++) {
169  if (!(hits[1 + i] + hits[17 + i]))
170  continue; /* skip unused colors to gain time */
171  color = dvdc->global_palette[i];
172  bright = 0;
173  for (j = 0; j < 3; j++, color >>= 8)
174  bright += (color & 0xFF) < 0x40 || (color & 0xFF) >= 0xC0;
175  mult = 2 + FFMIN(bright, 2);
176  hits[ 1 + i] *= mult;
177  hits[17 + i] *= mult;
178  }
179 
180  /* Select four most frequent colors */
181  for (i = 0; i < 4; i++) {
182  for (j = 0; j < 33; j++)
183  if (hits[j] > hits[selected[i]])
184  selected[i] = j;
185  hits[selected[i]] = 0;
186  }
187 
188  /* Order the colors like in most DVDs:
189  0: background, 1: foreground, 2: outline */
190  for (i = 0; i < 16; i++) {
191  pseudopal[ 1 + i] = 0x80000000 | dvdc->global_palette[i];
192  pseudopal[17 + i] = 0xFF000000 | dvdc->global_palette[i];
193  }
194  for (i = 0; i < 3; i++) {
195  int best_d = color_distance(refcolor[i], pseudopal[selected[i]]);
196  for (j = i + 1; j < 4; j++) {
197  int d = color_distance(refcolor[i], pseudopal[selected[j]]);
198  if (d < best_d) {
199  FFSWAP(int, selected[i], selected[j]);
200  best_d = d;
201  }
202  }
203  }
204 
205  /* Output */
206  for (i = 0; i < 4; i++) {
207  out_palette[i] = selected[i] ? (selected[i] - 1) & 0xF : 0;
208  out_alpha [i] = !selected[i] ? 0 : selected[i] < 17 ? 0x80 : 0xFF;
209  }
210 }
211 
212 static void build_color_map(AVCodecContext *avctx, int cmap[],
213  const uint32_t palette[],
214  const int out_palette[], unsigned int const out_alpha[])
215 {
216  DVDSubtitleContext *dvdc = avctx->priv_data;
217  int i, j, d, best_d;
218  uint32_t pseudopal[4];
219 
220  for (i = 0; i < 4; i++)
221  pseudopal[i] = (out_alpha[i] << 24) |
222  dvdc->global_palette[out_palette[i]];
223  for (i = 0; i < 256; i++) {
224  best_d = INT_MAX;
225  for (j = 0; j < 4; j++) {
226  d = color_distance(pseudopal[j], palette[i]);
227  if (d < best_d) {
228  cmap[i] = j;
229  best_d = d;
230  }
231  }
232  }
233 }
234 
235 static void copy_rectangle(AVSubtitleRect *dst, AVSubtitleRect *src, int cmap[])
236 {
237  int x, y;
238  uint8_t *p, *q;
239 
240  p = src->data[0];
241  q = dst->data[0] + (src->x - dst->x) +
242  (src->y - dst->y) * dst->linesize[0];
243  for (y = 0; y < src->h; y++) {
244  for (x = 0; x < src->w; x++)
245  *(q++) = cmap[*(p++)];
246  p += src->linesize[0] - src->w;
247  q += dst->linesize[0] - src->w;
248  }
249 }
250 
252  uint8_t *outbuf, int outbuf_size,
253  const AVSubtitle *h)
254 {
255  DVDSubtitleContext *dvdc = avctx->priv_data;
256  uint8_t *q, *qq;
257  int offset1, offset2;
258  int i, rects = h->num_rects, ret;
259  unsigned global_palette_hits[33] = { 0 };
260  int cmap[256];
261  int out_palette[4];
262  int out_alpha[4];
263  AVSubtitleRect vrect;
264  uint8_t *vrect_data = NULL;
265  int x2, y2;
266  int forced = 0;
267 
268  if (rects == 0 || !h->rects)
269  return AVERROR(EINVAL);
270  for (i = 0; i < rects; i++)
271  if (h->rects[i]->type != SUBTITLE_BITMAP) {
272  av_log(avctx, AV_LOG_ERROR, "Bitmap subtitle required\n");
273  return AVERROR(EINVAL);
274  }
275  /* Mark this subtitle forced if any of the rectangles is forced. */
276  for (i = 0; i < rects; i++)
277  if ((h->rects[i]->flags & AV_SUBTITLE_FLAG_FORCED) != 0) {
278  forced = 1;
279  break;
280  }
281 
282  vrect = *h->rects[0];
283 
284  if (rects > 1) {
285  /* DVD subtitles can have only one rectangle: build a virtual
286  rectangle containing all actual rectangles.
287  The data of the rectangles will be copied later, when the palette
288  is decided, because the rectangles may have different palettes. */
289  int xmin = h->rects[0]->x, xmax = xmin + h->rects[0]->w;
290  int ymin = h->rects[0]->y, ymax = ymin + h->rects[0]->h;
291  for (i = 1; i < rects; i++) {
292  xmin = FFMIN(xmin, h->rects[i]->x);
293  ymin = FFMIN(ymin, h->rects[i]->y);
294  xmax = FFMAX(xmax, h->rects[i]->x + h->rects[i]->w);
295  ymax = FFMAX(ymax, h->rects[i]->y + h->rects[i]->h);
296  }
297  vrect.x = xmin;
298  vrect.y = ymin;
299  vrect.w = xmax - xmin;
300  vrect.h = ymax - ymin;
301  if ((ret = av_image_check_size(vrect.w, vrect.h, 0, avctx)) < 0)
302  return ret;
303 
304  /* Count pixels outside the virtual rectangle as transparent */
305  global_palette_hits[0] = vrect.w * vrect.h;
306  for (i = 0; i < rects; i++)
307  global_palette_hits[0] -= h->rects[i]->w * h->rects[i]->h;
308  }
309 
310  for (i = 0; i < rects; i++)
311  count_colors(avctx, global_palette_hits, h->rects[i]);
312  select_palette(avctx, out_palette, out_alpha, global_palette_hits);
313 
314  if (rects > 1) {
315  if (!(vrect_data = av_calloc(vrect.w, vrect.h)))
316  return AVERROR(ENOMEM);
317  vrect.data [0] = vrect_data;
318  vrect.linesize[0] = vrect.w;
319  for (i = 0; i < rects; i++) {
320  build_color_map(avctx, cmap, (uint32_t *)h->rects[i]->data[1],
321  out_palette, out_alpha);
322  copy_rectangle(&vrect, h->rects[i], cmap);
323  }
324  for (i = 0; i < 4; i++)
325  cmap[i] = i;
326  } else {
327  build_color_map(avctx, cmap, (uint32_t *)h->rects[0]->data[1],
328  out_palette, out_alpha);
329  }
330 
331  av_log(avctx, AV_LOG_DEBUG, "Selected palette:");
332  for (i = 0; i < 4; i++)
333  av_log(avctx, AV_LOG_DEBUG, " 0x%06"PRIx32"@@%02x (0x%x,0x%x)",
334  dvdc->global_palette[out_palette[i]], out_alpha[i],
335  out_palette[i], out_alpha[i] >> 4);
336  av_log(avctx, AV_LOG_DEBUG, "\n");
337 
338  // encode data block
339  q = outbuf + 4;
340  offset1 = q - outbuf;
341  // worst case memory requirement: 1 nibble per pixel..
342  if ((q - outbuf) + vrect.w * vrect.h / 2 + 17 + 21 > outbuf_size) {
343  av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
345  goto fail;
346  }
347  dvd_encode_rle(&q, vrect.data[0], vrect.w * 2,
348  vrect.w, (vrect.h + 1) >> 1, cmap);
349  offset2 = q - outbuf;
350  dvd_encode_rle(&q, vrect.data[0] + vrect.w, vrect.w * 2,
351  vrect.w, vrect.h >> 1, cmap);
352 
353  if (dvdc->even_rows_fix && (vrect.h & 1)) {
354  // Work-around for some players that want the height to be even.
355  vrect.h++;
356  *q++ = 0x00; // 0x00 0x00 == empty row, i.e. fully transparent
357  *q++ = 0x00;
358  }
359 
360  // set data packet size
361  qq = outbuf + 2;
362  bytestream_put_be16(&qq, q - outbuf);
363 
364  // send start display command
365  bytestream_put_be16(&q, (h->start_display_time*90) >> 10);
366  bytestream_put_be16(&q, (q - outbuf) /*- 2 */ + 8 + 12 + 2);
367  *q++ = 0x03; // palette - 4 nibbles
368  *q++ = (out_palette[3] << 4) | out_palette[2];
369  *q++ = (out_palette[1] << 4) | out_palette[0];
370  *q++ = 0x04; // alpha - 4 nibbles
371  *q++ = (out_alpha[3] & 0xF0) | (out_alpha[2] >> 4);
372  *q++ = (out_alpha[1] & 0xF0) | (out_alpha[0] >> 4);
373 
374  // 12 bytes per rect
375  x2 = vrect.x + vrect.w - 1;
376  y2 = vrect.y + vrect.h - 1;
377 
378  *q++ = 0x05;
379  // x1 x2 -> 6 nibbles
380  *q++ = vrect.x >> 4;
381  *q++ = (vrect.x << 4) | ((x2 >> 8) & 0xf);
382  *q++ = x2;
383  // y1 y2 -> 6 nibbles
384  *q++ = vrect.y >> 4;
385  *q++ = (vrect.y << 4) | ((y2 >> 8) & 0xf);
386  *q++ = y2;
387 
388  *q++ = 0x06;
389  // offset1, offset2
390  bytestream_put_be16(&q, offset1);
391  bytestream_put_be16(&q, offset2);
392 
393  *q++ = forced ? 0x00 : 0x01; // start command
394  *q++ = 0xff; // terminating command
395 
396  // send stop display command last
397  bytestream_put_be16(&q, (h->end_display_time*90) >> 10);
398  bytestream_put_be16(&q, (q - outbuf) - 2 /*+ 4*/);
399  *q++ = 0x02; // set end
400  *q++ = 0xff; // terminating command
401 
402  qq = outbuf;
403  bytestream_put_be16(&qq, q - outbuf);
404 
405  av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%"PTRDIFF_SPECIFIER"\n", q - outbuf);
406  ret = q - outbuf;
407 
408 fail:
409  av_free(vrect_data);
410  return ret;
411 }
412 
413 static int bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
414 {
415  int ret;
416  char *str;
417 
418  ret = av_bprint_finalize(buf, &str);
419  if (ret < 0)
420  return ret;
421  if (!av_bprint_is_complete(buf)) {
422  av_free(str);
423  return AVERROR(ENOMEM);
424  }
425 
426  avctx->extradata = str;
427  /* Note: the string is NUL terminated (so extradata can be read as a
428  * string), but the ending character is not accounted in the size (in
429  * binary formats you are likely not supposed to mux that character). When
430  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
431  * zeros. */
432  avctx->extradata_size = buf->len;
433  return 0;
434 }
435 
436 static int dvdsub_init(AVCodecContext *avctx)
437 {
438  DVDSubtitleContext *dvdc = avctx->priv_data;
439  static const uint32_t default_palette[16] = {
440  0x000000, 0x0000FF, 0x00FF00, 0xFF0000,
441  0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF,
442  0x808000, 0x8080FF, 0x800080, 0x80FF80,
443  0x008080, 0xFF8080, 0x555555, 0xAAAAAA,
444  };
445  AVBPrint extradata;
446  int i, ret;
447 
448  av_assert0(sizeof(dvdc->global_palette) == sizeof(default_palette));
449  if (dvdc->palette_str) {
451  } else {
452  memcpy(dvdc->global_palette, default_palette, sizeof(dvdc->global_palette));
453  }
454 
456  if (avctx->width && avctx->height)
457  av_bprintf(&extradata, "size: %dx%d\n", avctx->width, avctx->height);
458  av_bprintf(&extradata, "palette:");
459  for (i = 0; i < 16; i++)
460  av_bprintf(&extradata, " %06"PRIx32"%c",
461  dvdc->global_palette[i] & 0xFFFFFF, i < 15 ? ',' : '\n');
462 
463  ret = bprint_to_extradata(avctx, &extradata);
464  if (ret < 0)
465  return ret;
466 
467  return 0;
468 }
469 
470 static int dvdsub_encode(AVCodecContext *avctx,
471  unsigned char *buf, int buf_size,
472  const AVSubtitle *sub)
473 {
474  //DVDSubtitleContext *s = avctx->priv_data;
475  int ret;
476 
477  ret = encode_dvd_subtitles(avctx, buf, buf_size, sub);
478  return ret;
479 }
480 
481 #define OFFSET(x) offsetof(DVDSubtitleContext, x)
482 #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
483 static const AVOption options[] = {
484  {"palette", "set the global palette", OFFSET(palette_str), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SE },
485  {"even_rows_fix", "Make number of rows even (workaround for some players)", OFFSET(even_rows_fix), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, SE},
486  { NULL },
487 };
488 
489 static const AVClass dvdsubenc_class = {
490  .class_name = "VOBSUB subtitle encoder",
491  .item_name = av_default_item_name,
492  .option = options,
493  .version = LIBAVUTIL_VERSION_INT,
494 };
495 
497  .name = "dvdsub",
498  .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
499  .type = AVMEDIA_TYPE_SUBTITLE,
501  .init = dvdsub_init,
502  .encode_sub = dvdsub_encode,
503  .priv_class = &dvdsubenc_class,
504  .priv_data_size = sizeof(DVDSubtitleContext),
505  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
506 };
AVSubtitle
Definition: avcodec.h:2289
options
static const AVOption options[]
Definition: dvdsubenc.c:483
AVCodec
AVCodec.
Definition: codec.h:202
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
r
const char * r
Definition: vf_curves.c:116
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
dvdsubenc_class
static const AVClass dvdsubenc_class
Definition: dvdsubenc.c:489
copy_rectangle
static void copy_rectangle(AVSubtitleRect *dst, AVSubtitleRect *src, int cmap[])
Definition: dvdsubenc.c:235
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:234
color
Definition: vf_paletteuse.c:599
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:68
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
ff_dvdsub_encoder
const AVCodec ff_dvdsub_encoder
Definition: dvdsubenc.c:496
ff_dvdsub_parse_palette
void ff_dvdsub_parse_palette(uint32_t *palette, const char *p)
Definition: dvdsub.c:26
AVSubtitleRect
Definition: avcodec.h:2261
w
uint8_t w
Definition: llviddspenc.c:38
internal.h
AVOption
AVOption.
Definition: opt.h:247
b
#define b
Definition: input.c:40
DVDSubtitleContext::global_palette
uint32_t global_palette[16]
Definition: dvdsubenc.c:31
AVSubtitleRect::linesize
int linesize[4]
Definition: avcodec.h:2273
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
count_colors
static void count_colors(AVCodecContext *avctx, unsigned hits[33], const AVSubtitleRect *r)
Count colors used in a rectangle, quantizing alpha and grouping by nearest global palette entry.
Definition: dvdsubenc.c:117
PUTNIBBLE
#define PUTNIBBLE(val)
Definition: dvdsubenc.c:37
fail
#define fail()
Definition: checkasm.h:127
select_palette
static void select_palette(AVCodecContext *avctx, int out_palette[4], int out_alpha[4], unsigned hits[33])
Definition: dvdsubenc.c:154
AVSubtitleRect::x
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2262
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
AVERROR_BUFFER_TOO_SMALL
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition: error.h:53
bprint_to_extradata
static int bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
Definition: dvdsubenc.c:413
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:56
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
encode_dvd_subtitles
static int encode_dvd_subtitles(AVCodecContext *avctx, uint8_t *outbuf, int outbuf_size, const AVSubtitle *h)
Definition: dvdsubenc.c:251
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:485
AVSubtitleRect::y
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2263
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
DVDSubtitleContext::palette_str
char * palette_str
Definition: dvdsubenc.c:32
AVSubtitleRect::w
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:2264
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
PTRDIFF_SPECIFIER
#define PTRDIFF_SPECIFIER
Definition: internal.h:192
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_DVD_SUBTITLE
@ AV_CODEC_ID_DVD_SUBTITLE
Definition: codec_id.h:522
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AVSubtitleRect::data
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2272
src
#define src
Definition: vp8dsp.c:255
dvdsub_encode
static int dvdsub_encode(AVCodecContext *avctx, unsigned char *buf, int buf_size, const AVSubtitle *sub)
Definition: dvdsubenc.c:470
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
DVDSubtitleContext
Definition: dvdsubenc.c:29
build_color_map
static void build_color_map(AVCodecContext *avctx, int cmap[], const uint32_t palette[], const int out_palette[], unsigned int const out_alpha[])
Definition: dvdsubenc.c:212
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
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:92
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_SUBTITLE_FLAG_FORCED
#define AV_SUBTITLE_FLAG_FORCED
Definition: avcodec.h:2259
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2244
bprint.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
dvd_encode_rle
static void dvd_encode_rle(uint8_t **pq, const uint8_t *bitmap, int linesize, int w, int h, const int cmap[256])
Definition: dvdsubenc.c:45
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:484
color_distance
static int color_distance(uint32_t a, uint32_t b)
Definition: dvdsubenc.c:98
SE
#define SE
Definition: dvdsubenc.c:482
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:209
len
int len
Definition: vorbis_enc_data.h:426
AVCodecContext::height
int height
Definition: avcodec.h:556
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
avcodec.h
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
ret
ret
Definition: filter_design.txt:187
AVSubtitleRect::h
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:2265
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:93
AVCodecContext
main external API structure.
Definition: avcodec.h:383
dvdsub_init
static int dvdsub_init(AVCodecContext *avctx)
Definition: dvdsubenc.c:436
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:410
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
DVDSubtitleContext::even_rows_fix
int even_rows_fix
Definition: dvdsubenc.c:33
d
d
Definition: ffmpeg_filter.c:153
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:556
bytestream.h
convert_header.str
string str
Definition: convert_header.py:20
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
OFFSET
#define OFFSET(x)
Definition: dvdsubenc.c:481
int
int
Definition: ffmpeg_filter.c:153