Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
在OpenCV python中打开具有未知扩展名(Mjpeg?)的文件_Python_Opencv_Ffmpeg - Fatal编程技术网

在OpenCV python中打开具有未知扩展名(Mjpeg?)的文件

在OpenCV python中打开具有未知扩展名(Mjpeg?)的文件,python,opencv,ffmpeg,Python,Opencv,Ffmpeg,我正在尝试用python将第三方视频文件打开到OpenCV中。 我的相机(plotwatcher camera trap)以愚蠢的专有格式拍摄。扩展名是唯一的(.tlv),但我可以在VLC中播放该文件,并且使用ffmpeg可以看到以下编码: C:\Users\Ben>ffmpeg -i C:/Users/Ben/Documents/OpenCV_HummingbirdsMotion/PlotwatcherTest.tlv ffmpeg version N-58037-g355cea8 C

我正在尝试用python将第三方视频文件打开到OpenCV中。 我的相机(plotwatcher camera trap)以愚蠢的专有格式拍摄。扩展名是唯一的(.tlv),但我可以在VLC中播放该文件,并且使用ffmpeg可以看到以下编码:

C:\Users\Ben>ffmpeg -i C:/Users/Ben/Documents/OpenCV_HummingbirdsMotion/PlotwatcherTest.tlv

ffmpeg version N-58037-g355cea8 Copyright (c) 2000-2013 the FFmpeg developers
built on Nov 11 2013 18:01:42 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil      52. 52.100 / 52. 52.100
libavcodec     55. 41.100 / 55. 41.100
libavformat    55. 21.100 / 55. 21.100
libavdevice    55.  5.100 / 55.  5.100
libavfilter     3. 90.102 /  3. 90.102
libswscale      2.  5.101 /  2.  5.101
libswresample   0. 17.104 /  0. 17.104
libpostproc    52.  3.100 / 52.  3.100
Input #0, avi, from 'C:/Users/Ben/Documents/OpenCV_HummingbirdsMotion/Plotwatche
rTest.tlv':
Duration: 00:00:05.00, start: 0.000000, bitrate: 14608 kb/s
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc), 1280x720, 10 tb
r, 10 tbn, 10 tbc
从这里我可以看到文件被编码成mjpeg格式

如何在open cv中打开此文件

import cv2
#import cv2.cv as cv
import numpy as np
cap = cv2.VideoCapture("C:/Users/Ben/Documents/OpenCV_HummingbirdsMotion/PlotwatcherTest.mjpg")
ret, frame = cap.read()
#show first image
cv2.imshow('my window',frame)
cv2.waitKey(0)
cv2.destroyWindow('my window')
我看不出有什么东西上膛了。当我尝试查看第一帧时,出现错误:

File "C:\Users\Ben\Documents\OpenCV_HummingbirdsMotion\Test.py", line 21, in <module>
cv2.imshow('my window',frame)
error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215)
size.width>0        && size.height>0
文件“C:\Users\Ben\Documents\OpenCV\u HummingbirdsMotion\Test.py”,第21行,在
cv2.imshow(“我的窗口”,框架)
错误:..\..\..\opencv\modules\highgui\src\window.cpp:261:错误:(-215)
size.width>0&&size.height>0
我试着按照这里找到的概念性想法离开原生的.tlv、mjpeg和mjpg以及.mjpg结尾:


我感谢所有的帮助

我无法手动使其工作。我卸载了所有东西,然后安装了内置open_cv的anaconda,然后通过环境设置连接ffmpeg路径,它成功了

我还应该补充的是,我已经将所有内容添加到windows路径:C:\OpenCV\3rdparty\ffmpeg\到windows路径环境变量中,如下所示:您拥有的是嵌入在AVI容器文件中的MJPEG流,而不是原始MJPEG流,因此请尝试将其作为AVI提供给OpenCV。别忘了在Windows中安装正确的MJPEG编解码器。