How I could use ExtractThumb ?
#1
Hi, i want to open some video file and ExtractThumb seeking to some positions.
I saw that XBMC makes this and i want to do it into my plugin to work with those thumbs.
There is any function to Extract a Thumb for a video seeking the position?
Thanks in advance.
Reply
#2
not available from python, but we do have such a function. although i doubt it takes the position as a parameter.
Reply
#3
spiff Wrote:not available from python, but we do have such a function. although i doubt it takes the position as a parameter.

Ok, thanks.

Is it possible i could use your function? or any idea i could make a function to seek a position and extract a thumb.

Thanks a lot.
Reply
#4
sure, patch welcome.
Reply
#5
spiff Wrote:sure, patch welcome.

What? Huh

I need code or help to make code of the function.

Thanks
Reply
#6
Anyone could help me to make a function that extracts thumbs for video files seeking the position?
Thanks in advance.
Reply
#7
When we create bookmarks seeking time of a movie, xbmc save a thumbnail into \XBMC\UserData\Thumbnails\Video\Bookmarks
I want to save thumbnails of a movie in a folder seeking its positions and without play the movie.
Any idea?
Thanks.
Reply
#8
I found this:
http://www.crocodile.org/lord/thumbextraction/vthumb.py

Quote:import Image
import sys, os, urllib, time, math, shutil, string
import getopt

NFRAMES=100
FFMPEG="ffmpeg"
TMPDIR="."
THUMB_SIZE = 128, 128

def main():
alsosave = []
nframes = NFRAMES
verbose = False
thumb = False
infile = None
outfile = None
try:
opts, args = getopt.getopt(sys.argv[1:], "vs:f:n:o:t", ["verbose","save","file","nframes","ofile","thumbnail"])
except getopt.GetoptError:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-f", "file"):
infile=a
if o in ("-o", "ofile"):
outfile=a
if o in ("-n", "nframes"):
nframes=int(a)
if o in ("-s", "save"):
alsosave = map(int,string.split(a,","))
if o in ("-v", "verbose"):
verbose=True
if o in ("-t", "thumbnail"):
thumb=True

if len(args) !=0 or not infile or not outfile or nframes<1:
usage()
sys.exit(2)

sys.exit(find_thumb(infile, outfile, nframes, alsosave, verbose, thumb))

def usage():
print "Usage vthumb [-t] [-v] [-s N,N,N...] -f <infile> -o <outfile> [-n nframes]"
print "\t-f Input video file"
print "\t-o Output base file name for thumbnails (w/o extension)"
print "\t-v Be verbose"
print "\t-t Scale extracted frame into smaller 128x128 thumbnail"
print "\t-s Specify frame numbers which to save additionally"
print "\t-n Number of frames to examine"

def frame_rmse(hist, median):
res = 0.0
n = len(median)
for j in range(n):
err=median[j]-float(hist[j]);
res+=(err*err)/n;
return math.sqrt(res);

def img_hist(im):
return im.histogram()

def copy_thumb(src, dst, thumb):
if thumb:
im = Image.open(src)
im.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
im.save(dst, "JPEG")
else:
shutil.copyfile(src, dst)

def find_thumb(infile, outfile, nframes, alsosave, verbose, thumb):
if verbose:
print "Processing %s" % infile
print "Extracting frames"
framemask = "frame" + str(time.time()) + ".%d.jpg"
cmd = "%s -y -vframes %d -i %s %s" % (FFMPEG, nframes, infile, framemask)
if not verbose:
cmd = cmd + " -v '-1' > /dev/null 2>&1"
if os.system(cmd) != 0:
print "Error invoking ffmpeg"
return 10
if verbose:
print "Analyzing frames"
hist=[]
for i in range(1,nframes+1):
fname = framemask % i
if not os.path.exists(fname):
break
if verbose:
print "\tProcessin frame %d" % i
im = Image.open(fname).convert("RGB")
if not im or im.mode == None:
print "Error reading frame %d" % i
return 20
hist.append(img_hist(im))
if i in alsosave:
thumbfname = outfile + "."+str(i)+".jpg"
if thumb:
im.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
im.save(thumbfname, "JPEG")
else:
shutil.copyfile(fname, thumbfname)

if verbose:
print "Calculating averages"
n=len(hist)
avg=[]
for c in range(len(hist[0])):
ac = 0.0
for i in range(n):
ac = ac + (float(hist[i][c])/n)
avg.append(ac)

minn = -1
minRMSE = -1
for i in range(1,n+1):
rmse = frame_rmse(hist[i-1], avg);
if minn==-1 or rmse<minRMSE:
minn = i
minRMSE = rmse
#print "Frame %d RMSE %f" % (i, rmse)
if verbose:
print "BEST Frame: %d" % minn

rc = 0
try:
# Copy best
copy_thumb(framemask % (minn), outfile + ".jpg", thumb)
except:
print "Error copying thumb file"
rc = 100

if verbose:
print "Removing temp files"
for i in range(1,n+1):
fname = framemask % i
os.unlink(fname)

return rc

if __name__ == '__main__':
main()


And this:
http://myy.helia.fi/~karte/mplayer-video...ailer.html

I think the first code could be used to make thumbnails seeking position but I dont know how to begin with.
Anyone know how I could make a python function that let me take thumbnails for a input file (video) seeking a position or time??

Thanks
Reply
#9
Hi, Im triying to make thumbnails using ffmpeg but doesnt work!

If I execute this with cmd (under windows 7):
Code:
"C:\Program Files (x86)\XBMC\scripts\Base De Datos\ffmpeg.exe" -y -ss 30 -i "C:\Program Files (x86)\XBMC\scriptsmovie.avi" -f mjpeg -vframes 1 -s 120x90 -an "C:\Program Files (x86)\XBMC\scripts\Base De Datos\thumbnail.jpg"

work fine!

But, if I execute this code into my python plugin:
Code:
os.system('"C:\Program Files (x86)\XBMC\scripts\Base De Datos\ffmpeg.exe" -y -ss 30 -i "C:\Program Files (x86)\XBMC\scriptsmovie.avi" -f mjpeg -vframes 1 -s 120x90 -an "C:\Program Files (x86)\XBMC\scripts\Base De Datos\thumbnail.jpg"')

doesnt work!

I import os and the code work into my cmd so there is no errors.

Anyone could help me??

Thanks a lot.
Reply
#10
I bet if you delimit your spaces, it will work.
Reply
#11
davilla Wrote:I bet if you delimit your spaces, it will work.
I tryed this without spaces:
Code:
os.system('"C:\prueba\ffmpeg.exe" -y -ss 30 -i "C:\prueba\movie.avi" -f mjpeg -vframes 1 -s 120x90 -an "C:\prueba\thumbnail.jpg"')

Into cmd works fine but doesnt work in python with os.system.

Any idea? I need make thumbnails, i trying a lot of methods Sad

Thanks.
Reply
#12
I solved the problem, I have to use \\ instead \.
But now, I have another problem:
When my plugin executes the order os.system() xbmc window minimizes!!
Anyone could help me?
Thanks in advance.
Reply
#13
Anyone know how to launch a subprocess in python ?
I want to launch ffmpeg without interfering with my plugin.

If I use:

Code:
sacarThumb = """"C:\\Program Files (x86)\\XBMC\\scripts\\Base De Datos\\ffmpeg.exe" -y -ss 423 -i "\\GERAR\\HD_RED_6\\Peliculas\\La Princesa Mononoke\\Movie.mkv" -f mjpeg -vframes 1 -s 720x400 -an "C:/Program Files (x86)/XBMC/scripts/Base De Datos/thumbnail.jpg""""

subprocess.Popen([sacarThumb], shell=False)

Debugger says me:
Code:
13:46:41 T:2904 M:2748325888   ERROR: Exception in python script's onAction
13:46:41 T:2904 M:2748325888  NOTICE: Traceback (most recent call last):
13:46:41 T:2904 M:2748325888  NOTICE:   File "C:\Program Files (x86)\XBMC\scripts\Base De Datos\default.py", line 8461, in onAction
13:46:42 T:2904 M:2748469248  NOTICE: if action == ACTION_PREVIOUS_MENU :
13:46:42 T:2904 M:2748469248  NOTICE:   File "C:\Program Files (x86)\XBMC\scripts\Base De Datos\default.py", line 8874, in onClick
13:46:44 T:2904 M:2748485632  NOTICE: self.Jugar()
13:46:44 T:2904 M:2748485632  NOTICE:   File "C:\Program Files (x86)\XBMC\scripts\Base De Datos\default.py", line 9746, in Jugar
13:46:46 T:2904 M:2748473344  NOTICE: self.pruebaFotograma(ronda)
13:46:46 T:2904 M:2748473344  NOTICE:   File "C:\Program Files (x86)\XBMC\scripts\Base De Datos\default.py", line 6530, in pruebaFotograma
13:46:47 T:2904 M:2748497920  NOTICE: subprocess.Popen([sacarThumb], shell=False)
13:46:47 T:2904 M:2748497920  NOTICE:   File "special:\\xbmc\system\python\python24.zlib\subprocess.py", line 558, in __init__
13:46:47 T:2904 M:2748493824  NOTICE:   File "special:\\xbmc\system\python\python24.zlib\subprocess.py", line 722, in _execute_child
13:46:47 T:2904 M:2748493824  NOTICE: WindowsError


If I use:

Code:
os.system(sacarThumb)

Works fine ! but minimizes my xbmc window Sad

If I use:
Code:
os.popen(sacarThumb)

Debugger says me:

Code:
14:47:04 T:1980 M:2464804864   ERROR: CThread::staticThread : Access violation at 0x77498c19: Writing location 0x00000014

Thanks.
Reply

Logout Mark Read Team Forum Stats Members Help
How I could use ExtractThumb ?0