gpt4 book ai didi

python - 无法在Raspberry Pi4上播放使用OpenCV 4.4.0录制的视频

转载 作者:行者123 更新时间:2023-12-02 17:58:20 24 4
gpt4 key购买 nike

我在Raspberry Pi Model 4B上安装了OpenCV 4.4。我可以直接从相机播放视频。当我录制视频并想要播放文件时,则无法播放视频。我正在使用VLC播放器。这是我用来录制视频的代码

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
if (cap.isOpened()==False) :
print("error in opening video stream")
exit()

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('video.mp4',fourcc,20.0,(160,120),True)
while(cap.isOpened()):
ret,frame = cap.read()
if ret == True:
frame = cv2.flip(frame,0)
out.write(frame)
cv2.imshow('frame',frame)
# Press 'q' to quit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
在运行上述脚本时,我得到以下警告
[ WARN:0] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
当我尝试使用ffmpeg转换录制的视频时,出现错误。
我用于转换的代码
ffmpeg -i video.mp4 -vcodec libx264 demo.mp4
错误详情
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.20.100
Duration: 00:00:00.00, bitrate: N/A
Output #0, mp4, to 'demo.mp4':
Output file #0 does not contain any stream
似乎文件已创建,但缺少视频编解码器。寻求帮助。
谢谢

最佳答案

谢谢大家 !
我能够解决。就默认VideoCapture分辨率而言,我提供给VideoWriter的帧和高度似乎存在问题。下面是修改后的脚本

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

if (cap.isOpened()==False) :
print("error in opening video stream")
exit()

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

while(cap.isOpened()):
ret,frame = cap.read()
if ret == True:
frame = cv2.flip(frame,0)
out.write(frame)
cv2.imshow('frame',frame)
# Press 'q' to quit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()

关于python - 无法在Raspberry Pi4上播放使用OpenCV 4.4.0录制的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64171508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com