Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th September 2017, 07:21   #1  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
Burn srt to transparent video

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?

Last edited by Taapo; 19th September 2017 at 07:22. Reason: sentence
Taapo is offline   Reply With Quote
Old 19th September 2017, 10:06   #2  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Use MaskSub() function of (xy-)vsfilter plugin.
sneaker_ger is offline   Reply With Quote
Old 19th September 2017, 10:40   #3  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
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?

Code:
MaskSub("subtitles.ext",video.width,video.height,video.framerate,video.framecount)
Taapo is offline   Reply With Quote
Old 19th September 2017, 11:08   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by Taapo View Post
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. ?
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 19th September 2017, 15:40   #5  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
There is no problem. I was just wondering if there was a way to do it without the source file?
Taapo is offline   Reply With Quote
Old 19th September 2017, 15:47   #6  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,392
Ffmpeg white on black script
https://github.com/brontosaurusrex/s.../bin/srt2video
__________________
certain other member
smok3 is offline   Reply With Quote
Old 19th September 2017, 15:57   #7  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
Quote:
Originally Posted by smok3 View Post
Now, *that's* helpful Finally someone who brings forward the right information. Thanks a lot!
Taapo is offline   Reply With Quote
Old 19th September 2017, 17:40   #8  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,392
Btw, you dont need to invent alpha, just drop the results to say premiere and set overlay to screen, then position stuff.
__________________
certain other member
smok3 is offline   Reply With Quote
Old 19th September 2017, 18:14   #9  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 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.

Code:
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
Taapo is offline   Reply With Quote
Old 19th September 2017, 18:19   #10  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,374
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
poisondeathray is offline   Reply With Quote
Old 19th September 2017, 18:34   #11  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
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 is offline   Reply With Quote
Old 19th September 2017, 18:39   #12  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
Sorry, too fast. I found the working version: https://forum.doom9.org/showthread.php?t=168282
Taapo is offline   Reply With Quote
Old 19th September 2017, 18:43   #13  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
So I managed to get things working in Avisynth with the following lines:

Code:
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?
Taapo is offline   Reply With Quote
Old 19th September 2017, 18:54   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,374
yes you can use vdub if you want. Use UT or lagarith in RGBA mode
poisondeathray is offline   Reply With Quote
Old 20th September 2017, 08:08   #15  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
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:
Code:
-c:v png
But is there a way to set a background to transparent using lavfi?
Taapo is offline   Reply With Quote
Old 20th September 2017, 11:26   #16  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
So I tried something new: using a transparent png as input, and overlay the subtitles on it.

Code:
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?
Taapo is offline   Reply With Quote
Old 20th September 2017, 12:19   #17  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Code:
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/1242...me-as-an-image
sneaker_ger is offline   Reply With Quote
Old 20th September 2017, 12:30   #18  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
Awesome Thanks a lot! Setting the background to black is a better way, since white will show through a little bit around the fonts.
Taapo is offline   Reply With Quote
Old 20th September 2017, 12:36   #19  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Eh, isn't the color irrelevant? We're rendering on alpha. I thought color is only to get the picture dimensions.
sneaker_ger is offline   Reply With Quote
Old 20th September 2017, 12:40   #20  |  Link
Taapo
Registered User
 
Join Date: Jul 2016
Posts: 14
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 ...
Taapo is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:57.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.