High Quality Thumbnails

I didn’t like the grainy thumbnails Plex produced (Emby is much cleaner!!!) … especially when it came to umm… “adult entertainment”. So I wrote the batch file below to scan media and generate high quality thumbnails for your media. - Enjoy

@echo off
echo ***** Starting Thumbnails *****

for /R %%f in (*.avi *.mkv *.mp4 *.wmv *.mov *.mpeg *.mpg) do (
	If NOT Exist "%%~pf%%~nf.png" (
		echo Creating Thumnail for %%f
		rem #############Getting Duration Start################
		for /f "tokens=2-5 delims=:., " %%a in (
			'c:\ffmpeg\bin\ffmpeg.exe -i "%%f" 2^>^&1 ^| find "Duration:"'
        	) do (
			rem set /p =%%~nxf^|<nul
			setlocal enableDelayedExpansion
			set /a "duration=1%%a*3600 + 1%%b*60 + 1%%c - 366100"

			rem echo %%f 
			rem echo !duration!
        	rem #############Getting Duration End################
		
			if !duration! LSS 1500 (
				rem #####Smaller Files#####
		 		c:\ffmpeg\bin\ffmpeg.exe -ss 1 -i "%%f" -vf "select=gt(scene\,0.6)" -vsync vfr -vf fps=fps=1/100 -vframes 1 "%%~pf%%~nf.png" -y
		 		rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "scale=-1:900" -vframes 1 "%%~pf%%~nf.png" -y
		 		rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "crop=600:900" -vframes 1 "%%~pf%%~nf.png" -y

			) else (
				#####Larger Files#####
				c:\ffmpeg\bin\ffmpeg.exe -ss 60 -i "%%f" -vf "select=gt(scene\,0.6)" -vsync vfr -vf fps=fps=1/1500 -vframes 1 "%%~pf%%~nf.png" -y
		 		rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "scale=-1:900" -vframes 1 "%%~pf%%~nf.png" -y
		 		rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "crop=600:900" -vframes 1 "%%~pf%%~nf.png" -y
			)

		rem ############Looks Like We Got a ■■■■ Thumbnail Let's Try Again
			FOR %%E IN ("%%~pf%%~nf.png") DO (
				if %%~zE LSS 400000 (
				
					echo Bad Image Detected Trying Again			
					if !duration! LSS 1500 (
						rem #####Smaller Files#####
		 				c:\ffmpeg\bin\ffmpeg.exe -ss 3 -i "%%f" -vf "select=gt(scene\,0.6)" -vsync vfr -vf fps=fps=1/100 -vframes 1 "%%~pf%%~nf.png" -y
		 				rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "scale=-1:900" -vframes 1 "%%~pf%%~nf.png" -y
		 				rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "crop=600:900" -vframes 1 "%%~pf%%~nf.png" -y

					) else (
						rem #####Larger Files#####
						c:\ffmpeg\bin\ffmpeg.exe -ss 120 -i "%%f" -vf "select=gt(scene\,0.9)" -vsync vfr -vf fps=fps=1/1500 -vframes 1 "%%~pf%%~nf.png" -y
		 				rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "scale=-1:900" -vframes 1 "%%~pf%%~nf.png" -y
		 				rem c:\ffmpeg\bin\ffmpeg.exe -i "%%~pf%%~nf.png" -filter "crop=600:900" -vframes 1 "%%~pf%%~nf.png" -y
					)
				)
			) 
			endlocal
		)
	) else (
		echo Skipped %%f
	)
	echo ------------------------------------------------------------------------------------------------------------------------------------------------------
)
echo ***** Finished Thumbnails*****

How it works:

  1. Checks if image thumbnail already exists
  2. If image exists -> Skip
  3. If Image doesn’t use FFMPEG to try and find the most qualified image to represent your media
  4. If the image generated is too small it means your probably pulled a black image, and it will try again.

You’ll need to download https://www.ffmpeg.org/ and put it in c:\ffmpeg

Can’t you use the Plextranscoder.exe instead of a second copy of ffmpeg ?

You can if you want…This was made to run recursively against a file tree from my desktop and isn’t running directly on the server… Feel free to make your own modifications. It’s not like ffmpeg is a huge difficult install.