View Full Version : Burn srt to transparent video
Taapo
19th September 2017, 07:21
This question has been asked before on this board, but never fully answered.
Before someone says that you can hardcode subtitles directly to a movie, yes - I know that. There are use cases for what I'm trying to accomplish, but it seems difficult. If one of you could help out, that would be awesome.
What I'm trying to do is to use a SRT/ASS file and avisynth+ to create a transparent video file, with just the subtitles burnt in.
The movie should have the same length as the last timecode in the srt/ass file, and a alpha channel should be set for the background. Export it using lagarith or any other losless codec, so it would be easy to drop into a NLE (Premieren, Vegas, etc).
Is this possible with Avisynth?
sneaker_ger
19th September 2017, 10:06
Use MaskSub() function of (xy-)vsfilter plugin.
Taapo
19th September 2017, 10:40
As I can see, MaskSub needs a video to determine the length of the subtitles, correct? Is there a way to just render out the subtitles without having a resource? Can it take the length from the srt file itself?
MaskSub("subtitles.ext",video.width,video.height,video.framerate,video.framecount)
StainlessS
19th September 2017, 11:08
Is there a way to just render out the subtitles without having a resource? Can it take the length from the srt file itself?
You're gonna need details of source vid anyways, so whats the prob. ?
Taapo
19th September 2017, 15:40
There is no problem. I was just wondering if there was a way to do it without the source file?
smok3
19th September 2017, 15:47
Ffmpeg white on black script
https://github.com/brontosaurusrex/singularity/blob/master/bin/srt2video
Taapo
19th September 2017, 15:57
Ffmpeg white on black script
https://github.com/brontosaurusrex/singularity/blob/master/bin/srt2video
Now, *that's* helpful :) Finally someone who brings forward the right information. Thanks a lot!
smok3
19th September 2017, 17:40
Btw, you dont need to invent alpha, just drop the results to say premiere and set overlay to screen, then position stuff.
Taapo
19th September 2017, 18:14
Well, just when I'm getting myself in a corner again.
Everything works, but I want to use ASS formatting (border around font, and shadow) - I need an alpha channel of course. With normal white text, it would be easy, but with more advanced formatting the screen overlay wouldn't work - or am I wrong?
Currently I'm trying to do this - which works for the most part, but it leaves red traces around the font.
ffmpeg.exe -y -f lavfi -i color=s=1920x1080:color=0xff0000 -an -vf "ass=test.ass,colorkey=0xff0000:0.5:0.5,format=yuva420p" -c:v png -t "00:01:40.544" -threads 0 "video.mov" -stats
poisondeathray
19th September 2017, 18:19
Keying out a color will give you poor results. You're going to get overlap and ratty edges
Black/white and using white as a luma mask will only work... if you have white text. No fancy ASS subs. Otherwise you need 2 videos, 1 for the separate alpha (black/white text is the alpha channel)
Sorry, but the only way you're going to get perfect clean results is with masksub
Taapo
19th September 2017, 18:34
In that case, where can I find a compatible XySubFilter.dll file for use in avisynth+?
The ones at https://code.google.com/archive/p/xy-vsfilter/downloads doesn't seem to work at all ...
Taapo
19th September 2017, 18:39
Sorry, too fast. I found the working version: https://forum.doom9.org/showthread.php?t=168282
Taapo
19th September 2017, 18:43
So I managed to get things working in Avisynth with the following lines:
LoadPlugin("VSFilter.dll")
MaskSub("test.ass",1920,1080,25,3000)
FlipVertical()
I'm not sure how I can get the avs encoded to for example an avi with transparent background. Is there a line that enables saving to an external file, or should I open this in virtualdub and save it that way?
What would be the best way to get a workable file for Premiere Pro?
poisondeathray
19th September 2017, 18:54
yes you can use vdub if you want. Use UT or lagarith in RGBA mode
Taapo
20th September 2017, 08:08
I have gotten this to work perfectly with avisynth.
But I'm still wondering why it would be difficult to get it working using ffmpeg alone? Is there a way to set a background completely transparent in ffmpeg, and have the subtitle visible only?
Transparency is no problem by using these settings:
-c:v png
But is there a way to set a background to transparent using lavfi?
Taapo
20th September 2017, 11:26
So I tried something new: using a transparent png as input, and overlay the subtitles on it.
ffmpeg.exe -y -loop 1 -i transparent-1920x1080.png -vf "ass=test-normal.ass,format=rgba" -c:v png -t "00:00:10.000" -threads 4 "video-transparent.mov" -stats
When I play in a normal video player, I can see the subtitles on a white background. But when I open in Premiere, it shows nothing - just as if the alpha channel is applied to the whole image.
Any ideas?
sneaker_ger
20th September 2017, 12:19
ffmpeg -f lavfi -i "color=color=white@0.0:size=1920x1080,format=rgba,subtitles=test.ass:alpha=1" -t 10 out%d.png
https://superuser.com/questions/1242710/ffmpeg-how-to-render-subtitle-at-a-specific-time-as-an-image
Taapo
20th September 2017, 12:30
Awesome :) Thanks a lot! Setting the background to black is a better way, since white will show through a little bit around the fonts.
sneaker_ger
20th September 2017, 12:36
Eh, isn't the color irrelevant? We're rendering on alpha. I thought color is only to get the picture dimensions.
Taapo
20th September 2017, 12:40
Well, I thought so as well, but have been testing it here with black bordered white fonts - and it shows through. So black background with the black borders gives it maybe a subpixel more black ...
sneaker_ger
20th September 2017, 12:54
I don't understand. Why? Bug?
Taapo
20th September 2017, 12:59
Not sure, need to submit it to ffmpeg developers to know why.
poisondeathray
20th September 2017, 17:34
ffmpeg subtitle/ass alpha isn't preserved correctly . For example, things like drop shadow aren't preserved. Just compare it to masksub or view the alpha channel directly
shekh
20th September 2017, 18:49
I tried it and don`t see any problem. Large shadow with \blur10 looks ok.
Whether you need black or white background depends on application. Normally it should be black and treated as "premultiplied alpha".
However, now I think there is a problem. Alpha is squared - this is wrong.
poisondeathray
20th September 2017, 19:25
left = masksub ; right = ffmpeg
top is composite against a random background (teal)
bottom is alpha channel viewed directly
https://s26.postimg.org/dz0hhjr1l/image.png (https://postimages.org/)
shekh
20th September 2017, 19:33
Yes, I saw ffmpeg source code and it does not implement a path specific for alpha.
Taapo
21st September 2017, 18:00
@poisondeathray how do you show the alpha channel in your example? Is it inside editing software, or something like ffmpeg?
poisondeathray
21st September 2017, 18:17
@poisondeathray how do you show the alpha channel in your example? Is it inside editing software, or something like ffmpeg?
In avisynth, showalpha(). Seems appropriate since this is posted in avisynth usage forum
http://avisynth.nl/index.php/ShowAlpha
Or you can use other programs, video editors, after effects etc.. It's just viewing the "A" in RGBA . Just like you can view red, green, blue channels individually too
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.