Since I wanted my movies to have thumbnails I decided to write a little script that goes through my library and creates them using ffmpeg.
Since it's pretty much finished right now I decided to share it
Hope anyone else finds this useful
Code: Select all
@echo off
if exist done.txt (dir /s /b /o -s *.mp4 *.mkv *.avi *.mpg *.ts *.mpeg *.m2ts *.vob *.ifo > files.txt
FOR /F "delims=*" %%A IN ('findstr /l /v /g:done.txt files.txt') DO CALL:GENERATE "%%A"
cls
@echo on
echo All done
@echo off
pause
del files.txt
goto :eof)
FOR /F "delims=*" %%A IN ('dir /s /b /o -s *.mp4 *.mkv *.avi *.mpg *.ts *.mpeg *.m2ts *.vob *.ifo') DO CALL:GENERATE"%%A"
cls
@echo on
echo All done
@echo off
pause
goto :eof
:GENERATE
if exist "%~dnp1.jpg" (goto:done "%~dnpx1")
set /a randnum=%random%*59/32767+1
@ffmpeg -i "%~dnpx1" -deinterlace -an -ss 00:00:%randnum% -t 00:00:01 -r 1 -y -s 320x240 -vcodec mjpeg -f mjpeg "%~dnp1.jpg"
echo %~dnp1.jpg created
echo %~dnpx1>> done.txt
goto :eof
:done
findstr /C:"%~dnpx1" done.txt
if errorlevel 1 (echo %~dnpx1>> done.txt
goto :eof)
goto :eof
The script will create a text file calle done.txt, where it stores which files have already been processed.
You can also adapt it a little bit:
- dir /s /b /o -s *.mp4 *.mkv *.avi *.mpg *.ts *.mpeg *.m2ts *.vob *.ifo
This part appears twice, it's just a list of files that will be processed by the script, you can add filetypes by simply appending *.extension to this list. Make sure to edit both instances
- set /a randnum=%random%*59/32767+1
This sets the time from where to extract the thumbnail. By default it will generate a thumbnail from a random time point within the first 60 seconds of the file. The red number is the max time that will be taken into account -1 second. So if you want your thumbnail to be within the first 10 seconds of the file you'd need to replace the 59 with just 9. More than 60 seconds into the file is not possible with the way I scripted it atm.
You can also set a fixed time point by replacing "-ss 00:00:%randnum%" with anything you want in the format -ss hh:mm:ss