开发者

How do you set the frame size of cv.CreateVideoWriter

开发者 https://www.devze.com 2023-03-23 04:36 出处:网络
if I try: writer = cv.CreateVideoWriter(file, -1,(int(800),int(600)), is_color=1) -or- writer = cv.CreateVideoWriter(file, -1,(800,600), is_color=1)

if I try:

writer = cv.CreateVideoWriter(file, -1,(int(800),int(600)), is_color=1)

-or-

writer = cv.CreateVideoWriter(file, -1,(800,600), is_color=1)

-or-

writer = cv.CreateVideoWriter(file, -1,(800.0,600.0), is_color=1)

I get the error:

开发者_Python百科

TypeError: a float is required

with this I get progress:

writer = cv.CreateVideoWriter(file, -1, 25.0, (800,600), is_color=1)

error: Gstreamer Opencv backend doesn't support this codec acutally.

The input files are .png, the output is .avi


You need to pass a valid fourcc and fps:

fourcc = cv.CV_FOURCC('X','V','I','D')
fps = 25.0 # or 30.0 for a better quality stream
writer = cv.CreateVideoWriter(file, fourcc, 25.0, (800,600), is_color=1)

Alternatively, you can use named parameters in Python. It is less error-prone this way:

writer = cv.CreateVideoWriter(
    filename=file,
    fourcc=cv.CV_FOURCC('X','V','I','D'),
    fps=25.0,
    frame_size=(800,600),
    is_color=1)

A fourcc is an 32bit identifier of the codec of the video stream inside your target avi. Possible values for gstreamer according to cap_gstreamer.cpp are:

cv.CV_FOURCC('H','F','Y','U') # HuffYUV
cv.CV_FOURCC('D','R','A','C') # BBC Dirac
cv.CV_FOURCC('X','V','I','D') # MPEG-4 Part 2
cv.CV_FOURCC('X','2','6','4') # MPEG-4 Part 10 (aka. H.264 or AVC)
cv.CV_FOURCC('M','P','1','V') # MPEG-1 video

I believe all of the above can be put inside an avi container.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号