擅长:python、mysql、java
<p>关于这个话题有很多过时的和不正确的在线指南——我想我几乎每一个都试过了。在查看了Mac OSX上基于源QTKit的VideoWriter实现之后,我终于能够使用以下代码让VideoWriter输出有效的视频文件:</p>
<pre><code>fps = 15
capSize = (1028,720) # this is the size of my source video
fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') # note the lower case
self.vout = cv2.VideoWriter()
success = self.vout.open('output.mov',fourcc,fps,capSize,True)
</code></pre>
<p>要编写图像帧(请注意,imgFrame的大小必须与上面的capSize相同,否则更新将失败):</p>
<pre><code>self.vout.write(imgFrame)
</code></pre>
<p>完成后,请确保:</p>
<pre><code>vout.release()
self.vout = None
</code></pre>
<p>这在macosx10.8.5(山狮)上对我有效:对其他平台没有保证。我希望这个片段能帮别人省下几个小时的实验时间!</p>