Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python存储10秒的未编码视频缓冲区_Python_Picamera - Fatal编程技术网

使用Python存储10秒的未编码视频缓冲区

使用Python存储10秒的未编码视频缓冲区,python,picamera,Python,Picamera,我正在尝试使用Python脚本保存10秒的缓冲视频,特别是“.rgb”格式 为了做到这一点,我一直在使用连接到覆盆子圆周率的PiCamera 根据下面的脚本,如果我选择使用h264格式保存视频,我将能够成功完成预期目标,但如果将格式从h264更改为.rgb(目标格式),则不会生成任何输出 有什么想法吗?这里可能有什么问题 谢谢 代码捕捉: import time import io import os import picamera import datetime as dt from PIL

我正在尝试使用Python脚本保存10秒的缓冲视频,特别是“.rgb”格式

为了做到这一点,我一直在使用连接到覆盆子圆周率的PiCamera

根据下面的脚本,如果我选择使用h264格式保存视频,我将能够成功完成预期目标,但如果将格式从h264更改为.rgb(目标格式),则不会生成任何输出

有什么想法吗?这里可能有什么问题

谢谢

代码捕捉:

import time
import io
import os 
import picamera
import datetime as dt
from PIL import Image
import cv2 

#obtain current time
def return_currentTime():
    return dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

#trigger event declaration
def motion_detected():
    while True:
        print ("Trigger event(y)?")
        trigger = input ()
        if trigger =="y":
            time = return_currentTime()
            print ("Buffering...")
            camera.wait_recording(5)     
            stream.copy_to(str(time)+'.rgb')            
           
        else: 
           camera.stop_recording()
           
           break
        
#countdown timer 
def countdown (t):
    while t:
        mins, secs = divmod (t,60)
        timer = '{:02d}:{:02d}'.format(mins, secs)
        print(timer, end="\r")
        time.sleep(1)
        t-=1
    print('Buffer available!')
   

camera = picamera.PiCamera()

camera.resolution = (640, 480)

stream = picamera.PiCameraCircularIO(camera, seconds = 5)

#code will work using h264 as format
camera.start_recording (stream, format = 'rgb')
countdown(5)
motion_detected()

这个问题与您的流格式以及
stream.copy_to()
的工作方式有关

根据功能“复制到”(输出,大小=无,秒数=无,第一帧=2)的说明,第一帧是对要复制的第一帧的限制。默认情况下,这被设置为
sps_header
,这通常是H264流的第一帧

但是,由于您的流格式是RGB而不是H264,因此没有sps_头,因此
copy_to
找不到sps_头,因此不复制任何内容


要解决此问题,必须允许任何帧作为第一帧,而不仅仅是sps_头。这可以通过在通话中设置
first\u frame=None
来实现,例如
copy\u to(file,first\u frame=None)

请不要链接到代码。取而代之的是,在这里发布一个格式为代码的帖子(使用
{}
标记)。第一个问题解决了……但现在我可能正面临一个新的问题。应用更改后,我注意到生成的未编码文件(例如rgb、yuv)比生成的编码数据文件(例如h264)小。难道不是相反吗?我有什么遗漏吗?谢谢,伯特,真奇怪。您能否运行
file output.rgb
来确定输出的格式,或者在这里转储前几十个字节?让我们试着找出问题所在。嗨@id01,请查看下面请求的信息(第一个命令): pi@raspberrypi:~/Desktop$file 2020-09-02\11 \:13 \:31.rgb 2020-09-02 11:13:31.rgb:datasecond命令:pi@raspberrypi:~/Desktop$hexdump 2020-09-02\11 \:13 \:31.rgb 0000000 0000*08ca000@Bert看起来你的视频完全是黑色的,这很奇怪。脚本是否与h264一起工作?