[PYTHON] Set the color on the poster side so that the color of the Youtube subtitles changes automatically.

at first

Nice to meet you. Thank you for visiting. I tried various things about the subtitle function of Youtube. I've also created a simple tool for coloring subtitles, so I'll publish it.

Subtitle test Subtitle test --Youtube (No sound)

In this way, youtube subtitles can be displayed in color. I didn't get much information when I looked it up, so I'd like to summarize it for reference.

Trigger

I was watching this video on Youtube.

Yorushika-Rain with Cappuccino Yorushika-Rain with Cappuccino

If you add subtitles somehow ... Even though I haven't set it, the colors change and the fonts are different. It's really amazing so please take a look.

This time I will not touch on how to change the font. I wasn't sure when I looked it up, so I'd like to add it if there is any information.

manner

The detailed procedure is explained from here.

About code writing tools

This is the procedure to create a subtitle file using the creation tool.

Source code

The source code has been released. You can fly from the link below.

Source code of "Set the color on the poster side so that the color of Youtube subtitles changes automatically"

1. Download the tool

** We have confirmed the operation only on windows10. I haven't confirmed if it works on other OS. ** ** Download it from the following, save it anywhere, and unzip it.

Colored Subtitle Creation Tool (Link to Google Drive)

After decompressing, check that the configuration is as follows.

Colored subtitle creation tool ――――――― Please put the downloaded subtitle file in this. ――― Please save the file name as “captions” without changing the extension.
| ―― Configuration file ―――――― Colors to be used and specified characters.txt
| ―― Color specification file.txt
| ―― Primary Color Dictionary Vivid Color
| ―― Color to be used and specified character description method.txt
| ―― Color specification file description method.txt
| ―― Colored subtitle creation tool.exe

2. Download video subtitles

The tool supports sbv and srt format subtitle files. Use the following page to download the srt format subtitle file.

I'm not sure if the link is allowed, so I won't list the URL. Search the web for "CGI to download YouTube video subtitles". Please see the author's page for how to use it.

Save the file in the folder "Please put the downloaded subtitle file in this." ** Save the name as "captions". If the name is different, it will not be read. ** **

3. Check and edit the configuration file

For the setting method, refer to "Color to be used and specified character description method.txt" and "Color specification file description method.txt". ** By default, 12 colors are available and all subtitles are displayed in red. ** **

4. Execute "Colored subtitle creation tool.exe"

A black screen will be displayed. Follow the instructions to create it. ** If an error message is displayed, or if the screen appears and disappears for a moment, it is a file read error. Check that there are no mistakes in the configuration file, etc. ** ** If you cannot solve the problem, please let us know in the comments.

About subtitle specifications

In addition to adding subtitles on the Youtube site, you can upload subtitle files to Youtube. For details, please see the official page below.

Supported Subtitle Files-Youtube Help

This tool uses what is called the SAMI file in this.

Creation example

As an example, this time I would like to display the following sentences in color.

① I am a cat. There is no name yet. ② I have no idea where I was born. ③ I remember only crying in a dim and damp place. ④ I saw a human being for the first time here. ⑤ Moreover, I heard later that it was the most evil race of human beings called Shosei.

Quote-I am a cat (Natsume Soseki)

In this example, each sentence ① ** Red (# ff0000) ** </ font> ② ** Pink (# ffc0cb) ** </ font> ③ ** Orange (# ffa500) ** </ font> ④ ** Green (# 008000) ** </ font> ⑤ ** Blue (# 0000ff) ** </ font> As a result, it will be displayed for 5 seconds (5000 milliseconds).

Use the color code to select the color. Please refer to the following page.

Web Color Sample Primary Color Encyclopedia

From here, follow the steps above.

1. Download and save the subtitle file

If you create a subtitle on the Youtube official page and download it according to the procedure, it will be such a file.

captions.srt


1
00:00:00,000 --> 00:00:05,000
I am a cat. There is no name yet.

2
00:00:05,000 --> 00:00:10,000
I have no idea where I was born.

3
00:00:10,000 --> 00:00:15,000
I remember only crying in a dim and damp place.

4
00:00:15,000 --> 00:00:20,000
I saw human beings for the first time here.

5
00:00:20,000 --> 00:00:28,000
Moreover, I heard later that it was the most evil race of human beings called Shosei.

2. Edit the configuration file

First, edit "Color to be used and specified character .txt". This time, we will use five colors, but since there is no color you want to display with the default settings, add it. The specified characters are "a, b, c, d, e". ** The parts a to e are additional parts. ** **

Color to use and specified character.txt


1:#ff0000
2:#ff007f
3:#ff00ff
4:#7f00ff
5:#0000ff
6:#007fff
7:#00ffff
8:#00ff7f
9:#00ff00
10:#7fff00
11:#ffff00
12:#ff7f00
a:#ff0000
b:#ffc0cb
c:#ffa500
d:#008000
e:#0000ff

Next, edit the "color specification file.txt". This time, we will change the color one sentence at a time, so edit it as follows.

Color specification file.txt


a
b
c
d
e

With this description, the characters specified earlier and the color code are specified correspondingly, such as "a (# ff0000)" in the first sentence and "b (# ffc0cb)" in the second sentence. If you want to display them all in the same color, you can write "all the specified character of the color you want to use" only on the first line. For details, refer to the description method file.

3. Run the tool

If the settings are successful, the following file will be completed. (Saved as sample.smi)

sample.smi


<SAMI>
<HEAD>
<SAMIParam>
Metrics {time:ms;}
Spec {MSFT:1.0;}
</SAMIParam>
</HEAD>
<BODY>
<SYNC Start=0><font color="#ff0000"><b>I am a cat. There is no name yet.</b></font>
<SYNC Start=5000><font color="#ffc0cb"><b>I have no idea where I was born.</b></font>
<SYNC Start=10000><font color="#ffa500"><b>I remember only crying in a dim and damp place.</b></font>
<SYNC Start=15000><font color="#008000"><b>I saw human beings for the first time here.</b></font>
<SYNC Start=20000><font color="#0000ff"><b>Moreover, I heard later that it was the most evil race of human beings called Shosei.</b></font>

4. Post to Youtube!

After that, upload the subtitle file and finish. If you search for uploads, you will find a lot of information, so please refer to that.

Subtitle test-Youtube (No sound)

This is a video of uploading the above file.

Finally

Thank you for watching until the end. The tool is written in python. Since I am a beginner, the degree of completion is not high, but since it was created by an individual as a hobby, I would be grateful if you could see it with warm eyes.

We would appreciate it if you could refer to those who want to give individuality to subtitles, Youtuber, etc.

Well then!

Recommended Posts