]> git.sesse.net Git - ffmpeg/blob - libavcodec/libzvbi-teletextdec.c
Merge commit '9c0bc1e980a99106d6749ec632f166b87275871e'
[ffmpeg] / libavcodec / libzvbi-teletextdec.c
1 /*
2  * Teletext decoding for ffmpeg
3  * Copyright (c) 2005-2010, 2012 Wolfram Gloger
4  * Copyright (c) 2013 Marton Balint
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "avcodec.h"
22 #include "libavcodec/ass.h"
23 #include "libavcodec/dvbtxt.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/bprint.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/log.h"
29
30 #include <libzvbi.h>
31
32 #define TEXT_MAXSZ    (25 * (56 + 1) * 4 + 2)
33 #define VBI_NB_COLORS 40
34 #define VBI_TRANSPARENT_BLACK 8
35 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
36 #define VBI_R(rgba)   (((rgba) >> 0) & 0xFF)
37 #define VBI_G(rgba)   (((rgba) >> 8) & 0xFF)
38 #define VBI_B(rgba)   (((rgba) >> 16) & 0xFF)
39 #define VBI_A(rgba)   (((rgba) >> 24) & 0xFF)
40 #define MAX_BUFFERED_PAGES 25
41 #define BITMAP_CHAR_WIDTH  12
42 #define BITMAP_CHAR_HEIGHT 10
43 #define MAX_SLICES 64
44
45 typedef struct TeletextPage
46 {
47     AVSubtitleRect *sub_rect;
48     int pgno;
49     int subno;
50     int64_t pts;
51 } TeletextPage;
52
53 typedef struct TeletextContext
54 {
55     AVClass        *class;
56     char           *pgno;
57     int             x_offset;
58     int             y_offset;
59     int             format_id; /* 0 = bitmap, 1 = text/ass */
60     int             chop_top;
61     int             sub_duration; /* in msec */
62     int             transparent_bg;
63     int             opacity;
64     int             chop_spaces;
65
66     int             lines_processed;
67     TeletextPage    *pages;
68     int             nb_pages;
69     int64_t         pts;
70     int             handler_ret;
71
72     vbi_decoder *   vbi;
73 #ifdef DEBUG
74     vbi_export *    ex;
75 #endif
76     vbi_sliced      sliced[MAX_SLICES];
77 } TeletextContext;
78
79 static int chop_spaces_utf8(const unsigned char* t, int len)
80 {
81     t += len;
82     while (len > 0) {
83         if (*--t != ' ' || (len-1 > 0 && *(t-1) & 0x80))
84             break;
85         --len;
86     }
87     return len;
88 }
89
90 static void subtitle_rect_free(AVSubtitleRect **sub_rect)
91 {
92     av_freep(&(*sub_rect)->data[0]);
93     av_freep(&(*sub_rect)->data[1]);
94     av_freep(&(*sub_rect)->ass);
95     av_freep(sub_rect);
96 }
97
98 static int create_ass_text(TeletextContext *ctx, const char *text, char **ass)
99 {
100     int ret;
101     AVBPrint buf, buf2;
102     const int ts_start    = av_rescale_q(ctx->pts,          AV_TIME_BASE_Q,        (AVRational){1, 100});
103     const int ts_duration = av_rescale_q(ctx->sub_duration, (AVRational){1, 1000}, (AVRational){1, 100});
104
105     /* First we escape the plain text into buf. */
106     av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
107     ff_ass_bprint_text_event(&buf, text, strlen(text), "", 0);
108     av_bprintf(&buf, "\r\n");
109
110     if (!av_bprint_is_complete(&buf)) {
111         av_bprint_finalize(&buf, NULL);
112         return AVERROR(ENOMEM);
113     }
114
115     /* Then we create the ass dialog line in buf2 from the escaped text in buf. */
116     av_bprint_init(&buf2, 0, AV_BPRINT_SIZE_UNLIMITED);
117     ff_ass_bprint_dialog(&buf2, buf.str, ts_start, ts_duration, 0);
118     av_bprint_finalize(&buf, NULL);
119
120     if (!av_bprint_is_complete(&buf2)) {
121         av_bprint_finalize(&buf2, NULL);
122         return AVERROR(ENOMEM);
123     }
124
125     if ((ret = av_bprint_finalize(&buf2, ass)) < 0)
126         return ret;
127
128     return 0;
129 }
130
131 /* Draw a page as text */
132 static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
133 {
134     const char *in;
135     AVBPrint buf;
136     char *vbi_text = av_malloc(TEXT_MAXSZ);
137     int sz;
138
139     if (!vbi_text)
140         return AVERROR(ENOMEM);
141
142     sz = vbi_print_page_region(page, vbi_text, TEXT_MAXSZ-1, "UTF-8",
143                                    /*table mode*/ TRUE, FALSE,
144                                    0,             chop_top,
145                                    page->columns, page->rows-chop_top);
146     if (sz <= 0) {
147         av_log(ctx, AV_LOG_ERROR, "vbi_print error\n");
148         av_free(vbi_text);
149         return AVERROR_EXTERNAL;
150     }
151     vbi_text[sz] = '\0';
152     in  = vbi_text;
153     av_bprint_init(&buf, 0, TEXT_MAXSZ);
154
155     if (ctx->chop_spaces) {
156         for (;;) {
157             int nl, sz;
158
159             // skip leading spaces and newlines
160             in += strspn(in, " \n");
161             // compute end of row
162             for (nl = 0; in[nl]; ++nl)
163                 if (in[nl] == '\n' && (nl==0 || !(in[nl-1] & 0x80)))
164                     break;
165             if (!in[nl])
166                 break;
167             // skip trailing spaces
168             sz = chop_spaces_utf8(in, nl);
169             av_bprint_append_data(&buf, in, sz);
170             av_bprintf(&buf, "\n");
171             in += nl;
172         }
173     } else {
174         av_bprintf(&buf, "%s\n", vbi_text);
175     }
176     av_free(vbi_text);
177
178     if (!av_bprint_is_complete(&buf)) {
179         av_bprint_finalize(&buf, NULL);
180         return AVERROR(ENOMEM);
181     }
182
183     if (buf.len) {
184         int ret;
185         sub_rect->type = SUBTITLE_ASS;
186         if ((ret = create_ass_text(ctx, buf.str, &sub_rect->ass)) < 0) {
187             av_bprint_finalize(&buf, NULL);
188             return ret;
189         }
190         av_log(ctx, AV_LOG_DEBUG, "subtext:%s:txetbus\n", sub_rect->ass);
191     } else {
192         sub_rect->type = SUBTITLE_NONE;
193     }
194     av_bprint_finalize(&buf, NULL);
195     return 0;
196 }
197
198 static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page,
199                              int chop_top, int resx, int resy)
200 {
201     int iy;
202
203     // Hack for transparency, inspired by VLC code...
204     for (iy = 0; iy < resy; iy++) {
205         uint8_t *pixel = sub_rect->data[0] + iy * sub_rect->linesize[0];
206         vbi_char *vc = page->text + (iy / BITMAP_CHAR_HEIGHT + chop_top) * page->columns;
207         vbi_char *vcnext = vc + page->columns;
208         for (; vc < vcnext; vc++) {
209             uint8_t *pixelnext = pixel + BITMAP_CHAR_WIDTH;
210             switch (vc->opacity) {
211                 case VBI_TRANSPARENT_SPACE:
212                     memset(pixel, VBI_TRANSPARENT_BLACK, BITMAP_CHAR_WIDTH);
213                     break;
214                 case VBI_OPAQUE:
215                     if (!ctx->transparent_bg)
216                         break;
217                 case VBI_SEMI_TRANSPARENT:
218                     if (ctx->opacity > 0) {
219                         if (ctx->opacity < 255)
220                             for(; pixel < pixelnext; pixel++)
221                                 if (*pixel == vc->background)
222                                     *pixel += VBI_NB_COLORS;
223                         break;
224                     }
225                 case VBI_TRANSPARENT_FULL:
226                     for(; pixel < pixelnext; pixel++)
227                         if (*pixel == vc->background)
228                             *pixel = VBI_TRANSPARENT_BLACK;
229                     break;
230             }
231             pixel = pixelnext;
232         }
233     }
234 }
235
236 /* Draw a page as bitmap */
237 static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
238 {
239     int resx = page->columns * BITMAP_CHAR_WIDTH;
240     int resy = (page->rows - chop_top) * BITMAP_CHAR_HEIGHT;
241     uint8_t ci;
242     vbi_char *vc = page->text + (chop_top * page->columns);
243     vbi_char *vcend = page->text + (page->rows * page->columns);
244
245     for (; vc < vcend; vc++) {
246         if (vc->opacity != VBI_TRANSPARENT_SPACE)
247             break;
248     }
249
250     if (vc >= vcend) {
251         av_log(ctx, AV_LOG_DEBUG, "dropping empty page %3x\n", page->pgno);
252         sub_rect->type = SUBTITLE_NONE;
253         return 0;
254     }
255
256     sub_rect->data[0] = av_mallocz(resx * resy);
257     sub_rect->linesize[0] = resx;
258     if (!sub_rect->data[0])
259         return AVERROR(ENOMEM);
260
261     vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
262                             sub_rect->data[0], sub_rect->linesize[0],
263                             0, chop_top, page->columns, page->rows - chop_top,
264                             /*reveal*/ 1, /*flash*/ 1);
265
266     fix_transparency(ctx, sub_rect, page, chop_top, resx, resy);
267     sub_rect->x = ctx->x_offset;
268     sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT;
269     sub_rect->w = resx;
270     sub_rect->h = resy;
271     sub_rect->nb_colors = ctx->opacity > 0 && ctx->opacity < 255 ? 2 * VBI_NB_COLORS : VBI_NB_COLORS;
272     sub_rect->data[1] = av_mallocz(AVPALETTE_SIZE);
273     if (!sub_rect->data[1]) {
274         av_freep(&sub_rect->data[0]);
275         return AVERROR(ENOMEM);
276     }
277     for (ci = 0; ci < VBI_NB_COLORS; ci++) {
278         int r, g, b, a;
279
280         r = VBI_R(page->color_map[ci]);
281         g = VBI_G(page->color_map[ci]);
282         b = VBI_B(page->color_map[ci]);
283         a = VBI_A(page->color_map[ci]);
284         ((uint32_t *)sub_rect->data[1])[ci] = RGBA(r, g, b, a);
285         ((uint32_t *)sub_rect->data[1])[ci + VBI_NB_COLORS] = RGBA(r, g, b, ctx->opacity);
286         ff_dlog(ctx, "palette %0x\n", ((uint32_t *)sub_rect->data[1])[ci]);
287     }
288     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK] = RGBA(0, 0, 0, 0);
289     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK + VBI_NB_COLORS] = RGBA(0, 0, 0, 0);
290     sub_rect->type = SUBTITLE_BITMAP;
291     return 0;
292 }
293
294 static void handler(vbi_event *ev, void *user_data)
295 {
296     TeletextContext *ctx = user_data;
297     TeletextPage *new_pages;
298     vbi_page page;
299     int res;
300     char pgno_str[12];
301     vbi_subno subno;
302     vbi_page_type vpt;
303     int chop_top;
304     char *lang;
305
306     snprintf(pgno_str, sizeof pgno_str, "%03x", ev->ev.ttx_page.pgno);
307     av_log(ctx, AV_LOG_DEBUG, "decoded page %s.%02x\n",
308            pgno_str, ev->ev.ttx_page.subno & 0xFF);
309
310     if (strcmp(ctx->pgno, "*") && !strstr(ctx->pgno, pgno_str))
311         return;
312     if (ctx->handler_ret < 0)
313         return;
314
315     res = vbi_fetch_vt_page(ctx->vbi, &page,
316                             ev->ev.ttx_page.pgno,
317                             ev->ev.ttx_page.subno,
318                             VBI_WST_LEVEL_3p5, 25, TRUE);
319
320     if (!res)
321         return;
322
323 #ifdef DEBUG
324     fprintf(stderr, "\nSaving res=%d dy0=%d dy1=%d...\n",
325             res, page.dirty.y0, page.dirty.y1);
326     fflush(stderr);
327
328     if (!vbi_export_stdio(ctx->ex, stderr, &page))
329         fprintf(stderr, "failed: %s\n", vbi_export_errstr(ctx->ex));
330 #endif
331
332     vpt = vbi_classify_page(ctx->vbi, ev->ev.ttx_page.pgno, &subno, &lang);
333     chop_top = ctx->chop_top ||
334         ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
335
336     av_log(ctx, AV_LOG_DEBUG, "%d x %d page chop:%d\n",
337            page.columns, page.rows, chop_top);
338
339     if (ctx->nb_pages < MAX_BUFFERED_PAGES) {
340         if ((new_pages = av_realloc_array(ctx->pages, ctx->nb_pages + 1, sizeof(TeletextPage)))) {
341             TeletextPage *cur_page = new_pages + ctx->nb_pages;
342             ctx->pages = new_pages;
343             cur_page->sub_rect = av_mallocz(sizeof(*cur_page->sub_rect));
344             cur_page->pts = ctx->pts;
345             cur_page->pgno = ev->ev.ttx_page.pgno;
346             cur_page->subno = ev->ev.ttx_page.subno;
347             if (cur_page->sub_rect) {
348                 res = (ctx->format_id == 0) ?
349                     gen_sub_bitmap(ctx, cur_page->sub_rect, &page, chop_top) :
350                     gen_sub_text  (ctx, cur_page->sub_rect, &page, chop_top);
351                 if (res < 0) {
352                     av_freep(&cur_page->sub_rect);
353                     ctx->handler_ret = res;
354                 } else {
355                     ctx->pages[ctx->nb_pages++] = *cur_page;
356                 }
357             } else {
358                 ctx->handler_ret = AVERROR(ENOMEM);
359             }
360         } else {
361             ctx->handler_ret = AVERROR(ENOMEM);
362         }
363     } else {
364         //TODO: If multiple packets contain more than one page, pages may got queued up, and this may happen...
365         av_log(ctx, AV_LOG_ERROR, "Buffered too many pages, dropping page %s.\n", pgno_str);
366         ctx->handler_ret = AVERROR(ENOSYS);
367     }
368
369     vbi_unref_page(&page);
370 }
371
372 static int slice_to_vbi_lines(TeletextContext *ctx, uint8_t* buf, int size)
373 {
374     int lines = 0;
375     while (size >= 2 && lines < MAX_SLICES) {
376         int data_unit_id     = buf[0];
377         int data_unit_length = buf[1];
378         if (data_unit_length + 2 > size)
379             return AVERROR_INVALIDDATA;
380         if (ff_data_unit_id_is_teletext(data_unit_id)) {
381             if (data_unit_length != 0x2c)
382                 return AVERROR_INVALIDDATA;
383             else {
384                 int line_offset  = buf[2] & 0x1f;
385                 int field_parity = buf[2] & 0x20;
386                 int i;
387                 ctx->sliced[lines].id = VBI_SLICED_TELETEXT_B;
388                 ctx->sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0);
389                 for (i = 0; i < 42; i++)
390                     ctx->sliced[lines].data[i] = vbi_rev8(buf[4 + i]);
391                 lines++;
392             }
393         }
394         size -= data_unit_length + 2;
395         buf += data_unit_length + 2;
396     }
397     if (size)
398         av_log(ctx, AV_LOG_WARNING, "%d bytes remained after slicing data\n", size);
399     return lines;
400 }
401
402 static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt)
403 {
404     TeletextContext *ctx = avctx->priv_data;
405     AVSubtitle      *sub = data;
406     int             ret = 0;
407     int j;
408
409     if (!ctx->vbi) {
410         if (!(ctx->vbi = vbi_decoder_new()))
411             return AVERROR(ENOMEM);
412         if (!vbi_event_handler_add(ctx->vbi, VBI_EVENT_TTX_PAGE, handler, ctx)) {
413             vbi_decoder_delete(ctx->vbi);
414             ctx->vbi = NULL;
415             return AVERROR(ENOMEM);
416         }
417     }
418
419     if (avctx->pkt_timebase.num && pkt->pts != AV_NOPTS_VALUE)
420         ctx->pts = av_rescale_q(pkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
421
422     if (pkt->size) {
423         int lines;
424         const int full_pes_size = pkt->size + 45; /* PES header is 45 bytes */
425
426         // We allow unreasonably big packets, even if the standard only allows a max size of 1472
427         if (full_pes_size < 184 || full_pes_size > 65504 || full_pes_size % 184 != 0)
428             return AVERROR_INVALIDDATA;
429
430         ctx->handler_ret = pkt->size;
431
432         if (ff_data_identifier_is_teletext(*pkt->data)) {
433             if ((lines = slice_to_vbi_lines(ctx, pkt->data + 1, pkt->size - 1)) < 0)
434                 return lines;
435             ff_dlog(avctx, "ctx=%p buf_size=%d lines=%u pkt_pts=%7.3f\n",
436                     ctx, pkt->size, lines, (double)pkt->pts/90000.0);
437             if (lines > 0) {
438 #ifdef DEBUG
439                 int i;
440                 av_log(avctx, AV_LOG_DEBUG, "line numbers:");
441                 for(i = 0; i < lines; i++)
442                     av_log(avctx, AV_LOG_DEBUG, " %d", ctx->sliced[i].line);
443                 av_log(avctx, AV_LOG_DEBUG, "\n");
444 #endif
445                 vbi_decode(ctx->vbi, ctx->sliced, lines, 0.0);
446                 ctx->lines_processed += lines;
447             }
448         }
449         ctx->pts = AV_NOPTS_VALUE;
450         ret = ctx->handler_ret;
451     }
452
453     if (ret < 0)
454         return ret;
455
456     // is there a subtitle to pass?
457     if (ctx->nb_pages) {
458         int i;
459         sub->format = ctx->format_id;
460         sub->start_display_time = 0;
461         sub->end_display_time = ctx->sub_duration;
462         sub->num_rects = 0;
463         sub->pts = ctx->pages->pts;
464
465         if (ctx->pages->sub_rect->type != SUBTITLE_NONE) {
466             sub->rects = av_malloc(sizeof(*sub->rects));
467             if (sub->rects) {
468                 sub->num_rects = 1;
469                 sub->rects[0] = ctx->pages->sub_rect;
470 #if FF_API_AVPICTURE
471 FF_DISABLE_DEPRECATION_WARNINGS
472                 for (j = 0; j < 4; j++) {
473                     sub->rects[0]->pict.data[j] = sub->rects[0]->data[j];
474                     sub->rects[0]->pict.linesize[j] = sub->rects[0]->linesize[j];
475                 }
476 FF_ENABLE_DEPRECATION_WARNINGS
477 #endif
478             } else {
479                 ret = AVERROR(ENOMEM);
480             }
481         } else {
482             av_log(avctx, AV_LOG_DEBUG, "sending empty sub\n");
483             sub->rects = NULL;
484         }
485         if (!sub->rects) // no rect was passed
486             subtitle_rect_free(&ctx->pages->sub_rect);
487
488         for (i = 0; i < ctx->nb_pages - 1; i++)
489             ctx->pages[i] = ctx->pages[i + 1];
490         ctx->nb_pages--;
491
492         if (ret >= 0)
493             *data_size = 1;
494     } else
495         *data_size = 0;
496
497     return ret;
498 }
499
500 static int teletext_init_decoder(AVCodecContext *avctx)
501 {
502     TeletextContext *ctx = avctx->priv_data;
503     unsigned int maj, min, rev;
504
505     vbi_version(&maj, &min, &rev);
506     if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
507         av_log(avctx, AV_LOG_ERROR, "decoder needs zvbi version >= 0.2.26.\n");
508         return AVERROR_EXTERNAL;
509     }
510
511     if (ctx->format_id == 0) {
512         avctx->width  = 41 * BITMAP_CHAR_WIDTH;
513         avctx->height = 25 * BITMAP_CHAR_HEIGHT;
514     }
515
516     ctx->vbi = NULL;
517     ctx->pts = AV_NOPTS_VALUE;
518
519     if (ctx->opacity == -1)
520         ctx->opacity = ctx->transparent_bg ? 0 : 255;
521
522 #ifdef DEBUG
523     {
524         char *t;
525         ctx->ex = vbi_export_new("text", &t);
526     }
527 #endif
528     av_log(avctx, AV_LOG_VERBOSE, "page filter: %s\n", ctx->pgno);
529     return (ctx->format_id == 1) ? ff_ass_subtitle_header_default(avctx) : 0;
530 }
531
532 static int teletext_close_decoder(AVCodecContext *avctx)
533 {
534     TeletextContext *ctx = avctx->priv_data;
535
536     ff_dlog(avctx, "lines_total=%u\n", ctx->lines_processed);
537     while (ctx->nb_pages)
538         subtitle_rect_free(&ctx->pages[--ctx->nb_pages].sub_rect);
539     av_freep(&ctx->pages);
540
541     vbi_decoder_delete(ctx->vbi);
542     ctx->vbi = NULL;
543     ctx->pts = AV_NOPTS_VALUE;
544     return 0;
545 }
546
547 static void teletext_flush(AVCodecContext *avctx)
548 {
549     teletext_close_decoder(avctx);
550 }
551
552 #define OFFSET(x) offsetof(TeletextContext, x)
553 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
554 static const AVOption options[] = {
555     {"txt_page",        "list of teletext page numbers to decode, * is all", OFFSET(pgno),           AV_OPT_TYPE_STRING, {.str = "*"},      0, 0,        SD},
556     {"txt_chop_top",    "discards the top teletext line",                    OFFSET(chop_top),       AV_OPT_TYPE_INT,    {.i64 = 1},        0, 1,        SD},
557     {"txt_format",      "format of the subtitles (bitmap or text)",          OFFSET(format_id),      AV_OPT_TYPE_INT,    {.i64 = 0},        0, 1,        SD,  "txt_format"},
558     {"bitmap",          NULL,                                                0,                      AV_OPT_TYPE_CONST,  {.i64 = 0},        0, 0,        SD,  "txt_format"},
559     {"text",            NULL,                                                0,                      AV_OPT_TYPE_CONST,  {.i64 = 1},        0, 0,        SD,  "txt_format"},
560     {"txt_left",        "x offset of generated bitmaps",                     OFFSET(x_offset),       AV_OPT_TYPE_INT,    {.i64 = 0},        0, 65535,    SD},
561     {"txt_top",         "y offset of generated bitmaps",                     OFFSET(y_offset),       AV_OPT_TYPE_INT,    {.i64 = 0},        0, 65535,    SD},
562     {"txt_chop_spaces", "chops leading and trailing spaces from text",       OFFSET(chop_spaces),    AV_OPT_TYPE_INT,    {.i64 = 1},        0, 1,        SD},
563     {"txt_duration",    "display duration of teletext pages in msecs",       OFFSET(sub_duration),   AV_OPT_TYPE_INT,    {.i64 = 30000},    0, 86400000, SD},
564     {"txt_transparent", "force transparent background of the teletext",      OFFSET(transparent_bg), AV_OPT_TYPE_INT,    {.i64 = 0},        0, 1,        SD},
565     {"txt_opacity",     "set opacity of the transparent background",         OFFSET(opacity),        AV_OPT_TYPE_INT,    {.i64 = -1},      -1, 255,      SD},
566     { NULL },
567 };
568
569 static const AVClass teletext_class = {
570     .class_name = "libzvbi_teletextdec",
571     .item_name  = av_default_item_name,
572     .option     = options,
573     .version    = LIBAVUTIL_VERSION_INT,
574 };
575
576 AVCodec ff_libzvbi_teletext_decoder = {
577     .name      = "libzvbi_teletextdec",
578     .long_name = NULL_IF_CONFIG_SMALL("Libzvbi DVB teletext decoder"),
579     .type      = AVMEDIA_TYPE_SUBTITLE,
580     .id        = AV_CODEC_ID_DVB_TELETEXT,
581     .priv_data_size = sizeof(TeletextContext),
582     .init      = teletext_init_decoder,
583     .close     = teletext_close_decoder,
584     .decode    = teletext_decode_frame,
585     .capabilities = AV_CODEC_CAP_DELAY,
586     .flush     = teletext_flush,
587     .priv_class= &teletext_class,
588 };