FFmpeg thumbnail batch script

General discussion about the media server. Feature requests. Hints, tips and tricks.
Locked
KamikaZee
Posts:9
Joined:Wed Oct 20, 2010 6:30 pm
AV Hardware:Samsung UE40C6000
Linkstation Pro XHL
FFmpeg thumbnail batch script

Post by KamikaZee » Sat Jun 23, 2012 6:51 pm

Hey,

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 :D
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
Paste this into a text file and change the extension to .bat. You'll also need the latest ffmpeg binary. Put both in the base directory of your library and execute the bat file.
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

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: FFmpeg thumbnail batch script

Post by phibertron » Mon Jun 25, 2012 7:10 pm

Nice!
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

Locked