Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to choose Traditional Chinese subtitle automatically? #6885

Closed
laichiaheng opened this issue Aug 22, 2019 · 18 comments
Closed

How to choose Traditional Chinese subtitle automatically? #6885

laichiaheng opened this issue Aug 22, 2019 · 18 comments

Comments

@laichiaheng
Copy link

mpv version and platform

mpv 0.29.0-372-g80552ab28e Copyright © 2000-2019 mpv/MPlayer/mplayer2 projects
built on UNKNOWN
ffmpeg library versions:
libavutil 56.33.100
libavcodec 58.55.100
libavformat 58.31.101
libswscale 5.6.100
libavfilter 7.58.100
libswresample 3.6.100
ffmpeg version: N-94597-g74e6800381

Reproduction steps

slang=chi

Expected behavior

Choose Tradtional Chinese

Actual behavior

Choose Simplified Chinese

@qyot27
Copy link
Contributor

qyot27 commented Aug 22, 2019

https://www.loc.gov/standards/iso639-2/php/code_list.php

The ISO 639-2 character code for Traditional Chinese is zho.

@laichiaheng
Copy link
Author

laichiaheng commented Aug 22, 2019

Nobody uses the zho for Traditional Chinese, they use chi by adding a name "Traditional" behine it.
2019-08-23 02-33-51 的螢幕擷圖

@CounterPillow
Copy link
Contributor

Sounds like Chinese pirates should conform to ISO standards then instead of abusing track titles for something they're not for.

@laichiaheng
Copy link
Author

laichiaheng commented Aug 22, 2019

It doesn't look like "Chinese" pirates at all.
There is no "Traditional" Chinese in the list, either.

@qyot27
Copy link
Contributor

qyot27 commented Aug 22, 2019

It looks like I misinterpreted that table earlier, sorry. From a little more digging, there is no ISO 639-2 (or even 639-3, maybe?) code to differentiate between the writing forms of Chinese. What chi and zho actually are, are simply codes designating the ISO's internal English-based organizational system for the language codes (chi), and one that's based on the native name for the language (zho, at least I guess for some dialects).

This is actually a known issue with the language selection in the Matroska format itself:
https://gitlab.com/mbunkus/mkvtoolnix/wikis/Chinese-not-selectable-as-language

So yeah, putting 'Traditional' or 'Simplified' in the track titles looks like a necessary kludge until the Matroska specifications update to allow setting that distinction.

EDIT: The FAQ from the first link:
https://www.loc.gov/standards/iso639-2/faq.html#23

The suggestion there is that the script code gets appended to the 639-2 language code. Not sure if that style was ever floated for use in Matroska, although according to https://gitlab.com/mbunkus/mkvtoolnix/issues/2419, one likely option is that in MKVToolNix there might eventually be support for the recently-added LanguageIETF parameter. If the distinction between Traditional and Simplified is present there, that should ultimately fix it.

@zc62
Copy link
Contributor

zc62 commented Aug 22, 2019

Probably you can write a script to detect the track title (through this property: https://mpv.io/manual/master/#command-interface-track-list/n/title) to auto-select the TC track. Otherwise if multiple chi tracks exist, mpv chooses the one with smaller track id (in your case the one who made the mkv file chose to put SC before TC).

Or just write a folder-specific/file-specific mpv.conf to manually set the sid.

@laichiaheng
Copy link
Author

@zc62 I don't understand, what does the N suppose to mean in track-list/N/lang
Is the syntax correct?

local utils = require 'mp.utils'
local msg = require 'mp.msg'
mp.get_property_native(track-list/N/chi)

@zc62
Copy link
Contributor

zc62 commented Aug 23, 2019

No. You should first query the total number of tracks: track-list/count, then loop it.

Replace N with the 0-based track index.

See https://mpv.io/manual/master/#command-interface-track-list

In the loop of N from 0 to count-1, compare string property obtained from track-list/N/title with string Traditional, or other words you see that people use to mark TC tracks.

EDIT: of course you would want to make sure you first filter by type=="sub" and lang=="chi"

@zc62
Copy link
Contributor

zc62 commented Aug 23, 2019

I just wrote one. @laichiaheng

mp.register_event("file-loaded", function()
    local count = mp.get_property_native("track-list/count")
    for N = 0,count-1,1 do
        local type = mp.get_property_native("track-list/" .. tostring(N) .. "/type")
        if type == "sub" then
            local lang = mp.get_property_native("track-list/" .. tostring(N) .. "/lang")
            if lang == "chi" then
                local title = mp.get_property_native("track-list/" .. tostring(N) .. "/title")
                if title == "Traditional" then
                    local id = mp.get_property_native("track-list/" .. tostring(N) .. "/id")
                    mp.commandv("set", "sid", id)
                    return
                end
            end
        end
    end
end)

Change the line

if title == "Traditional" then

to

if title == "Traditional" or title == "繁体中文" then

or even

if string.find(title, "Traditional") or string.find(title, "") then

if you want.

@CounterPillow
Copy link
Contributor

Perhaps it would be worth it to have a --stitle option which selects a more specific track if the --slang selection has no unambiguous one result, may be useful for more than just differentiating between traditional and simplified Chinese.

@laichiaheng
Copy link
Author

laichiaheng commented Aug 23, 2019

@zc62 How do you get these syntax: "track-list/" .. tostring(N) .. "/type"
The .. isn't mentioned in the manual.
Why are there space between .. and other strings?
How do you know the N should be string?
If there is no mp.register_event, will it work?

@laichiaheng
Copy link
Author

if title == "Traditional" or title == "繁体中文" then

By the way, it should be "繁體中文"

@CounterPillow
Copy link
Contributor

What .. does is it joins two strings, in other programming languages this is usually done with + but Lua uses .. for string concatenation.

@zc62
Copy link
Contributor

zc62 commented Aug 23, 2019

@CounterPillow I actually had a similar feature request, see #5133.
I mentioned

Even for built-in PGS subtitles, slang alone can also have troubles. For example, Simplified Chinese and Traditional Chinese share the code chi.

@zc62
Copy link
Contributor

zc62 commented Aug 23, 2019

@laichiaheng Just try if my script works or not. If you want to learn scripting for mpv, learn lua first.

@laichiaheng
Copy link
Author

@zc62 Yes, it works.

@Akemi
Copy link
Member

Akemi commented Sep 19, 2019

see #5133.

@Akemi Akemi closed this as completed Sep 19, 2019
@teohhanhui
Copy link
Contributor

There's https://github.com/CogentRedTester/mpv-sub-select which is already listed on https://github.com/mpv-player/mpv/wiki/User-Scripts

Seems like the best solution without having to write your own script.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants