View Full Version : subtitling bluebox howto?
fray
18th January 2005, 00:15
Hi,
I have subtitles with black boxes around them
I want to blend into a video.
I'd like to have only one bitmap file per subtitle -
black, grey values and white from that bitmap should appear
in the video, the colored rest should not - just
like a bluebox screen in TV studio use. The subtitles have to
cover titles in another language, that's why they can't be see thru.
Is this possible to to in avisynth or do I need
two bitmaps for each subtitle? Can I convert the "blue" information
in the bitmap into a mask?
Also, what's the best way to position the bitmaps in a video?
I know the frame in- and out-number for each of the bitmaps so
my best attempt so far is putting them together using the Freezeframe
command plus some blank screens.
(Alas I did not manage to post the image - please imagine a blue
colored bmp 720x576 pixels that has two black bars with white
text at the bottom)
fray
18th January 2005, 15:24
Here's a followup to my question.
This code works, apart from two problems:
1. There's a small blue line on top of the subtitle.
2. I can't get the mask to work 100%. There's always a little bit of blue left on the whole of the result image. I can cheat by performing a greyscale action on the subtitles, but this would still darken the result image.
# Example image to put the subtitle on
# Greyscaled to show the color problems.
testcard = ColorBars().Greyscale().ConvertToYV12
# get a blue mask clip
maskclip = BlankClip(clip=testcard,color=$0000FF).ConvertToYV12
# Example subtitle file with blue backgroud as above
# This image has the same blue blackground as the maskclip above
# and has black bars with white text. Resize to make it fit on the
# testcard.
subs = ImageSource("c:\blue.bmp").ConvertToYV12.PointResize(640,480)
# Generating mask
maskclip = subtract(subs,maskclip).Levels(128, 1, 130,0, 255)
# put subtitle on top of image using mask made before, Loop this.
Loop(Overlay(testcard,subs,mask=maskclip,mode="blend",opacity=1),-1)
trolltuning
18th January 2005, 18:29
I am trying to follow along (I couldn't begin to solve your problem myself)
when I create a bit-map in Paint and try to open your script I get this message:
filter tried to create video frame with invalid pixel_type
Are their special requirements for the bitmap that I've missed?
fray
18th January 2005, 19:17
Hi, I tried to get this to run using Paint and also failed to get results. On the machine I tried this I had Photoshop 6.0 and I used the clipboard to paste the blue screen generated by Avisynth into the painting program.
I got the script to work here, but without any usable results.
Do get it to work, I generated the blue screen in Avisynth, ran the
script in VirtualDub,pressed Crtl-1 to copy the image into the clipboard. In Paint I used paste to get a blue screen image, I added a black box, put some white text into it and saved the result as a 24bit bmp-file. The results were different from the other computer. Also, I think this aproach is way too difficult, there must be an easier way to convert a color into a transparency layer.
While browsing the avisynth site, I found the "ColorKeyMask [RGB32]" command in the manual though. This one doesn't seem to run with Avisynth 2.51, but maybe I'll install the older version to try this instead.
I'm going to continue to try several things to get this to work - if I'm successful I'll post it here.
Wilbert
18th January 2005, 20:55
Could you upload blue.bmp somewhere?
fray
19th January 2005, 12:00
http://img34.exs.cx/img34/6145/blue36hl.th.jpg (http://img34.exs.cx/my.php?loc=img34&image=blue36hl.jpg)
You'll have to save the large image as blue.jpg for this test
The result is:
http://img116.exs.cx/img116/636/result6eo.th.jpg (http://img116.exs.cx/my.php?loc=img116&image=result6eo.jpg)
Problems with it again:
- The black bar is not 100% black
- There's a litte blue line on that is not masked
- The image is too blue: The white block on the right should
be 100% white.
The working script:
testcard = ColorBars().Greyscale().ConvertToYV12
# get a blue mask clip
maskclip = BlankClip(clip=testcard,color=$0000FF).ConvertToYV12
# Example subtitle file with blue backgroud as above
subs = ImageSource("{your path}blue.jpg").ConvertToYV12.PointResize(640,480)
maskclip = subtract(subs,maskclip).Levels(128, 1, 130,0, 255)
Loop(Overlay(testcard,subs,mask=maskclip,mode="blend",opacity=1),-1)
Wilbert
20th January 2005, 22:53
I also get those lines, I have to look at it more closely.
Two remarks:
1) The blue in blue.jpg is not the same as in colorbars (the latter is $0f0fb4 or R15 G15 B180).
2) The right rectangle is not white, it's grey (R180 G180 B180).
My try:
testcard = ColorBars().Greyscale().ConvertToYV12
# Example subtitle file with blue backgroud as above
subs = ImageSource("F:\TestClips\blue.jpg").ConvertToRGB32
maskclip = ColorKeyMask(subs, $0f0fb4, 2)
Overlay(testcard, subs, mask=showalpha(maskclip), mode="blend", opacity=1)
Results: see attachment.
Wilbert
20th January 2005, 22:54
Ok, now the attachment :)
Wilbert
20th January 2005, 22:56
and my blue.jpg.
Wilbert
24th January 2005, 21:15
The blue was not uniform. Highering the tolerance:
maskclip = ColorKeyMask(subs, $0f0fb4, 60)
did the trick (near the black rectangles the blue is given by R23 G22 B124; due to the jpeg-compression I guess).
fray
25th January 2005, 08:17
Thanks for the tip.
I was without internet for a couple of days thanks
to my lousy DSL provider so I won't be able to try this
before the weekend.
I'll post a followup message on success :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.