PDA

View Full Version : Fixing ABC's end credits


FreQi
7th November 2003, 10:49
I've been working on a function for "fixing" the end credits on ABC's HDTV broadcast. I've had a couple working versions for several months now, but I just re-wrote it this evening to add some flexibility (ie: "nudging"). But before I get any further, here's some background on what I did, why I did it and then how.

I encode a lot of stuff off ABC, and their HDTV programming often has their end credits segment sent out in the Standard Definition (SD) 4:3 with the credits scrolling on the left and the video insert on the right. Since I encode everything to anamorphic 16:9, it seemed silly to put this 4:3 clip at the end with another 4:3 clip set inside that. So I wrote a function that cropped out the credits, slid it all the way to the left of the 16:9 video, and cropped out the 4:3 video insert and used it to fill the remaining space on the right of the credits. It's pretty simple really, compared to last year (I wrote a function to fix those credits on ABC and it was a bit more complicated with a logo overlay, but I digress).

So to illistrate, this function takes frames that look like this
http://freqi.net/forums/abccredfix_2_orig.jpg
and makes them look like this
http://freqi.net/forums/abccredfix_2_fixed.jpg

Here are a couple more examples
http://freqi.net/forums/abccredfix_3_orig.jpg
http://freqi.net/forums/abccredfix_3_fixed.jpg
http://freqi.net/forums/abccredfix_4_orig.jpg
http://freqi.net/forums/abccredfix_4_fixed.jpg

Because I sometimes encode to 2 different resolutions of XviD, and sometimes I encode for DVD's, I wanted to make sure the function could return at least those resolutions. I know it probably would have been easy to write it so that an arbitrary resolution would be possible, but to maintain the correct aspect ratio of the promo insert clip, I wanted to explicitly define the different cases.

So here's the function, loaded with comments:
function ABCreditsFix(clip clip, int start, int end, int width,
\ int "cl", int "ct", int "cr", int "cb",
\ int "pl", int "pt", int "pr", int "pb")
{

# "cl" optional var for nudging credits left edge
cl = Default(cl,0)
# "ct" optional var for nudging credits top edge
ct = Default(ct,0)
# "cr" optional var for nudging credits right edge
cr = Default(cr,0)
# "cb" optional var for nudging credits bottom edge
cb = Default(cb,0)
# "pl" optional var for nudging promo left edge
pl = Default(pl,0)
# "pt" optional var for nudging promo top edge
pr = Default(pr,0)
# "pr" optional var for nudging promo right edge
pt = Default(pt,0)
# "pb" optional var for nudging promo bottom edge
pb = Default(pb,0)

# cropping values for the credits, altered by the nudging values
credits_L = cl+214
credits_T = ct+4
credits_R = cr+250
credits_B = cb-60

# cropping values for the promo, altered by the nudging values
promo_L = pl+470
promo_T = pt+94
promo_R = pr-204
promo_B = pb-167

# crop values for the video clip before and after the "treated" part
pre_L = 4
pre_T = 4
pre_R = -4
pre_B = -4
post_L = 4
post_T = 4
post_R = -4
post_B = -4

pre = (start == 0)
\ ? clip.blankclip(0)
\ : clip.Trim(0,start-1).Crop(pre_L,pre_T,pre_R,pre_B)

post = (end == 0)
\ ? clip.blankclip(0)
\ : clip.Trim(end+1,0).Crop(post_L,post_T,post_R,post_B)

credits = clip.Trim(start,end).ConvertToRGB().Crop(credits_L,credits_T,credits_R,credits_B)
promo = clip.Trim(start,end).ConvertToRGB().Crop(promo_L,promo_T,promo_R,promo_B)

# the rest depends on the target width since this is meant to be
# used only for xvid's at 640x352 or 624x352, or for DVD at 720x480

# when target is 640x352
pre = (width == 640) ? pre.BicubicResize(640,352,0,0.5) : pre
post = (width == 640) ? post.BicubicResize(640,352,0,0.5) : post
credits = (width == 640) ? credits.LanczosResize(160,352) : credits
promo = (width == 640) ? promo.LanczosResize(480,352) : promo

# when target is 624x352
pre = (width == 624) ? pre.BicubicResize(624,352,0,0.5) : pre
post = (width == 624) ? post.BicubicResize(624,352,0,0.5) : post
credits = (width == 624) ? credits.LanczosResize(144,352) : credits
promo = (width == 624) ? promo.LanczosResize(480,352) : promo

# when target is 720x480
pre = (width == 720) ? pre.BicubicResize(720,480,0,0.5) : pre
post = (width == 720) ? post.BicubicResize(720,480,0,0.5) : post
credits = (width == 720) ? credits.LanczosResize(166,480) : credits
promo = (width == 720) ? promo.LanczosResize(554,480) : promo

# now determine the colorspace the video should be in. If the
# output is going to be DVD, we must convert pre and post to YUY2
# for CCE. Otherwise we have to convert credits and promo back
# to YV12 for XviD

pre = (width == 720)
\ ? pre.ConvertToYUY2()
\ : pre
post = (width == 720)
\ ? post.ConvertToYUY2()
\ : post
promo = (width == 720)
\ ? promo.ConvertToYUY2()
\ : promo.ConvertToYV12()
credits = (width == 720)
\ ? credits.ConvertToYUY2()
\ : credits.ConvertToYV12()

return pre++StackHorizontal(credits,promo)++post
}

Using the function is simple. You just edit your video like normal, decimate it and everything, just don't do any cropping or resizing. Then find the frame number that the end credits start on, and the frame number they end on. Then you just call the function with those frames as the first two args, followed by the width you want it all to be sized to. For example...


Import("C:\Program Files\AviSynth 2.5\myFunctions.avs")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\MPEG2Dec3.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\Decomb.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\BT709ToBT601.dll")

MPEG2Source("D:\LtP.s2e07\ltp-s2e07.d2v")
BT709ToBT601()
AddRange(1812,14425)++AddRange(23669,36513)++AddRange(69413,24240)++AddRange(99897,2278)
SelectEven().Decimate(cycle=5)

ABCreditsFix(30513,0, 624)

That'll starte the credit fixing at frame 30513 and continue all the way to the end (0) and make the output at 624x352. Because I found that the promo and end credits are not positioned in the exact same place all the time, I found it necessary to be able to "nudge" the edges of the cropping. For example, if the promo video is positioned more to the right, it may be necessary to nudge the left and right edges to one side or the other. You can do that by using the optional pl pt pr and pb variables. The same goes with the credits cl ct cr and cb. So something like this might be useful...

ABCreditsFix(30513,0, 624, pl=2)
ABCreditsFix(30513,0, 624, pr=10, cr=20)
ABCreditsFix(30513,0, 624, cr=15, cl=-15, pt=20, pb=-20)

Anyway, that pretty much does it. Let me know what you think.