gjhicks
21st July 2006, 14:58
Hi,
I guess that most of the contributors to this forum are generally concerned with using Avisynth with manipulating video files.
But, avoiding the long story, I was looking for a better way to convert digital camera images into a slideshow. So below is a script that (seems) to work fine. The reason for posting is that I am hoping someone can give a few tips to optimise the script. Given that this is my first script, I am certain that there are aspects that should be changed.
Also, am hoping that someone can advise what filter/plugin to use, to reduce the 'shimmering' seen in still images on a TV.
#--------------------------------------------------------------------------------------------------------------
# make a slideshow avi, from images of any size, both landscape and portrait mode,
# preseve the aspect ratio of the images and
# allow for the "TV safe area" by resizing and adding a black border.
# output avi is 720x576, 25fps, RGB 24, no audio
#-------------------------------------------------------------------------------------------------------------
# set up a 'blank' clip to initialise the slideshow variable
global SlideShow=KillAudio(ConvertToRGB24(BlankClip(length=10, width=720, height=576, fps=25, color=$000000)))
#--------------------------------------------------------------------------------------------------------------
# set up a 'blank' fading clip to use with dissolve function
# length of black clip to use for dissolve between slides
global black = 100
# length of dissolve fade
global fade = 50
global fading = KillAudio(ConvertToRGB24(BlankClip(length=black, width=720, height=576, fps=25, color=$000000)))
#--------------------------------------------------------------------------------------------------------------
# final width and height of slide show frame
fr_width = 720
fr_height = 576
# factor to reduce 720x576 image, to allow for TV safe area
tv_safe = 0.10
# TV safe area width and height
global safe_w = int(fr_width - (fr_width*tv_safe))
global safe_h = int(fr_height - (fr_height*tv_safe))
# border required to get width of 720 and height of 576
global border_w = fr_width - safe_w
global border_h = fr_height - safe_h
# total length for each slide, add fade due to reduction via dissolve
global cliplength = 300 + fade
# length of short clip to resize and border
global firstclip = 5
# calculate number of firstclips needed for total slide display time
global nclips = cliplength / firstclip
#--------------------------------------------------------------------------------------------------------------
# first: make a short clip of the image, to use in the resize/add border function
function firstclip(pic)
{
clip=ImageSource(pic, fps = 25, end = firstclip, use_DevIL = true)
return clip
}
#--------------------------------------------------------------------------------------------------------------
# second: resize the image to TV safe area size, preserving the aspect ratio
# and add the required border to get 720x576 final size
function fixsize(pic)
{
fixedpic = pic.width >= pic.height ? Eval("""
aspect = (float(pic.width) / float(pic.height))
w = safe_w
h = int(safe_w / aspect)
extra_b = safe_h - h
border_h = border_h + extra_b
# rounding down of int function can cause the extra border size to be 1 pixel too small, correct with this logic
border_h_t = border_h / 2
border_h_b = border_h - border_h_t
pic = pic.Lanczos4Resize(w,h)
pic = pic.AddBorders(border_w / 2,border_h_t,border_w / 2,border_h_b)
return pic
""") : Eval("""
aspect = (float(pic.width) / float(pic.height))
h = safe_h
w = int(safe_h * aspect)
extra_b = safe_w - w
border_w = border_w + extra_b
# rounding down of int function can cause the extra border size to be 1 pixel too small, correct with this logic
border_w_l = border_w / 2
border_w_r = border_w - border_w_l
pic = pic.Lanczos4Resize(w,h)
pic = pic.AddBorders(border_w_l,border_h / 2,border_w_r,border_h / 2)
return pic
""")
return fixedpic
}
#--------------------------------------------------------------------------------------------------------------
# third: copy the short clip onto itself enough times to build a clip that displays for the specified time
function copyclip(clip, nclips)
{
Assert (nclips >= 0)
return (nclips == 1)
\ ? clip
\ : clip ++ copyclip(clip, nclips - 1)
}
#--------------------------------------------------------------------------------------------------------------
# the main bit
slideshow = slideshow + dissolve (fading, copyclip (fixsize (firstclip ("c:\p01.JPG")), nclips), fading, fade)
slideshow = slideshow + dissolve (fading, copyclip (fixsize (firstclip ("c:\p02.JPG")), nclips), fading, fade)
# and so on
slideshow = slideshow + dissolve (fading, copyclip (fixsize (firstclip ("c:\p99.JPG")), nclips), fading, fade)
return slideshow
#--------------------------------------------------------------------------------------------------------------
Look foreward to some comments/tips/corrections/etc.
Thanks,
Geoff.
I guess that most of the contributors to this forum are generally concerned with using Avisynth with manipulating video files.
But, avoiding the long story, I was looking for a better way to convert digital camera images into a slideshow. So below is a script that (seems) to work fine. The reason for posting is that I am hoping someone can give a few tips to optimise the script. Given that this is my first script, I am certain that there are aspects that should be changed.
Also, am hoping that someone can advise what filter/plugin to use, to reduce the 'shimmering' seen in still images on a TV.
#--------------------------------------------------------------------------------------------------------------
# make a slideshow avi, from images of any size, both landscape and portrait mode,
# preseve the aspect ratio of the images and
# allow for the "TV safe area" by resizing and adding a black border.
# output avi is 720x576, 25fps, RGB 24, no audio
#-------------------------------------------------------------------------------------------------------------
# set up a 'blank' clip to initialise the slideshow variable
global SlideShow=KillAudio(ConvertToRGB24(BlankClip(length=10, width=720, height=576, fps=25, color=$000000)))
#--------------------------------------------------------------------------------------------------------------
# set up a 'blank' fading clip to use with dissolve function
# length of black clip to use for dissolve between slides
global black = 100
# length of dissolve fade
global fade = 50
global fading = KillAudio(ConvertToRGB24(BlankClip(length=black, width=720, height=576, fps=25, color=$000000)))
#--------------------------------------------------------------------------------------------------------------
# final width and height of slide show frame
fr_width = 720
fr_height = 576
# factor to reduce 720x576 image, to allow for TV safe area
tv_safe = 0.10
# TV safe area width and height
global safe_w = int(fr_width - (fr_width*tv_safe))
global safe_h = int(fr_height - (fr_height*tv_safe))
# border required to get width of 720 and height of 576
global border_w = fr_width - safe_w
global border_h = fr_height - safe_h
# total length for each slide, add fade due to reduction via dissolve
global cliplength = 300 + fade
# length of short clip to resize and border
global firstclip = 5
# calculate number of firstclips needed for total slide display time
global nclips = cliplength / firstclip
#--------------------------------------------------------------------------------------------------------------
# first: make a short clip of the image, to use in the resize/add border function
function firstclip(pic)
{
clip=ImageSource(pic, fps = 25, end = firstclip, use_DevIL = true)
return clip
}
#--------------------------------------------------------------------------------------------------------------
# second: resize the image to TV safe area size, preserving the aspect ratio
# and add the required border to get 720x576 final size
function fixsize(pic)
{
fixedpic = pic.width >= pic.height ? Eval("""
aspect = (float(pic.width) / float(pic.height))
w = safe_w
h = int(safe_w / aspect)
extra_b = safe_h - h
border_h = border_h + extra_b
# rounding down of int function can cause the extra border size to be 1 pixel too small, correct with this logic
border_h_t = border_h / 2
border_h_b = border_h - border_h_t
pic = pic.Lanczos4Resize(w,h)
pic = pic.AddBorders(border_w / 2,border_h_t,border_w / 2,border_h_b)
return pic
""") : Eval("""
aspect = (float(pic.width) / float(pic.height))
h = safe_h
w = int(safe_h * aspect)
extra_b = safe_w - w
border_w = border_w + extra_b
# rounding down of int function can cause the extra border size to be 1 pixel too small, correct with this logic
border_w_l = border_w / 2
border_w_r = border_w - border_w_l
pic = pic.Lanczos4Resize(w,h)
pic = pic.AddBorders(border_w_l,border_h / 2,border_w_r,border_h / 2)
return pic
""")
return fixedpic
}
#--------------------------------------------------------------------------------------------------------------
# third: copy the short clip onto itself enough times to build a clip that displays for the specified time
function copyclip(clip, nclips)
{
Assert (nclips >= 0)
return (nclips == 1)
\ ? clip
\ : clip ++ copyclip(clip, nclips - 1)
}
#--------------------------------------------------------------------------------------------------------------
# the main bit
slideshow = slideshow + dissolve (fading, copyclip (fixsize (firstclip ("c:\p01.JPG")), nclips), fading, fade)
slideshow = slideshow + dissolve (fading, copyclip (fixsize (firstclip ("c:\p02.JPG")), nclips), fading, fade)
# and so on
slideshow = slideshow + dissolve (fading, copyclip (fixsize (firstclip ("c:\p99.JPG")), nclips), fading, fade)
return slideshow
#--------------------------------------------------------------------------------------------------------------
Look foreward to some comments/tips/corrections/etc.
Thanks,
Geoff.