mpv icon indicating copy to clipboard operation
mpv copied to clipboard

secondary-sub-scale option?

Open Darkmaster006 opened this issue 1 year ago • 18 comments

Expected behavior of the wanted feature

Hello! I've been tinkering with the options to show two subtitles at the same time (which is especially useful for learning new languages, for example); but I have not been able to scale each subtitle separately. So far, I have this:

mpv --sid=4 --secondary-sid=3 --sub-pos=95 --secondary-sub-pos=100 --sub-scale=1 video.mkv

Let's say ID 4 is Chinese, ID 3 is English. Chinese is chosen as primary language, and the idea with --sub-pos=95 is so that it goes above the English, while --secondary-sub-pos=100 is so that English goes below the Chinese.

What I would like to do is have the, in this case, Chinese, be scaled bigger than the English. I have sub-scale=0.500 in my mpv.conf, so --sub-scale=1 would be double, but it seems to scale both subtitles at the same time, which is not what I would like. There does not seem to be a "--secondary-sub-scale" option anywhere, so it seems the default is to scale both, could this option be added? Thank you very much.

Alternative behavior of the wanted feature

No response

Log File

No response

Sample Files

No response

Darkmaster006 avatar Oct 03 '24 19:10 Darkmaster006

(which is especially useful for learning new languages, for example)

I use it in such way, too!

kuraga avatar Oct 06 '24 16:10 kuraga

(which is especially useful for learning new languages, for example)

Use it as such!

What do you mean?

Darkmaster006 avatar Oct 06 '24 22:10 Darkmaster006

  • dualsubs-creat.lua
    • Create bilingual ASS subtitles with pop movie style
    • Uses currently selected primary and secondary subtitles
    • Supports both external and embedded subtitles

mpv-0001 mpv-0002

VimWei avatar Oct 08 '24 02:10 VimWei

Fixed :)

How?

VimWei avatar Oct 08 '24 02:10 VimWei

  • dualsubs-creat.lua

    * Create bilingual ASS subtitles with pop movie style
    * Uses currently selected primary and secondary subtitles
    * Supports both external and embedded subtitles
    

mpv-0001 mpv-0002

Thank you, this could be very useful, but I couldn't get it to work. I got both dualsubs-creat.lua dualsubs-init.lua and dualsubs-creat.conf dualsubs-init.conf and I want to use Primary sub: Chinese (simplified) Secondary sub: Spanish (if there's no Spanish, either English or French) My absolute perfect config would be: mpv --sid=1 --secondary-sid=3 --sub-pos=90 --secondary-sub-pos=95 "video.mkv" 1 being Chinese (simplified) 2 is Chinese (trad) 3 is Spanish Chinese goes above Spanish, either at 95 if CHI is 90, or at 100 if CHI is 95. Then, if secondary sub scale existed: mpv --sid=1 --secondary-sid=3 --sub-pos=90 --secondary-sub-pos=95 --sub-scale=1 --secondary-sub-scale=0.5 "video.mkv" that is, Chinese at 1 or 1.1 and Spanish at 0.5 or maybe 0.6. In any case, I tried changing the code in dualsubs-init.conf, from primary_langs=en,eng,english secondary_langs=zh,chs,chi,chinese to primary_langs=zh,chs,chi,chinese secondary_langs=es,spa,spanish but it would not work, and it always default the second subtitle to the other Chinese track (trad) in the file, even when I use --secondary-sid=3 it just changes it to 2. Also, the dualsubs-creat.lua does not seem to work, as what shift+B does is just start to cycle through the video in a weird way where I can't control it anymore. Either way, thank you very much, any help is appreciated.

Darkmaster006 avatar Oct 09 '24 03:10 Darkmaster006

I haven't tested it with .mkv video files or subtitle formats other than .srt.

You could test it using a .mp4 video file with .zh.srt and .es.srt subtitle files.

If you encounter any issues, feel free to use notdiamond.ai for assistance.

VimWei avatar Oct 09 '24 04:10 VimWei

dualsubs-create.lua takes as input the current primary and secondary subtitles that are visible to you. You don't necessarily need to use dualsubs-init.lua. dualsubs-init.lua and dualsubs-create.lua are two separate lua srcipt. dualsubs-init.lua only serves to make mpv automatically load dual subtitles when starting a video, and has no other purpose.

VimWei avatar Oct 09 '24 04:10 VimWei

dualsubs-create.lua takes as input the current primary and secondary subtitles that are visible to you. You don't necessarily need to use dualsubs-init.lua. dualsubs-init.lua and dualsubs-create.lua are two separate lua srcipt. dualsubs-init.lua only serves to make mpv automatically load dual subtitles when starting a video, and has no other purpose.

I see, so in case I've got four subtitles, it would take only the first two always? Thanks.

Darkmaster006 avatar Oct 09 '24 18:10 Darkmaster006

I see, so in case I've got four subtitles, it would take only the first two always? Thanks.

No. It will take subs which you set in primary sub and secondary sub, just what you see in the screen when you play the video.

VimWei avatar Oct 10 '24 01:10 VimWei

I see, so in case I've got four subtitles, it would take only the first two always? Thanks.

No. It will take subs which you set in primary sub and secondary sub, just what you see in the screen when you play the video.

Alright, I see what you mean now. Sadly, this does not seem to work with .mkv. After "parsing" the video two times, each for one sub, I guess, it says: [dualsubs_creat] No external primary subtitle file found, reading from video [dualsubs_creat] No external secondary subtitle file found, reading from video [dualsubs_creat] Failed to create bilingual subtitles

Darkmaster006 avatar Oct 10 '24 12:10 Darkmaster006

@VimWei I have tried to change the color of the subtitles but I can't do it, the main and secondary subtitles are still white, I am learning English, my native language is Spanish, the truth is I ask for your help because I don't know anything about programming, I appreciate if you can help me adapt the files, thank you very much

miguequinteroga avatar Jan 05 '25 06:01 miguequinteroga

@VimWei I have tried to change the color of the subtitles but I can't do it, the main and secondary subtitles are still white, I am learning English, my native language is Spanish, the truth is I ask for your help because I don't know anything about programming, I appreciate if you can help me adapt the files, thank you very much

@miguequinteroga You can use my mpv-config: https://github.com/VimWei/mpv-config and "mpv-x86_64-v3-*********-git- ****** .7z" from https://github.com/shinchiro/mpv-winbuild-cmake/releases

  1. download my mpv-config and put it under your mpv folder: mpv\portable_config\
  2. Prepare your srt subtitles: one is english such as "subtitlename.en.srt", another is spanish such as "subtitlename.es.srt"

Note: I have tested dualsubs-creat.lua only with external .srt subtitle. If you have embed subtitle, you can extract and convert to srt by ffmpeg. ChatGPT, Perplexity.ai and so on can help you how.

  1. Change the default language setting for mpv init load: one is english, another is spanish change secondary_langs from chinese to spanish

image

  1. Open your video with mpv by dobule click, and mpv would load double subtitle english and spanish.

  2. You can use Alt + u to exchange primary subtitle and secondary subtitle for your preference.

  3. Use Shift + B to create bilingual ASS subtitles.

  4. You can change color, font and so on by edit subtitlename.bilingual.ass with any text editor. or you can change the default setting in mpv\portable_config\script-opts\dualsubs-creat.conf.

Now you can select the subtitle "subtitlename.bilingual.ass" by mpv hotkey "gs" or "gS". and you can hide another subtitle by mpv hotkey "v" or "Alt + v".

VimWei avatar Jan 05 '25 14:01 VimWei

As a workaround, using bash-shell utility sed to colorize my secondary subtitles.

sed -i -E '
  /^[0-9]+$/b            # Skip lines that contain only numbers
  /^[0-9]{2}:/b          # Skip lines that contain timestamps (start with hh:mm)
  /^[[:space:]]*$/b      # Skip blank lines
  s/^(.*)$/<font color="white">\1<\/font>/  # Wrap all other lines in white font
' translated.srt

Before modification:

1
00:00:00,000 --> 00:00:02,000
 A few weeks later.

2
00:00:02,000 --> 00:00:07,240
 Welcome to "Rapport".

3
00:00:07,240 --> 00:00:10,840
 Up to 150 billion kronor a year-

4
00:00:10,840 --> 00:00:14,360
 -since the economic crime in Sweden has changed so much.

After:

1
00:00:00,000 --> 00:00:02,000
<font color="white"> A few weeks later.</font>

2
00:00:02,000 --> 00:00:07,240
<font color="white"> Welcome to "Rapport".</font>

3
00:00:07,240 --> 00:00:10,840
<font color="white"> Up to 150 billion kronor a year-</font>

4
00:00:10,840 --> 00:00:14,360
<font color="white"> -since the economic crime in Sweden has changed so much.</font>

Besides color, one can adjust size too:

<font color="white" size="24"> A few weeks later.</font>

Playing it in mpv like this:

mpv video.mp4 --sub-files=translated.srt.srt:original.srt --sub-color=#F3CE32 --secondary-sid=2 --secondary-sub-pos=95

That would be great if --secondary-sub-color existed, but it doesn't exist at the moment.

DmitrySandalov avatar May 05 '25 23:05 DmitrySandalov

As a workaround, using bash-shell utility sed to colorize my secondary subtitles.

sed -i -E '
  /^[0-9]+$/b            # Skip lines that contain only numbers
  /^[0-9]{2}:/b          # Skip lines that contain timestamps (start with hh:mm)
  /^[[:space:]]*$/b      # Skip blank lines
  s/^(.*)$/<font color="white">\1<\/font>/  # Wrap all other lines in white font
' translated.srt

Before modification:

1
00:00:00,000 --> 00:00:02,000
 A few weeks later.

2
00:00:02,000 --> 00:00:07,240
 Welcome to "Rapport".

3
00:00:07,240 --> 00:00:10,840
 Up to 150 billion kronor a year-

4
00:00:10,840 --> 00:00:14,360
 -since the economic crime in Sweden has changed so much.

After:

1
00:00:00,000 --> 00:00:02,000
<font color="white"> A few weeks later.</font>

2
00:00:02,000 --> 00:00:07,240
<font color="white"> Welcome to "Rapport".</font>

3
00:00:07,240 --> 00:00:10,840
<font color="white"> Up to 150 billion kronor a year-</font>

4
00:00:10,840 --> 00:00:14,360
<font color="white"> -since the economic crime in Sweden has changed so much.</font>

Besides color, one can adjust size too:

<font color="white" size="24"> A few weeks later.</font>

Playing it in mpv like this:

mpv video.mp4 --sub-files=translated.srt.srt:original.srt --sub-color=#F3CE32 --secondary-sid=2 --secondary-sub-pos=95

That would be great if --secondary-sub-color existed, but it doesn't exist at the moment.

Oooh, I see, that's interesting. So this modifies the original .srt file (so one has to extract it) and then plays the video with that external (or embedded again) .srt, is this correct? Does this work only on Linux and not on Windows? I have a dual-boot installation, in any case. Thank you.

Darkmaster006 avatar May 06 '25 13:05 Darkmaster006

So this modifies the original .srt file (so one has to extract it) and then plays the video with that external (or embedded again) .srt, is this correct?

Correct.

(In my case, the source videos don't have any subtitles. I use ffmpeg to extract the audio track from the videos and then run https://github.com/ggml-org/whisper.cpp twice. First to generate subtitles in the original language and a second time to produce subtitles in English.)

If your videos include subtitles, you should be able to extract them using some ffmpeg command like this

ffmpeg -i input_video.mp4 -map 0:s:0 subtitles.srt

Does this work only on Linux and not on Windows?

ffmpeg builds are available for both Windows and Linux.

sed is originally a Unix/Linux utility, but you can achieve the same in Windows in different ways

  • Using WSL (Windows Subsystem for Linux)
  • Using sed for Windows (as part of GNUWin32 or Cygwin)
  • Using PowerShell
# Read the file line by line
(Get-Content original.srt) | ForEach-Object {
    if ($_ -match '^[0-9]+$') { $_ } # Skip lines with only numbers
    elseif ($_ -match '^[0-9]{2}:') { $_ } # Skip lines with timestamps
    elseif ($_ -match '^\s*$') { $_ } # Skip blank lines
    else { "<font color=`"white`">$_</font>" } # Wrap other lines in white font
} | Set-Content translated.srt

DmitrySandalov avatar May 07 '25 08:05 DmitrySandalov

Note <font> can have other attributes than color, e.g. size.

kuraga avatar May 07 '25 08:05 kuraga

So this modifies the original .srt file (so one has to extract it) and then plays the video with that external (or embedded again) .srt, is this correct?

Correct.

(In my case, the source videos don't have any subtitles. I use ffmpeg to extract the audio track from the videos and then run https://github.com/ggml-org/whisper.cpp twice. First to generate subtitles in the original language and a second time to produce subtitles in English.)

If your videos include subtitles, you should be able to extract them using some ffmpeg command like this

ffmpeg -i input_video.mp4 -map 0:s:0 subtitles.srt

Does this work only on Linux and not on Windows?

ffmpeg builds are available for both Windows and Linux.

sed is originally a Unix/Linux utility, but you can achieve the same in Windows in different ways

* Using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) (Windows Subsystem for Linux)

* Using `sed` for Windows (as part of [GNUWin32](http://gnuwin32.sourceforge.net/packages/sed.htm) or [Cygwin](https://www.cygwin.com/))

* Using PowerShell
# Read the file line by line
(Get-Content original.srt) | ForEach-Object {
    if ($_ -match '^[0-9]+$') { $_ } # Skip lines with only numbers
    elseif ($_ -match '^[0-9]{2}:') { $_ } # Skip lines with timestamps
    elseif ($_ -match '^\s*$') { $_ } # Skip blank lines
    else { "<font color=`"white`">$_</font>" } # Wrap other lines in white font
} | Set-Content translated.srt

Thank you very much for the help. I will try it out!

Darkmaster006 avatar May 09 '25 21:05 Darkmaster006

I tried Dmitry's sed command without thinking. It's probably only for .srt files. My .ass file ended up broken. 😂 To change subs size inplace in an .ass file it's even simpler (no script).

Just change the styling header with a text editor, For me it looked like,

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, (...)
Style: Default,微软雅黑,100,&H00FFFFFF, (...)

I changed 100 to 150, works like a charm. Like a couple other contributers here, it was for my Chinese primary subs.

Thanks Dmitry Sandalov for the idea for a workaround.

stephan-dev avatar Jun 05 '25 10:06 stephan-dev

I ended up just going with converting a vtt/srt to srt with ...it's bloats size wise bigtime over a vtt. Got it to work with white, lime, yellow, red, magenta and for dark ..black, maroon, navy, indigo those looked ok but just decided to keep it white. Can switch with VimWei 's script up or bottom.

Image

then swap it ...easier to distinguish which language

Image

but ultimately it'd be nice to have secondary-sub properties besides pos ...btw when I swap them need the secondary-sub-ass-override set to no for the secondary srt to be seen with the new font color.

Meta+o set secondary-sub-ass-override "no" ; script-binding swap_subtitles #! [Subtitles] > [Bilingual] > Swap dual subtitles position

sub-color="#55321f" sub-border-color="#e4c060" sub-shadow-color="#e1a47a" sub-border-size=1.5 sub-shadow-offset=2.5 sub-blur=0

secondary-sub-color="#55321f" secondary-sub-border-color="#e4c060" secondary-sub-shadow-color="#e1a47a" secondary-sub-border-size=1.5 secondary-sub-shadow-offset=2.5 secondary-sub-blur=0

mrfragger avatar Jun 27 '25 19:06 mrfragger