【问题标题】:cant play the video saved from python 2.7无法播放从 python 2.7 保存的视频
【发布时间】:2016-11-13 23:13:08
【问题描述】:

我尝试了很多编解码器,除了最后一个之外,所有编解码器都产生 0 字节的视频,最后一个编解码器确实产生了一个视频文件,其中有一些但随后无法播放。这个问题让我发疯,我使用的代码已经过其他用户的测试。 我已将 opencv_ffmpeg310_64.dll 文件复制到 c:\python2.7 文件夹中。 我在 windows 10 和 opencv 3.1.0 我尝试了所有类型的 CODEC 都没有工作。

import numpy as np
import cv2

    cap = cv2.VideoCapture(0)

    # Define the codec and create VideoWriter object
# Define the codec and create VideoWriter object
#fourcc = cv2.VideoWriter_fourcc(*'FFV1')
#fourcc = cv2.VideoWriter_fourcc(*'XVID')
#fourcc = cv2.VideoWriter_fourcc(*'DIVX')
#fourcc = cv2.VideoWriter_fourcc(*'DIV3')
#fourcc = cv2.VideoWriter_fourcc('F','M','P','4')
#fourcc = cv2.VideoWriter_fourcc('D','I','V','X')
#fourcc = cv2.VideoWriter_fourcc('D','I','V','3')
#fourcc = cv2.VideoWriter_fourcc('F','F','V','1')


fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
    out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

    while(cap.isOpened()):
        ret, frame = cap.read()
        if ret==True:
            frame = cv2.flip(frame,0)

            # write the flipped frame
            out.write(frame)

            cv2.imshow('frame',frame)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        else:
            break

    # Release everything if job is finished
    cap.release()
    out.release()
    cv2.destroyAllWindows()

【问题讨论】:

    标签: python-2.7 opencv3.1


    【解决方案1】:

    我找到了答案,我所做的是通过输入“-1”而不是“fourcc”来获取可能的 CODEC 值,然后在fourcc 编解码器网站https://www.fourcc.org/codecs.php 上查找该编解码器的 4 位代码。 就我而言,它是 Cinemax 编解码器 CDIV

    SO first step:  find the code and enter by hand manually and see if the video is made and is playable   
    
    #use -1 below for entering the codec by hand
    #out = cv2.VideoWriter('output.avi',-1, 20.0, (640,480))
    
    second step: from the above step find out which codec worked for you and then look up the four digit code on the fourcc site and plug it in 
    
    fourcc = cv2.VideoWriter_fourcc(*'CVID')
    out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多