Raspberry Pi相机写权限

时间:2015-04-19 10:07:35

标签: python linux raspberry-pi

当写一个python脚本在Pi上每分钟拍一张照片时,它会吐出这个错误:

“mmal:main:打开输出文件时出错:”

Python代码:

jpeg_list = open('jpeg_still_list.txt','w')
count = 0
tlcount = 0
while True:
    os.system("raspistill -w 1920 -h 1080 -q 80 -o frames/%s.jpg" % count)
    jpeg_list.write("frames%s.jpg" % count)
    time.sleep(60)
    count = count+1

    if count == 180:
        count = 0

        os.system("mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o %s -mf type=jpeg:fps=24 mf://@jpeg_still_list.txt" %"lol")

我已经广泛搜索了这个问题,我遇到了其他堆栈溢出的答案,这可能是我需要做的。

https://raspberrypi.stackexchange.com/questions/24460/how-to-write-raspistill-image-to-usb-drive

但我认为他们正在改变的文件已经改变了格式,因为它不太清楚如何做到这一点。

我尝试使用sudo和超级用户运行它。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

使用子流程模块,特别是check_call

with open('jpeg_still_list.txt', 'w') as jpeg_list:
    from subprocess import check_call  
    count = 0
    tlcount = 0
    while True:
        check_call(["raspistill", "-w", "1920", "-h",
                    "1080", "-q", "80", "-o", "frames{}.jpg".format(count)])
        jpeg_list.write("frames{}.jpg".format(count))
        time.sleep(60)
        count += 1
        if count == 180:
            count = 0
        check_call(["mencoder", "-nosound", "-ovc", "lavc", "-lavcopts",
                    "vcodec=mpeg4:aspect=16/9:vbitrate=8000000", "-vf",
                    "scale=1920:1080", "-o", "lol", "-mf",
                    "type=jpeg:fps=24", "mf://@jpeg_still_list.txt"])

frames/表示您要打开不存在的frames目录中的.jpg文件,以免出错,删除/