Skip to content

Commit

Permalink
osd: draw the OSD bar with ASS vector drawings
Browse files Browse the repository at this point in the history
Drawing the bar with vector drawings (instead with characters from the
OSD font) offers more flexibility and looks better. This also adds
chapter marks to the OSD bar, which are visible as small triangles on
the top and bottom inner border of the bar.

Change the default position of the OSD bar below the center of the
screen. This is less annoying than putting the bar directly into the
center of the view, where it obscures the video. The new position is
not quite on the bottom of the screen to avoid collisions with
subtitles.

The old centered position can be forced with ``--osd-bar-align-y=0``.

Also make it possible to change the OSD bar width/height with the new
--osd-bar-w and --osd-bar-h options.

It's possible that the new OSD bar renders much slower than the old
one. There are two reasons for this: 1. the character based bar
allowed libass to cache each character, while the vector drawing forces
it to redraw every time the bar position changes. 2., the bar position
is updated at a much higher granularity (the bar position is passed
along as float instead of as integer in the range 0-100, so the bar
will be updated on every single video frame).
  • Loading branch information
wm4 committed Mar 30, 2013
1 parent d39b131 commit ef3c0e6
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 71 deletions.
11 changes: 9 additions & 2 deletions DOCS/man/en/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1315,12 +1315,19 @@
prefixes, see ``Input command prefixes``. If you want to disable the OSD
completely, use ``--osd-level=0``.

--osd-bar-align-x=<-1..1>
--osd-bar-align-x=<-1-1>
Position of the OSD bar. -1 is far left, 0 is centered, 1 is far right.

--osd-bar-align-y=<-1..1>
--osd-bar-align-y=<-1-1>
Position of the OSD bar. -1 is top, 0 is centered, 1 is bottom.

--osd-bar-w=<1-100>
Width of the OSD bar, in percentage of the screen width (default: 75).
A value of 0.5 means the bar is half the screen wide.

--osd-bar-h=<0.1-50>
Height of the OSD bar, in percentage of the screen height (default: 3.125).

--osd-back-color=<#RRGGBB>, --sub-text-back-color=<#RRGGBB>
See ``--osd-color``. Color used for OSD/sub text background.

Expand Down
2 changes: 2 additions & 0 deletions core/cfg-mplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ const m_option_t common_opts[] = {
OPT_FLAG("osd-bar", osd_bar_visible, 0),
OPT_FLOATRANGE("osd-bar-align-x", osd_bar_align_x, 0, -1.0, +1.0),
OPT_FLOATRANGE("osd-bar-align-y", osd_bar_align_y, 0, -1.0, +1.0),
OPT_FLOATRANGE("osd-bar-w", osd_bar_w, 0, 1, 100),
OPT_FLOATRANGE("osd-bar-h", osd_bar_h, 0, 0.1, 50),
OPT_SUBSTRUCT("osd", osd_style, osd_style_conf, 0),
OPT_SUBSTRUCT("sub-text", sub_text_style, osd_style_conf, 0),
{NULL, NULL, 0, 0, 0, 0, NULL}
Expand Down
3 changes: 3 additions & 0 deletions core/defaultopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void set_default_mplayer_options(struct MPOpts *opts)
.gamma_hue = 1000,
.osd_level = 1,
.osd_duration = 1000,
.osd_bar_align_y = 0.5,
.osd_bar_w = 75.0,
.osd_bar_h = 3.125,
.loop_times = -1,
.ordered_chapters = 1,
.chapter_merge_threshold = 100,
Expand Down
26 changes: 24 additions & 2 deletions core/mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,8 @@ void set_osd_bar(struct MPContext *mpctx, int type, const char *name,
if (mpctx->sh_video && opts->term_osd != 1) {
mpctx->osd_visible = (GetTimerMS() + opts->osd_duration) | 1;
mpctx->osd->progbar_type = type;
mpctx->osd->progbar_value = 256 * (val - min) / (max - min);
mpctx->osd->progbar_value = (val - min) / (max - min);
mpctx->osd->progbar_num_stops = 0;
vo_osd_changed(OSDTYPE_PROGBAR);
return;
}
Expand All @@ -1345,14 +1346,34 @@ static void update_osd_bar(struct MPContext *mpctx, int type,
double min, double max, double val)
{
if (mpctx->osd->progbar_type == type) {
int new_value = 256 * (val - min) / (max - min);
float new_value = (val - min) / (max - min);
if (new_value != mpctx->osd->progbar_value) {
mpctx->osd->progbar_value = new_value;
vo_osd_changed(OSDTYPE_PROGBAR);
}
}
}

static void set_osd_bar_chapters(struct MPContext *mpctx, int type)
{
struct osd_state *osd = mpctx->osd;
osd->progbar_num_stops = 0;
if (osd->progbar_type == type) {
double len = get_time_length(mpctx);
if (len > 0) {
int num = get_chapter_count(mpctx);
for (int n = 0; n < num; n++) {
double time = chapter_start_time(mpctx, n);
if (time >= 0) {
float pos = time / len;
MP_TARRAY_APPEND(osd, osd->progbar_stops,
osd->progbar_num_stops, pos);
}
}
}
}
}

void set_osd_function(struct MPContext *mpctx, int osd_function)
{
struct MPOpts *opts = &mpctx->opts;
Expand Down Expand Up @@ -1432,6 +1453,7 @@ static void add_seek_osd_messages(struct MPContext *mpctx)
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 1,
av_clipf(get_current_pos_ratio(mpctx), 0, 1));
set_osd_bar_chapters(mpctx, OSD_BAR_SEEK);
}
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
mp_osd_msg_t *msg = add_osd_msg(mpctx, OSD_MSG_TEXT, 1,
Expand Down
2 changes: 2 additions & 0 deletions core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ typedef struct MPOpts {
int osd_bar_visible;
float osd_bar_align_x;
float osd_bar_align_y;
float osd_bar_w;
float osd_bar_h;
struct osd_style_opts *osd_style;
struct osd_style_opts *sub_text_style;
float sub_scale;
Expand Down
Loading

0 comments on commit ef3c0e6

Please sign in to comment.