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.
This commit is contained in:
wm4 2016-09-03 17:05:11 +02:00
parent 590caeb2bd
commit 4f263dce34
4 changed files with 18 additions and 0 deletions

View File

@ -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
------

View File

@ -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,

View File

@ -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;

View File

@ -22,6 +22,7 @@
#include <libavcodec/avcodec.h>
#include <libavutil/common.h>
#include <libavutil/intreadwrite.h>
#include <libavutil/opt.h>
#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)