标签:class print h264 div opened logs etc 正数 win
一、H264文件获取
下载一段MP4文件,通过FFMPEG转换成MP4
ffmpeg -i Gravity.mp4 -vcodec h264 out_2.264
二、通过解析H264成帧,然后刷新
这里的环境是 MacOS + Python2.7 + openCV2
#!/usr/local/bin/python2.7 # -*- coding: utf-8 -*- __author__ = ‘qqvipfunction‘ import sys import cv2 import os import datetime #打印时间戳 def Log(str): print(datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S.%f‘) + ": " + str) #cv2.waitKey ,填写0表示永久等待,正数表示等待多少毫秒,如果按键返回按键的值 if __name__ == ‘__main__‘: h264_path = os.getcwd() + ‘/rsc/gravity/out.h264‘ Log(h264_path) loop = True frameCount = 0 cap = cv2.VideoCapture(h264_path) while (cap.isOpened() and loop): Log("frame " + str(frameCount)) frameCount = frameCount + 1 ret, frame = cap.read() if ret: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA) cv2.imshow(‘frame‘, gray) if cv2.waitKey(1) & 0xFF == ord(‘q‘): loop = False break else: print("Parse H264 failed " + ret) cap.release() cv2.destroyAllWindows()
三、效果
标签:class print h264 div opened logs etc 正数 win
原文地址:http://www.cnblogs.com/doudouyoutang/p/7577027.html