Workaround for adding hardcoded subtitles in ShotCut?


#1

I have read https://shotcut.org/FAQ/#how-do-i-make-subtitles

Let’s say we have a webvtt or other format subtitle file. I have thought of following workaround to add hardcoded subtitles to videos.

  1. Use some other “tool” that takes the vtt or srt file as input and creates a transparent / greenscreen video with subtitles being shown according to the timing in srt/vtt file.

  2. Next, add this video in second video track in ShotCut, and remove greenscreen.

Trouble is, I don’t know which tool I could use for step1. Please suggest such a tool (preferably free).

Or if you have a better workaround to add hardcoded subtitles from srt/vtt files to video, please let me know.


#2

Check out the link below which involves a few people discussing the same problem and offers a few solutions.


#3

Excellent! That does the job i think. Now the only thing remaining is how to export that video from Aegisub. If there is a better workaround than using a screen recording software, please let us know.


#4

I can’t help you there I’m afraid, but I did just find another player you might want to look at.


#5

This is an interesting project

I will look into modifying my WebVfx framework to enable subtitles in “srt” or “vtt” to be easily incorporated into a video using it. Hopefully I’ll be able to get a working version created sometime during this coming week - I’ll let you know when it’s available.


#6

You could create a green or blue screen video, then use Handbrake to hard-code the subtitles to the video.


#7

There is a filter in the engine that can help, but there is an issue with respect to trying to “cut” the subtitle:

Still, this might be a useful filter for some use cases.


#8

@ravenclaw, @berni, @stanglow, @nwgat, @jonray, @sauron, @qdsov,

I have modified my WebVfx framework to enable subtitles (in Subrip .srt file format) to be hardcoded onto videos using the Overlay HTML feature (see: WebVfx HTML Overlay Filters Update - Slideshows, Exploding Text). This is version 1.5 of the framework.

I tried several ways of reading an .srt file in javascript, but although some of them worked in the browser, none of them worked in Shotcut itself. So the contents of the .srt file have to be copied into a <pre></pre> tag in the HTML itself. See below and the example on the website: http://www.elusien.co.uk/shotcut/.

If you apply the subtitle to a video and then edit that video (e.g. by deleting a clip) then of course the subtitle cues will no longer match up to the speech on the video. You will either have to recreate the .srt file anew, or use a Subrip editor to edit the cues (see the documentation on my website). Another possibility would be to create a video with just the subtitles on it, then use this as a second track in Shotcut and whenever you cut the main track you would do an identical cut to the subtitle track.

You can use CSS to position and style the subtitle in whatever way you want. The example on the website shows two copies of the subtitles, the one at the top of the screen in white on a semitransparent dark background, while the one at the bottom of the screen is in white with a dark outline on a totally transparent background.

The basic HTML to create the example is:

<body data-control='40:30'>
	The subtitles appear at the top (#srt1) of the screen and also at the bottom (#srt2).
	<div id='st1' class='webvfx' data-subtitles='subtitles'></div>
	<div id='st2' class='webvfx' data-subtitles='subtitles'></div>
	<pre id='subtitles'>
1
00:00:04,000 --> 00:00:15,400
This is the 1st subtitle 04sec to 15.4sec
Mary had a little lamb,
its <i>fleece</i> was white as snow
and everywhere that Mary went
that <b>lamb</b> was sure to go!

2
00:00:16,600 --> 00:00:25,800
This is the 2nd subtitle 16.6sec to 25.8sec

3
00:00:20,600 --> 00:00:23,800
This is the 3rd subtitle 20.6sec to 23.8sec

4
00:00:24,600 --> 00:00:30,800
This is the 4th subtitle 24.6sec to 30.8sec

</pre>
</body>

Have a play with the source code on the website (including the CSS) and let me know what you think.


Bult-in subtitles (hardcoded/hardrendered)
#9

Great stuff, Neil! I was thinking about adding subtitles to a 7-minute video featuring one of my songs, and I think this will help greatly, Will try to experiment when I can but the problem of lack of time has recurred. ( I’m just experimenting with applying the mask filter to text, inspired by sauron’s work. )

Will get to it when I can. Still haven’t got round to playing with your exploding text either…:tired_face:

Thank you for your brilliant work on this.


#10

I tried the subtitles overlay with a video that I had subtitles for. The subtitles work but the first 4 lines of subtitles are showing on the left side of the video.

I tried an export and the 4 lines show in the export as well.

Is this a flaw in the code or did I mess up when I added my srt file to the code?


#11

Thanks a lot. I will try this in a couple of days and get back.


#12

The code should make the subtitle <pre> element with the subtitles in it invisible.

I’ll check to see what has gone wrong. In the meantime put the following in your CSS:

pre {display: none;}


#13

The WebVfx.js javascript file has been updated (v 1.6) on the website to include the fix mentioned above.


#14

This fixed the issue. Subtitles are working well.:smile:


#16

I followed your method and put following code in overlay html filter (saved as test.htm)

   <!DOCTYPE html><html><head><meta charset="UTF-8">
  
    <script src="qrc:/scripts/jquery.js"></script>
    <script src="qrc:/scripts/rangy-core.js"></script>
    <script src="qrc:/scripts/rangy-cssclassapplier.js"></script>
    <script src="qrc:/scripts/htmleditor.js"></script>
    <script src="./WebVfx.js"></script>
  </head>

  <body style="font-size: 25pt;" data-control="40:30">
  

	The subtitles appear at the top (#srt1) of the screen and also at the bottom (#srt2).
	<div id="st1" class="webvfx" data-subtitles="subtitles"></div>
	<div id="st2" class="webvfx" data-subtitles="subtitles"></div>
   <pre>
	<pre id="subtitles">1
00:00:04,000 --&gt; 00:00:15,400
This is the 1st subtitle 04sec to 15.4sec
Mary had a little lamb,
its <i>fleece</i> was white as snow
and everywhere that Mary went
that <b>lamb</b> was sure to go!

2
00:00:16,600 --&gt; 00:00:25,800
This is the 2nd subtitle 16.6sec to 25.8sec

3
00:00:20,600 --&gt; 00:00:23,800
This is the 3rd subtitle 20.6sec to 23.8sec

4
00:00:24,600 --&gt; 00:00:30,800
This is the 4th subtitle 24.6sec to 30.8sec

</pre>

</body></html>

It is working as expected I think, as it is showing different text at different times.

Thanks a lot. I will now try to figure out the best way to position them centre aligned and bold, black on white appearance (like usual subtitles)


#17

What does this part in code do? Does it have to do with screen resolution?


#18

I dont know what I have done wrong in html code but it is showing some subtitles twice, as in below screenshot

is this expected?

(ping to @Elusien)


#19

The first value is the clip length in seconds, the second value is the frame rate in fps.


#20

Here’s an example of the subtitle file I created that works.

Subtitle example.txt (956 Bytes)


#21

Sorry, having the downstairs of the villa re-tiled and staying at a friend’s who doesn’t have Internet.

You have 2 DIVs (id=‘st1’ and id=‘st2’), each one will receive the subtitles, which is why you are getting it twice.

Just remove the ‘st2’ one.