Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merge video with subtitles
#11
(Jun-28-2022, 02:48 PM)snippsat Wrote: Here is a way with free tool Subtitle Edit 3.6.6.
Load .vtt file and now change to .ass(Advanced SubStation Alpha File), then save this .ass file.
Open MKVToolNix and the same,but now drag in the new .ass file generated with Subtitle Edit.
Now get transparent background with the right colors.
MKVToolNix embed subtitles in rather strange manner, i.e. they are visible only in VLC player.
At least they are not visible in "Videos" (Ubuntu) and in "Films and TV" (Windows).
GiliSoft do embedding "properly".
Reply
#12
There is another issue with subtitles.
When I use option ydl_opts = {'writesubtitles': True} when downloading videos from arte.tv, I get subtitle file with french subtitles which are not visible when I play video online (because actors speak french).
These French subtitles are probably used when someone plays this video using arte.tv's language settings other than French.
When I use "Web Developer Tools" --> Network on Firefox and put vtt in "Filter", vtt only appears for threads that are not in French, but it seems that yt-dlp is not smart enough to handle this problem.
Reply
#13
(Jun-28-2022, 03:18 PM)Pavel_47 Wrote: MKVToolNix embed subtitles in rather strange manner, i.e. they are visible only in VLC player.
At least they are not visible in "Videos" (Ubuntu) and in "Films and TV" (Windows).
The original ones are limited i never use them,it work in many player other than VLC.
Eg SMPlayer, MPC-HC, 5KPlayer..,ect
Reply
#14
Finally, I found a "pure-Python" solution to embed subtitles.
It's based on using MoviePy package.
Here is example how to proceed:
MoviePy example

When I tried this example, error occurred:
Output:
=========== RESTART: /home/pavel/python_code/embed_subtitles_v1.py =========== Traceback (most recent call last): File "/home/pavel/.local/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 1137, in __init__ subprocess_call(cmd, logger=None) File "/home/pavel/.local/lib/python3.6/site-packages/moviepy/tools.py", line 54, in subprocess_call raise IOError(err.decode('utf8')) OSError: convert-im6.q16: not authorized `@/tmp/tmpsw5kqzya.txt' @ error/property.c/InterpretImageProperties/3516. convert-im6.q16: no images defined `PNG32:/tmp/tmpxp1zmiyb.png' @ error/convert.c/ConvertImageCommand/3258. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/pavel/python_code/embed_subtitles_v1.py", line 14, in <module> subtitles = SubtitlesClip(subtl_in, generator) File "/home/pavel/.local/lib/python3.6/site-packages/moviepy/video/tools/subtitles.py", line 86, in __init__ hasmask = bool(self.make_textclip('T').mask) File "/home/pavel/python_code/embed_subtitles_v1.py", line 13, in <lambda> generator = lambda txt: TextClip(txt, font='Arial', fontsize=20, color='yellow') File "/home/pavel/.local/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 1146, in __init__ raise IOError(error) OSError: MoviePy Error: creation of None failed because of the following error: convert-im6.q16: not authorized `@/tmp/tmpsw5kqzya.txt' @ error/property.c/InterpretImageProperties/3516. convert-im6.q16: no images defined `PNG32:/tmp/tmpxp1zmiyb.png' @ error/convert.c/ConvertImageCommand/3258. . .This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect >>>
I've checked if ImageMagick is installed.
It's the case, ImageMagick is here.

Any suggestions ?
Thanks.
Reply
#15
Here is the workaround to a similar problem:

fix ImageMagick error: convert-im6.q16: unable to open image

But this approach solves the problem, related to PDF, whereas according to my log, the problem is more related to TXT. In ImageMagic's policy.xml, there is no TXT policy. Should I add it?
Reply
#16
(Jun-28-2022, 02:48 PM)snippsat Wrote: Here is a way with free tool Subtitle Edit 3.6.6.
Load .vtt file and now change to .ass(Advanced SubStation Alpha File), then save this .ass file.
Open MKVToolNix and the same,but now drag in the new .ass file generated with Subtitle Edit.
Now get transparent background with the right colors.

Well, here are my "updated" consideration concerning subtitles issue:
There are 3 ways to play a video with subtitles:
  • hard embedding: this method involves rendering subtitles into particular frames, time-consuming process, requiring intensive processing
  • soft embedding: fairly fast method, subtitles are embedded as metadata in the video file, then during playback smart video players (not all!) render the subtitles in particular frames
  • do not embed any subtitles, just keep the subtitle file which can be read by smart player while the video is playing

The 2nd method appears to be the most effective because on the one hand it allows rapid processing on the other hand it avoids keeping two files (or more in the case of several languages) - video and subtitles.
The only issue with the 2nd method - there is no possibility to change subtitle color.
In VLC player, this option exists, but seems not to work, regardless specified color subtitles are always white ... at the same time, changing font works.
In another player "Videos" there is no option to work with subtitles... only enable them.
As I understood MKVToolNix do "hard embedding".
It will be nice to find a way to change the color of the subtitles. If this option in VLC is buggy, there are probably other smart players which have such option and this option works.
Reply
#17
(Jul-04-2022, 09:42 AM)Pavel_47 Wrote: The only issue with the 2nd method - there is no possibility to change subtitle color.
The meaning is that it show the original colors made in the the .vtt file.
So if look at a file eg Geo Reportage [101139-013-A].fr.vtt.
Then look at one part.
00:01:52.720 --> 00:01:57.320 line:83% align:center
<c.cyan.bg_black>Une femme d'exception a su donner</c>
<c.cyan.bg_black>une âme à ce havre de paix.</c>
So at 1:52 to 1:57 the color should be cyan.
Now when convert to .ass with l Subtitle Edit,this work perfectly as show subtitle transparent with right color.
To show this in another player eg SMPlayer
[Image: fwuBeC.png]
Reply
#18
I've already contacted yt-dlp staff concerning the issue with subtitles on ARTE channel.
As I mentioned before, there are two version of subtitles for German and French:
  • full version, where everything is subtitled (BAD !)
  • correct version, where only languages other than French (or German) are subtitled (GOOD !)
When you specify option -write-subs, it's BAD version that is downloaded.
To access to GOOD, version, you have to use some browser facilities (e.g. "Web Developer Tools" on Ubuntu) and do it manually.
The yt-dlp developer are agree that this bug must be corrected - soon there will be two versions of subtitles: 'FR' and 'GOOD-FR' ('GE' and 'GOOD-GE')

I guess your .vtt is BAD version, because in GOOD there is no color specifications close to titles (example of GOOD vtt in attachment).
Anyway can you confirm that in your VLC you can change color (because I met difficulties with updating my VLC) ?

Sincerely.
Reply
#19
Well ... site refuses .vtt attachments.
Here is fragment of file ...
Output:
WEBVTT STYLE ::cue(.black) { color: black; } STYLE ::cue(.red) { color: red; } STYLE ::cue(.green) { color: green; } STYLE ::cue(.yellow) { color: yellow; } STYLE ::cue(.blue) { color: blue; } STYLE ::cue(.magenta) { color: magenta; } STYLE ::cue(.cyan) { color: cyan; } STYLE ::cue(.white) { color: white; } STYLE ::cue(.bg_black) { background-color: black; } STYLE ::cue(.bg_red) { background-color: red; } STYLE ::cue(.bg_green) { background-color: green; } STYLE ::cue(.bg_yellow) { background-color: yellow; } STYLE ::cue(.bg_blue) { background-color: blue; } STYLE ::cue(.bg_magenta) { background-color: magenta; } STYLE ::cue(.bg_cyan) { background-color: cyan; } STYLE ::cue(.bg_white) { background-color: white; } 00:00:45.880 --> 00:00:47.080 line:91% align:center 100 % HUMAIN 00:08:28.920 --> 00:08:31.120 line:83% align:center REAL HUMANS (100 % Humain) 00:08:37.040 --> 00:08:38.640 line:91% align:center Gracieux, élégant, 00:08:39.000 --> 00:08:39.920 line:91% align:center efficace, 00:08:41.800 --> 00:08:43.960 line:91% align:center il prolongera votre vie. 00:08:44.560 --> 00:08:46.040 line:91% align:center Bonjour ! 00:08:46.600 --> 00:08:47.400 line:91% align:center Le HubMax PHD 00:08:47.720 --> 00:08:50.400 line:83% align:center se charge de toutes les tâches quotidiennes 00:08:50.600 --> 00:08:53.960 line:83% align:center
Reply
#20
There is no problem at all with .ass(Subtitle Edit) and embed with MKVToolNix.
There is no color change when is embedded then use color in .vtt.
Here in VLC(i have own skin).
[Image: auwOoA.png]
If not embedded just use .vtt the color is white.
[Image: jX0l3c.png]

Both work fine.
Now i am finish with this as all wok as except,what you mess🧬 up i am not sure.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to 'soft-embedd' subtitles with python-ffmpeg Pavel_47 2 2,112 Jul-04-2022, 12:33 PM
Last Post: Pavel_47

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020