views:

106

answers:

3

Im working in a Python plugin for XBMC (xbmc.org) and I want to execute a program (ffmpeg.exe) from my plugin without the cmd window appears. If I use os.system() to call ffmpeg.exe works fine but the xbmc minimizes because os.system open a cmd window a few seconds. So, I try to use os.spawnv() that I think its possible that allow me to call ffmpeg.exe without cmd window appears. The problem is I know how to use os.system but I dont know how to use os.spawnv. Im trying this, but doesnt work:

os.spawnv(os.P_DETACH,'"C:\Program Files (x86)\XBMC\scripts\Base De Datos\ffmpeg.exe" -y -ss 30 -i "C:\Program Files (x86)\XBMC\scripts\Base De Datos\Movie.avi" -f mjpeg -vframes 1 -s 720x400 -an  "C:\Program Files (x86)\XBMC\scripts\Base De Datos\thumbnail.jpg"')

"C:\Program Files (x86)\XBMC\scripts\Base De Datos\ffmpeg.exe" = The path of the ffmpeg.exe
-y -ss 30 -i = Arguments for ffmpeg.exe
"C:\Program Files (x86)\XBMC\scripts\Base De Datos\Movie.avi" = The path of the movie I want to use with ffmpeg.exe to make a thumbnail (argument for ffmpeg.exe)
-f mjpeg -vframes 1 -s 720x400 = More arguments for ffmpeg.exe
"C:\Program Files (x86)\XBMC\scripts\Base De Datos\thumbnail.jpg" = The path for save the thumbnail.

I trying a lot of methods to make a thumbnail but its seems to me there is really complicated in a xbmc plugin, I cannot use pyffmpeg because I cannot import the module from my plugin without installing it into de S.O. and my plugin must be portable, I could use PIL but only could make thumbnails of pictures and I need to make thumbnails of videos. I know some modules in python that allow me to call process without cmd window appears but depends of others modules like win32api that I cannot import for the same reasons I cannot use/import pyffmpeg... so I triying the "bad way" using this method, with os.system works but I loose control of my plugin window. If someone know other way to make a thumbnail of a video using python, please tell me. The other matter is my plugin must be multiplataform (Win and Linux at least) so this way is not good enought but it could be a big step for me.

Thanks a lot.

A: 

As per http://docs.python.org/library/os.html#os.spawnv, pass the arguments in a list:

os.spawnv(os.P_DETACH, "path\to\program.exe", ["arg1", "arg2", "arg3"])
Ray
Thanks, but I try:os.spawnv(os.P_DETACH, "C:\Program Files (x86)\XBMC\scripts\Base De Datos\ffmpeg.exe", ["-y", "-ss", "30", "-i", "C:\Program Files (x86)\XBMC\scripts\Base De Datos\Movie.avi", "-f", "mjpeg", "-vframes", "1", "-s", "720x400", "-an", "C:\Program Files (x86)\XBMC\scripts\Base De Datos\thumbnail.jpg"]) And doesnt work: ERROR: Exception in python script's onAction
GerarLM
What's onAction? Do you get an exception stack trace? Is it pointing to the line where you're using spawnv, or somewhere else? Does spawnv work from a standalone Python script?
Ray
onAction is because the line im using spawnv executes when I click in a buton of my plugin. The error is only in that line, anything else.
GerarLM
A: 

This way:

os.system(""C:\\Program Files (x86)\\XBMC\\scripts\\Base De Datos\\ffmpeg.exe" -y -ss 423 -i "C:\Program Files (x86)\XBMC\scripts\Base De Datos\Movie.avi" -f mjpeg -vframes 1 -s 720x320 -an "C:/Program Files (x86)/XBMC/scripts/Base De Datos/thumbnail.jpg"")

Works fine but minimizes xbmc because pop up a cmd window, so Im trying to do the same using os.spawnv but gives me an Error.

GerarLM
A: 

@llasram , Im GerarLM. My Python version I think is 2.4.5. If you know a way to call a program ( ffmpeg.exe in this case ) with arguments without the cmd window appears, please tell me.

GerarLM