列出本机音视频设备ffplay -list_devices true -f dshow -i dummy
播放指定视频设备以及分辨率ffplay -f dshow video="UVC Camera" -s 1920*1080
ffmpeg.exe -f dshow -list_options true -i video="UVC Camera"
ffmpeg -f dshow -vcodec mjpeg -s 1920*1080 -i video="UVC Camera" -vcodec copy ffmpeg-uvc.mjpeg
Python3代码获取数据
#eclipse, python2.7, opencv2.4.6
import sys
import cv2
#获得视频的格式
cnt = 0
for device in range(0, 10):
stream = cv2.VideoCapture(device)
grabbed = stream.grab()
stream.release()
if not grabbed:
break
else:
#print(stream, dir(stream))
cnt = cnt + 1
print("------------ video device cnt = %d ------------"%cnt)
#sys.exit(1)
#cv2.CAP_OPENCV_MJPEG
videoCapture = cv2.VideoCapture(0)
videoCapture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
frame_fps = videoCapture.get(cv2.CAP_PROP_FPS)
frame_width = int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT))
frame_codec = videoCapture.get(cv2.CAP_PROP_FOURCC)
frame_format = videoCapture.get(cv2.CAP_PROP_FORMAT)
frame_size = (frame_width, frame_height)
print("frame_fps:", frame_fps, "frame_size:", frame_size, "frame_format", frame_format)
print("frame_codec_float is ", frame_codec)
frame_codec_int = int(frame_codec)
print("frame_codec_int is 0x%x"%(frame_codec_int))
print("frame_codec_int is " + chr(frame_codec_int&0xFF) + chr((frame_codec_int>>8)&0xFF) + chr((frame_codec_int>>16)&0xFF) + chr((frame_codec_int>>24)&0xFF))
#print("videoCapture", videoCapture, dir(videoCapture))
#fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V') # mp4
#print("fourcc MP4V", cv2.VideoWriter_fourcc('M', 'P', '4', 'V'))
fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
print("fourcc MJPG", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
videoWriter = cv2.VideoWriter('opencv_uvc.mjpeg', fourcc, frame_fps, frame_size)
success, frame = videoCapture.read()
cnt=0
while success :
cv2.imshow("frame", frame)
cnt = cnt+1
cv2.waitKey(int(1000/int(frame_fps)))
videoWriter.write(frame)
success, frame = videoCapture.read()
videoWriter.release()
videoCapture.release()
cv2.destroyAllWindows()