Log in

View Full Version : Generate thumbnails from AVS


morphinapg
15th March 2009, 03:51
I'm looking for some kind of program or something that will take an AVS script input, frame number, and output size and output a thumbnail. I'm doing it through ffmpeg right now (not with AVS scripts right now) but it's pretty slow. This is for faster thumbnail generation in ASXGui.

Sagekilla
15th March 2009, 04:52
This is pretty easy.


# To do: Add support for padding to any arbitrary shape other than 1:1.
function GenerateThumbnails(clip src, int "width", int "height", bool "pad", string "path", int "start", int "end")
{
width = default(width, 100)
height = default(height, 100)
pad = default(pad, True)
path = default(path, "thumbail")
start = default(start, 0)
end = default(end, src.FrameCount()-1)

src = src.ConvertToRGB32().KillAudio()
x = src.width()
y = src.height()

padLen = int(abs(x - y) / 2)
padded = (x > y) ? src.AddBorders(0, padLen, 0, padLen) :
\ src.AddBorders(padLen, 0, padLen, 0)

src = (pad == True) ? padded : src
src = src.Spline36Resize(width, height)

src = ImageWriter(src, path + "_", start, end, "jpg").Crop(0,0,16,16)
return src
}


Load it up in VirtualDub, or something like that, and let it play.

morphinapg
15th March 2009, 22:36
This is pretty easy.


# To do: Add support for padding to any arbitrary shape other than 1:1.
function GenerateThumbnails(clip src, int "width", int "height", bool "pad", string "path", int "start", int "end")
{
width = default(width, 100)
height = default(height, 100)
pad = default(pad, True)
path = default(path, "thumbail")
start = default(start, 0)
end = default(end, src.FrameCount()-1)

src = src.ConvertToRGB32().KillAudio()
x = src.width()
y = src.height()

padLen = int(abs(x - y) / 2)
padded = (x > y) ? src.AddBorders(0, padLen, 0, padLen) :
\ src.AddBorders(padLen, 0, padLen, 0)

src = (pad == True) ? padded : src
src = src.Spline36Resize(width, height)

src = ImageWriter(src, path + "_", start, end, "jpg").Crop(0,0,16,16)
return src
}


Load it up in VirtualDub, or something like that, and let it play.

Cool, thanks. I already use a command line program that can run an avs script to check for errors, so it can probably be used simply to run the script and generate the file. Thanks!

Sagekilla
15th March 2009, 23:33
The only issue is that this would take as long as your movie is. Are you using this to create one thumbnail for every frame, or do you wanna do it like every X number of frames? If the latter, then you can add in a SelectEvery(X,0) before you run that script. That way, you can do, for X = 30, select 1 frame for every 30 frames of the movie. Or for X = 50, 1 frame out of every 50, etc.

morphinapg
16th March 2009, 00:54
The only issue is that this would take as long as your movie is. Are you using this to create one thumbnail for every frame, or do you wanna do it like every X number of frames? If the latter, then you can add in a SelectEvery(X,0) before you run that script. That way, you can do, for X = 30, select 1 frame for every 30 frames of the movie. Or for X = 50, 1 frame out of every 50, etc.

My GUI has a trackbar slider that the user can slide to pick a frame for the thumbnail. My GUI would then write the above script calling the function based on user selected frame, and GUI selected resolution, and then draw that outputted frame to the GUI.

Sagekilla
16th March 2009, 04:07
In that case, you may want to remove the "padding" parameter and just have your GUI pass off the "width" and "height" parameters.