Why are you not checking errors? If CreateVideoWriter()
is failing, you will never know.
I think that CreateVideoWriter is returning NULL. Add the appropriate code to check the return and verify if this is true.
If it is, the problem is most probably CV_FOURCC()
which is not finding the codec.
Then, check this answer for other codecs: Creating AVI files in OpenCV
I also recommend you to update OpenCV to the most recent available (I think its v2.2).
EDIT:
You were also missing the last parameter in CreateVideoWriter:
#!/usr/bin/env python
import sys
from opencv.cv import *
from opencv.highgui import *
im1 = cvLoadImage("img1.jpg")
if not im1:
print "Could not load im1"
im2 = cvLoadImage("img2.jpg")
if not im2:
print "Could not load im2"
fps = 4.0
frame_size = cvGetSize(im1)
#writer = cvCreateVideoWriter("out.avi", CV_FOURCC('M', 'J', 'P', 'G'), fps, frame_size, True)
writer = cvCreateVideoWriter("out.avi", CV_FOURCC('F', 'L', 'V', '1'), fps, frame_size, True)
if not writer:
print "Error in creating video writer"
sys.exit(1)
else:
print cvWriteFrame(writer, im1)
print cvWriteFrame(writer, im2)
cvReleaseVideoWriter(writer)
I think there's an issue with OpenCV/Linux/Python regarding cvCreateVideoWriter(). I'll try to talk with the devs and will update here when I get a reply.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…