Log in

View Full Version : Adding hard-coded subpicture on some frames


EuropeanMan
1st April 2011, 16:20
Hi guys,

(I'm gone for most of the day to work, but thought I'd post this in the meantime).

I have a lag file I've encoded.

There are some frames where I need to attach a HARD-CODED SUBPICTURE that translates a message on the screen just below. I realise I could add it to my srt file (which I can later convert to sup)...but I'd rather just add it to the frame itself...as other subtitles already appear during this time period. This will occur in some 8 sections of this movie.

Since I call up my avisource in an avs and feed through CCE...what would be a sample script to add it to my avs so that my HARD-CODED SUBS appear on the mpv?


avisource("c:\...\desktop\lag.avi")
converttoyuy2()

a=last
a1=a.trim(0,9999)
b=a.trim(10000,11000). #add hardcoded sub in YELLOW COLOUR in a SPECIFIC PORTION OF THE
# FRAME - let's say bottom left corner at least 50 pixels away from either edge
c=a.trim(11001,80000)
d=a.trim(80000,80500). #add hardcoded sub in RED COLOUR

# e=, f= ...etc as long as I need until final frame

a1+b+c+d (....)
addborders(0,52,0,52)
spline36resize(720,480)


Note: Hard-coded subpicture would be something like "The Netherlands", "Switzerland"...I'm adding city/country names in various portions of the film...
I'll assume my script would go something like that....

Many thanks in advance...

EuropeanMan
1st April 2011, 16:24
Seeing as my output would ALSO BE ANAMORPHIC 16:9 NTSC OUTPUT...would the added text ALSO BE STRETCHED? And how could I avoid that? (if possible)

txporter
1st April 2011, 16:32
You should be able to use Subtitle (http://avisynth.org/mediawiki/Subtitle) for that if you just want to use static text. It will be written into the video frame, so it will be affected by your encoding pixel size.

poisondeathray
1st April 2011, 17:12
Seeing as my output would ALSO BE ANAMORPHIC 16:9 NTSC OUTPUT...would the added text ALSO BE STRETCHED? And how could I avoid that? (if possible)

What is your source ?

If it's square pixel format (e.g. 1920x1080), add them before your resize to 720x480 and there should be no problem

EuropeanMan
2nd April 2011, 06:07
My source is my own DVD9...but unfortunately there aren't subtitles for the text on the screen...just the dialogue spoken in the film. It was NTSC...which I then encoded via Avisynth to a lag file...which is @ 720x304. I then feed this LAG into CCE with AddBorders line to finally resize to 720x480 and get anamorphic output 16:9.

However, I've never added hard-coded subtitles before and it's just for basically 2-3 minutes worth of frames in my 2 hour movie. I ''KNOW'' the sections where I'd like to put them...but don't know the HOW. Thanks

EuropeanMan
2nd April 2011, 06:10
You should be able to use Subtitle (http://avisynth.org/mediawiki/Subtitle) for that if you just want to use static text. It will be written into the video frame, so it will be affected by your encoding pixel size.

Thanks, reading about this filter now :):thanks:

manono
2nd April 2011, 08:44
It was NTSC...which I then encoded via Avisynth to a lag file...which is @ 720x304. I then feed this LAG into CCE with AddBorders line to finally resize to 720x480 and get anamorphic output 16:9.
This is a 2.37:1 film? So you not only cropped but also resized to get 720x304? If so, you can add the text and it'll look 'normal' on the 16:9 DVD. But if 720x304 is 1:1 (square pixel), you'll have to do more than just an AddBorders to make the aspect ratio come out right when you're all done. You'll also have to resize yet again.

EuropeanMan
2nd April 2011, 22:34
Well buddy, the A/R is 2.35 (or so...) What more do I have to do then? Because I'm SURE the letters will be then stretched :(

poisondeathray
2nd April 2011, 22:56
add it using square pixels , this is how graphics, titles etc... are added to dvd's in the first place

a 720x480 16:9 dvd will display as 854x480 on a pc monitor or using 1:1 pixels, so if you add your subtitle() or use whatever filter at that square pixel resolution , when you "squeeze" it down to 720x480 it will "stretch" back to 854x480 upon playback it will look normal

it you don't want to go through resizing the video back & forth , you should be able to resize a png image with alpha channel using overlay() (i.e. prepare the overlay as 854x480, then resize that to 720x480 to overlay onto the video.)

ajp_anton
2nd April 2011, 23:31
v = source # 720x480 video
a = v.pointresize(854,480) # 854x480 being the stretched resolution at playback
s = a.subtitle("whatever text you want to insert") # subs being added into the stretched video
d = mt_makediff(s,a,chroma="process")
f = d.spline36resize(v.width,v.height) # "reverse stretching" only the subtitles
return mt_adddiff(f,v,chroma="process")

Gavino
3rd April 2011, 00:04
ajp_anton, that doesn't look to me like it will work.
Firstly, if the subtitle differs by more than 128 from what is underneath it, the difference will be clipped in mt_makediff.
Secondly, since the difference is made against a PointResize'd clip, it will not be exact when added back later to the original.

ajp_anton
3rd April 2011, 00:24
Ah forgot about clipping. Could work around it by doing two diffs using mt_lutxy though (one for positive changes, one for negative).
About pointresize, I compared it against a spline36resize but couldn't notice any difference so I went with the faster.

manono
3rd April 2011, 00:51
Well buddy, the A/R is 2.35 (or so...) What more do I have to do then? Because I'm SURE the letters will be then stretched :(
Your Lag.avi is square pixel (apparently). So you add in the text while it's still at that resolution. When playing the Lag things look 'normal', right? And round things are round, right? Then you Resize and AddBorders to prepare for the 16:9 MPEG-2 encoding. One way would be like this:

#Add your text before the resize
LanczosResize(Width,368)
AddBorders(0,56,0,56)

That will make your text look too thin when viewed at 720x480. But after the encoding and authoring, it'll look 'normal' again.

EuropeanMan
4th April 2011, 04:37
^ ahhh yes thanks Manono

I was also toying around right now and was thinking something like this:

avisource("c:\....lag.avi")
addborders(0,52,0,52)
spline36resize(854,480) # now it looks like 16:9 'stretched'
...
...
... add lines to add text to certain frames
spline36resize(720,480)

---> now i can feed this into CCE and click 16:9 in setup boxes there...