下面是使用的OpenCV的Python绑定阅读掀起了网络摄像头,一个非常简单的例子:管原始OpenCV的图像FFmpeg的
'''capture.py'''
import cv, sys
cap = cv.CaptureFromCAM(0) # 0 is for /dev/video0
while True :
if not cv.GrabFrame(cap) : break
frame = cv.RetrieveFrame(cap)
sys.stdout.write(frame.tostring())
现在我想管道输出到FFmpeg的,如:
$ python capture.py | ffmpeg -f image2pipe -pix_fmt bgr8 -i - -s 640x480 foo.avi
可悲的是,我不能让ffmpeg的魔法咒语相当正确的,它失败
libavutil 50.15. 1/50.15. 1 libavcodec 52.72. 2/52.72. 2 libavformat 52.64. 2/52.64. 2 libavdevice 52. 2. 0/52. 2. 0 libavfilter 1.19. 0/1.19. 0 libswscale 0.11. 0/0.11. 0 libpostproc 51. 2. 0/51. 2. 0 Output #0, avi, to 'out.avi': Stream #0.0: Video: flv, yuv420p, 640x480, q=2-31, 19660 kb/s, 90k tbn, 30 tbc [image2pipe @ 0x1508640]max_analyze_duration reached [image2pipe @ 0x1508640]Estimating duration from bitrate, this may be inaccurate Input #0, image2pipe, from 'pipe:': Duration: N/A, bitrate: N/A Stream #0.0: Video: 0x0000, bgr8, 25 fps, 25 tbr, 25 tbn, 25 tbc swScaler: 0x0 -> 640x480 is invalid scaling dimension
- 捕获的帧肯定是640x480。
- 我很确定OpenCV图像类型(IplImage)的像素顺序是GBR,每个通道一个字节。至少,这似乎是从相机中脱颖而出。
我不是ffmpeg大师。有没有人成功做到这一点?
哦,男人! 输出到ffmpeg的想法非常聪明! – Mehran 2013-10-13 23:13:15