mpv-player / mpv-player/mpv

set_property sub-text

Open
#16,593 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

meta:feature-request
Dominant language
C
Stars
37k
Forks
3.5k
Avg merge
1d 10h
Merged PRs (30d)
22

Description

Expected behavior of the wanted feature

I’m not sure whether this is a bug or expected behavior, so I’m posting this as a feature request.

The idea is to modify the current subtitle. For now, let’s say that I want to make the subtitle uppercase. If this is working, I would like to apply typographic changes, such as correcting apostrophes and dashes.

I’ve created the following hook:

mp.observe_property("sub-text", "string", function(name, value)
  if value then
    local modified = modify_subtitle(value)
    if modified and modified ~= value then
      mp.set_property("sub-text", modified)
    end
  end
end)

But the subtitles are not modified. Is the property sub-text not editable?

The hook is part of a longer script that I created to have some debugging:

local log_file = io.open("/tmp/iina_subtitle_mod.log", "a")

function log_debug(message)
  if log_file then
    log_file:write(os.date("%Y-%m-%d %H:%M:%S") .. ": " .. message .. "\n")
    log_file:flush()
  end
  mp.msg.info(message)
end

log_debug("Script started")

function modify_subtitle(text)
  if not text then return nil end

  log_debug("Original subtitle: " .. text)
  local modified = text:upper()
  log_debug("Modified subtitle: " .. modified)

  return modified
end

mp.observe_property("sub-text", "string", function(name, value)
  log_debug("Subtitle change detected")
  if value then
    local modified = modify_subtitle(value)
    if modified and modified ~= value then
      mp.set_property("sub-text", modified)
      log_debug("Subtitle replaced")
    end
  end
end)

log_debug("Script loaded successfully")

mp.register_event("shutdown", function()
  if log_file then
    log_debug("Script shutting down")
    log_file:close()
  end
end)

The logfile created by the script also seems to work.

2025-07-28 20:53:12: Script started
2025-07-28 20:53:12: Script loaded successfully
2025-07-28 21:00:14: Subtitle change detected
2025-07-28 21:00:14: Original subtitle: Reach out to Kleya.
2025-07-28 21:00:14: Modified subtitle: REACH OUT TO KLEYA.
2025-07-28 21:00:14: Subtitle replaced
Alternative behavior of the wanted feature

Ideally, I would be able to apply changes to the subtitle currently being displayed on the fly.

Thank you so much for your work and help!

Log File
[   7.889][i][subtitle_modifier] Subtitle change detected
[   7.889][i][subtitle_modifier] Original subtitle: for everyone on Earth,
[   7.889][i][subtitle_modifier] Modified subtitle: FOR EVERYONE ON EARTH,
[   7.889][v][cplayer] Set property: sub-text="FOR EVERYONE ON EARTH," -> -2
[   7.889][i][subtitle_modifier] Subtitle replaced
[   7.892][v][sub/ass] fontselect: (sans-serif, 400, 0) -> /System/Library/Fonts/Helvetica.ttc, -1, Helvetica
[   7.893][v][vo/gpu] Reallocating OSD texture to 1024x256.
[   7.893][d][vo/gpu/libplacebo] Allocating 1081344 memory of type 0x1 (id 0) in heap 0: unknown
[   7.893][d][vo/gpu/libplacebo] Spent 0.046 ms allocating slab
[   9.271][d][vo/gpu/libplacebo] Garbage collected slab of size 2848K from pool 4
[   9.271][d][vo/gpu/libplacebo] Freeing slab of size 2848K
Sample Files

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Lua mp.observe_property/mp.set_property hook and the mpv sub-text property behavior shown in the report. Reproduce the logged update and trace how the subtitle value is passed to display rendering. Done means the requested subtitle transformation is applied reliably without breaking subtitle updates or rendering.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.