Log in

View Full Version : Batch script for creating thumbnails


GodofaGap
9th November 2010, 13:31
I don't know if this is useful to anyone, but I'm posting it here anyway. :)

I've created this batch script for creating thumbnails for WMC and other HW that can use jpg files with the same name as the video file as thumbnail. It uses avisynth, avs2yuv and Haali (avss.dll, for DSS2). I found it necessary because I was not happy how WMC generated thumbnails for mkv's (it takes the first frame which is usually black).

Some of the settings can be adjusted. (read comments in the script for usage)

@echo off

REM Thumbnail Creator

REM This script creates JPG thumbnails of various media files for Vista Media Center and other software and HW devices that can make use of these.
REM It requires Avisynth, avs2yuv and Haali Media Splitter (copy avss.dll from Haali to Avisynth plugins directory).
REM Usage: drag and drop a directory on the bat file.

REM Don't use quotes or trailing backslashes for the AVS2YUV path variable
REM BASE_HEIGHT will be the height of the thumbnail in pixels
REM POS_PERC is the position of the frame used for the thumbnail in percentage of the video length
REM Separate file extensions to check with ;

SET AVS2YUV_PATH=c:\tools
SET BASE_HEIGHT=240
SET POS_PERC=20
SET FILE_EXT=*.mkv;*.mp4

FOR /R %1 %%G IN (%FILE_EXT%) DO CALL :createthumb "%%G"

del "%AVS2YUV_PATH%\image.avs" 2> nul

echo Done!
pause
exit

:createthumb

REM Comment this if you want existing thumbnails to be replaced
IF EXIST "%~dpn1.jpg" GOTO :eof

del "%~dpn1.jpg" 2> nul

REM Deletes the Vista thumbnail file
del /ah "%~dp1ehthumbs_vista.db" 2> nul

echo DSS2(%1) > "%AVS2YUV_PATH%\image.avs"
echo Trim(framecount/(100/%POS_PERC%),-1).ConverttoRGB24.BicubicResize(Round(%BASE_HEIGHT%*width/(height*4))*4,%BASE_HEIGHT%) >> "%AVS2YUV_PATH%\image.avs"
echo ImageWriter("%~dpn1", type="jpeg") >> "%AVS2YUV_PATH%\image.avs"

echo Creating thumbnail for %~nx1...
"%AVS2YUV_PATH%\avs2yuv.exe" "%AVS2YUV_PATH%\image.avs" -o nul
rename "%~dpn1000000.jpeg" "%~n1.jpg"

GOTO :eof

I hope it is useful for someone else too.