OpenCV Video Writing _python

Source: Internet
Author: User

问题:为何视频能读出来,而写入代码也没报错,但文件大小为0k,视频好似没有写入成功!

原因:cv2.VideoWriter()a second parameter controls Video Encoding format, which is written in most tutorials

Videowriter = Cv2. Videowriter (' Out.mp4 ', Cv2.cv.CV_FOURCC (' M ', ' J ', ' P ', ' G '), FPS, size)

Or

Videowriter = Cv2. Videowriter (' Out.avi ', Cv2.cv.CV_FOURCC (' I ', ' 4 ', ' 2 ', ' 0 '), fps, size)

The actual runtime generated video size of 0k, the reason is that the operating environment does not correspond to the video encoder, so the video can not be generated, or the second parameter setting is not appropriate, the system is not appropriate.


Solutions

cv2.VideoWriter()The second parameter is set to -1, and the program runs interactively with a dialog box that lets you select one from the system's existing encoding.


Import cv2videocapture = Cv2. Videocapture (' Clocka.avi ') fps = Videocapture.get (cv2.cv.CV_CAP_PROP_FPS) size = (int (videocapture.get (Cv2.cv.CV_CAP _prop_frame_width)), int (Videocapture.get (Cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))) v = cv2. Videowriter (' Bb.avi ',-1, FPS, size) print fps, size, ' v-> ', vsuccess, frame = Videocapture.read () while success: Cv2.imshow (' Mywindow ', frame) Cv2.waitkey (1000/int (fps)) V.write (frame) success, frame = Videocapture.read ()



The results are as follows



File information


OpenCV Video Writing _python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.