views:

57

answers:

2

Hi, I have a problem when I generate an animated gif from a movie.avi using ffmpeg from python in Win7. If I open a cmd window and execute this line:

"C:\ffmpeg\ffmpeg.exe" -i "C:\ffmpeg\video.avi" -pix_fmt rgb24 -r 10.0 -loop_output 0 -ss 5 -t 10 -s 352x288 -f gif "C:\ffmpeg\video.gif"

ffmpeg.exe generates a gif perfectly from the video. I want to use ffmpeg.exe from my code in python for do the same but, when I execute this code from my python program:

argList = ["-i", "C:\\ffmpeg\\video.avi", "-pix_fmt", "rgb24", "-r", "10.0", "-loop_output", "0", "-ss", "5", "-t", "10", "-s", "352x288", "-f", "gif", "C:\\ffmpeg\\video.gif"]  
os.spawnv(os.P_DETACH, "C:\\ffmpeg\\ffmpeg.exe", argList)

Something really rare happends: My video.avi lose all its size, now is a blank file with 0 bytes and the movie.gif is a blank file with 0 bytes too so, the same code in cmd windows works fine and into my python program modifiques my movie.avi file and erase all its content (but the file movie.avi doesn't dessapear, the file still exists but now is a blank file) and generates a blank movie.gif file. Someone know why this happens? Thanks in advance.

+1  A: 

Your arglist for spawnv needs to start with "C:\\ffmpeg\\ffmpeg.exe". Try that and see how it goes.

argList = ["C:\\ffmpeg\\ffmpeg.exe", "-i", "C:\\ffmpeg\\video.avi", "-pix_fmt", "rgb24", "-r", "10.0", "-loop_output", "0", "-ss", "5", "-t", "10", "-s", "352x288", "-f", "gif", "C:\\ffmpeg\\video.gif"]  
os.spawnv(os.P_DETACH, "C:\\ffmpeg\\ffmpeg.exe", argList)
JoshD
Thanks a lot! Problem was there, now works fine. But I tryed argList without "C:\\ffmpeg\\ffmpeg.exe" because works fine generating a simple thumbnail.
GerarLM
+1. Also consider using `subprocess` instead, which doesn't require this duplication.
bobince
What would be the correct syntaxis using subprocess? I tryed to use subprocess but It was impossible for me!
GerarLM
A: 

@JoshD

argList = ["-y", "-ss", "750", "-i", "C:\\ffmpeg\\video.avi", "-f", "mjpeg", "-vframes", "1", "-s", "1280x720", "-an", "C:\\ffmpeg\\thumbnail.jpg"]
os.spawnv(os.P_DETACH, "C:\\ffmpeg\\ffmpeg.exe", argList)

This works fine without "C:\\ffmpeg\\ffmpeg.exe" in the start of spawnv, my confusion came from this. Thanks a lot.

GerarLM
Yes, sometimes it will work, but that's more luck that proof of valid behavior. :)
JoshD