Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

Python&OpenCV - 读写(read&write)视频(video) 详解 及 代码

$
0
0

读取(read&write)视频(video) 详解 及 代码


本文地址: http://blog.csdn.net/caroline_wendy/article/details/17084397


OpenCV读取视频, 获得视频的格式, 读取视频的每一帧, 播放控制; 使用VideoCapture()和read()函数

OpenCV写视频, 需要指定视频的格式, 可以从原视频中获取; 使用VideoWriter()和write()函数

注意: 使用OpenCV, cv2的方法, 和cv2.cv.XXX的参数;

代码如下:

# -*- coding: utf-8 -*-

#=================
#File: PyOpenCV.py
#Author: Wendy
#Date: 2013-12-03
#=================

#eclipse, python2.7, opencv 2.4.6

import cv2

#获得视频的格式
videoCapture = cv2.VideoCapture('oto.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)))

#指定写视频的格式, I420-avi, MJPG-mp4
videoWriter = cv2.VideoWriter('oto_other.mp4', cv2.cv.CV_FOURCC('M', 'J', 'P', 'G'), fps, size)

#读帧
success, frame = videoCapture.read()

while success :
    cv2.imshow("Oto Video", frame) #显示
    cv2.waitKey(1000/int(fps)) #延迟
    videoWriter.write(frame) #写视频帧
    success, frame = videoCapture.read() #获取下一帧
    


作者:u012515223 发表于2013-12-3 0:26:45 原文链接
阅读:165 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>