From 4f263dce34822a3f8356f88fa736353a20fd0c8c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 3 Sep 2016 17:05:11 +0200 Subject: sd_lavc: enable teletext Whitelisting supported codecs is (probably) still better than just allowing everything, given the weird FFmpeg API. I'm also assuming Libav doesn't even have the codec ID, but I didn't check. Also add a --teletext-page option, since otherwise it decodes every teletext page and shows them in succession. And yes, we can't use av_opt_set_int() - instead we have to set it as string. Because FFmpeg's option system is terrible. --- DOCS/man/options.rst | 4 ++++ options/options.c | 2 ++ options/options.h | 1 + sub/sd_lavc.c | 11 +++++++++++ 4 files changed, 18 insertions(+) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 8b7ffe02a5..6668849320 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1795,6 +1795,10 @@ Subtitles of subtitles across seeks, so after a seek libass can't eliminate subtitle packets with the same ReadOrder as earlier packets. +``--teletext-page=<1-999>`` + This works for ``dvb_teletext`` subtitle streams, and if FFmpeg has been + compiled with support for it. + Window ------ diff --git a/options/options.c b/options/options.c index ddebceef36..e00c46c676 100644 --- a/options/options.c +++ b/options/options.c @@ -469,6 +469,7 @@ const m_option_t mp_opts[] = { OPT_SUBSTRUCT("osd", osd_style, osd_style_conf, 0), OPT_SUBSTRUCT("sub-text", sub_text_style, sub_style_conf, 0), OPT_FLAG("sub-clear-on-seek", sub_clear_on_seek, 0), + OPT_INTRANGE("teletext-page", teletext_page, 0, 1, 999), //---------------------- libao/libvo options ------------------------ OPT_SETTINGSLIST("ao", audio_driver_list, 0, &ao_obj_list, ), @@ -776,6 +777,7 @@ const struct MPOpts mp_default_opts = { .sub_use_margins = 1, .ass_scale_with_window = 0, .sub_scale_with_window = 1, + .teletext_page = 100, #if HAVE_LUA .lua_load_osc = 1, .lua_load_ytdl = 1, diff --git a/options/options.h b/options/options.h index 7d6701cd1e..96345e66f4 100644 --- a/options/options.h +++ b/options/options.h @@ -281,6 +281,7 @@ typedef struct MPOpts { int ass_hinting; int ass_shaper; int sub_clear_on_seek; + int teletext_page; int hwdec_api; char *hwdec_codecs; diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index f310367734..2c1b327b38 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "config.h" @@ -106,6 +107,9 @@ static int init(struct sd *sd) // Supported codecs must be known to decode to paletted bitmaps switch (cid) { case AV_CODEC_ID_DVB_SUBTITLE: +#if LIBAVCODEC_VERSION_MICRO >= 100 + case AV_CODEC_ID_DVB_TELETEXT: +#endif case AV_CODEC_ID_HDMV_PGS_SUBTITLE: case AV_CODEC_ID_XSUB: case AV_CODEC_ID_DVD_SUBTITLE: @@ -339,6 +343,13 @@ static void decode(struct sd *sd, struct demux_packet *packet) MP_WARN(sd, "Subtitle with unknown start time.\n"); mp_set_av_packet(&pkt, packet, &priv->pkt_timebase); + + if (ctx->codec_id == AV_CODEC_ID_DVB_TELETEXT) { + char page[4]; + snprintf(page, sizeof(page), "%d", opts->teletext_page); + av_opt_set(ctx, "txt_page", page, AV_OPT_SEARCH_CHILDREN); + } + int got_sub; int res = avcodec_decode_subtitle2(ctx, &sub, &got_sub, &pkt); if (res < 0 || !got_sub) -- cgit v1.2.3