VideoWriter and PyOpenCv ?

94 views
Skip to first unread message

Rekveld

unread,
Jul 21, 2010, 9:28:54 PM7/21/10
to ctypes-opencv
Hi all,

I'm very impressed with the ease of use of pyopencv so far and I've
been very happy to play around exploring the demo files. For a project
I need to write results to a videofile, however, and I'm not sure how
to get this to work in pyopencv.

I have two questions:

- how should I open a videowriter ? I figured out a way around errors
about C++-format and the interpreter doesn't complain anymore, but I
don't manage to actually open a writer. What am I missing ?

I have this code:
fourcc = cv.CV_FOURCC('D','I','B',' ')
fps = 25.
size = cv.Size(500,500)
writer = cv.VideoWriter(filename,fourcc,fps,size) # the
constructor calls 'open', I also tried calling 'open' myself
print "filename: ", filename
print "fourcc ", fourcc
print "fps: ", fps
print "did writer open ?:", writer.isOpened()
print "writer ", writer

and these are the messages printed in the console:

filename: /media/docs/data/cvwrite01.mov
fourcc 541215044
fps: 25.0
did writer open ?: False
writer <pyopencv.pyopencvext.VideoWriter object at 0x31b6c58>

- how should add a frame to my video ?
If I look here <http://opencv.willowgarage.com/documentation/cpp/
reading_and_writing_images_and_video.html#videowriter> it seems it
should be something like
mywriter<<myimage ?? Is that all ??

is there somebody willing to share a working python code snippet ?

with kind regards,

Joost.

Minh-Tri Pham

unread,
Jul 22, 2010, 2:37:08 AM7/22/10
to ctypes...@googlegroups.com
Hi Joost,

The syntax is correct. I think the problem might be in OpenCV's code. Please
check if the specified codec is installed *and* OpenCV can use it. The best
way to check if this is a case is by writing equivalent C++ code.

>
> - how should add a frame to my video ?
> If I look here <http://opencv.willowgarage.com/documentation/cpp/
> reading_and_writing_images_and_video.html#videowriter> it seems it
> should be something like
> mywriter<<myimage ?? Is that all ??

Yes, that's all. :)

Minh-Tri

>
> is there somebody willing to share a working python code snippet ?
>
> with kind regards,
>
> Joost.
>

--
Dr. Minh-Tri Pham
Research Fellow, University of Surrey, UK
Email: t.p...@surrey.ac.uk or pmt...@gmail.com
Mob: +44 (0) 778 774 1089 | Tel: +44 (0) 148 368 4711

Rekveld

unread,
Jul 22, 2010, 8:12:50 PM7/22/10
to ctypes-opencv
Hi Minh-Tri,

thanks for the reply, it's good to know that the problem is not in my
syntax.
It is probably related to this:
http://opencv.willowgarage.com/wiki/FFMPEG
and I probably need to do this
http://ubuntuforums.org/showthread.php?t=786095
in order to solve it.
So if I have to rebuild FFMPEG and if I have to rebuild OpenCV on top
of that, does that mean i'll have to build pyopencv again too ?

kind regards,

Joost.
> Email: t.p...@surrey.ac.uk or pmtr...@gmail.com

Rekveld

unread,
Aug 22, 2010, 7:41:08 PM8/22/10
to ctypes-opencv
it turns out that OpenCv has a list of supported codecs and that
ofcourse you need to have codecs installed on your system in order to
use them.
My experience so far is that OpenCV (silently) does not open the
writer if the codec is not in the list of supported codecs. It opens
the writer but throws an error if it is on the list but if the codec
is not installed.
see <http://mathnathan.com/2010/07/18/error1/>

ciao,

Joost.

On Jul 23, 2:12 am, Rekveld <li...@lumen.nu> wrote:
> Hi Minh-Tri,
>
> thanks for the reply, it's good to know that the problem is not in my
> syntax.
> It is probably related to this:http://opencv.willowgarage.com/wiki/FFMPEG
> and I probably need to do thishttp://ubuntuforums.org/showthread.php?t=786095
Reply all
Reply to author
Forward
0 new messages