Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.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中PIL无法识别mjpeg流中保存的jpeg文件_Python_Image_Jpeg_Python Imaging Library_Mjpeg - Fatal编程技术网

python中PIL无法识别mjpeg流中保存的jpeg文件

python中PIL无法识别mjpeg流中保存的jpeg文件,python,image,jpeg,python-imaging-library,mjpeg,Python,Image,Jpeg,Python Imaging Library,Mjpeg,我试图从网络摄像头的MJPEG流中抓取一个有效的JPEG帧。我成功地将其写入磁盘,并可以在Infranview之类的程序中打开它,但Python和其他图形程序不将其视为有效的JPEG文件。我编写了一个函数,可以对其进行snarf并将其写入磁盘 def pull_frame(image_url,filename): flag = 0 # open the url of the webcam stream try: f = urllib.urlopen

我试图从网络摄像头的MJPEG流中抓取一个有效的JPEG帧。我成功地将其写入磁盘,并可以在Infranview之类的程序中打开它,但Python和其他图形程序不将其视为有效的JPEG文件。我编写了一个函数,可以对其进行snarf并将其写入磁盘

def pull_frame(image_url,filename):
    flag = 0
    # open the url of the webcam stream
    try:
            f = urllib.urlopen(image_url)
    except IOError:
            print "uh oh"
    else:
            # kill first two lines
            try:
                    null = f.readline()
            except:
                    print "duh"
            null = f.readline()
            pop = f.readline()
            # this pulls the length of the content
            count = pop[16:] # length of content.
            print "Size Of Image:" + count
            # read just the amount of the length of content
            if int(count):
                    s = f.read(int(count))
                    flag = 1
                    # write it to a file name
                    p = file(filename,'wb')
                    p.write(s)
                    p.close()
因此,我得到了破损的JPEG,我甚至尝试了一种简单的解决方法,尝试使用FFMPEG从破损的JPEG生成有效的PNG,它从comamnd行工作,但不从子流程工作。python中有没有一种方法可以使用正确的jpeg头从mjpeg steam中提取此jpeg

这里有一个指向camera1.jpg的链接,该链接是该例程中保存的数据的一个示例,该例程无法识别,也没有缩略图(尽管infraview可以将其作为jpg打开)

你能把这样一个坏掉的JPEG(或它的链接)包括在内吗?我在2shared.com上添加了一个链接-上传了一个坏掉的jpg版本,我从上面编辑的链接的网络摄像头上获得了这个版本!正如人们所知,我做了一项非常糟糕的工作,我使用FFMPEG将没有标题的糟糕jpg转换成一个有巨大文件大小的png:)笨重的乱七八糟,但目前正在工作!那个文件还有吗?我不能下载它,把它放在别的地方。