Skip to content

Commit 7dfab76

Browse files
author
chenxinfeng
committed
add IP camera reading
1 parent 3b0fe58 commit 7dfab76

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ cap = ffmpegcv.VideoCaptureCAM(0)
6565
cap = ffmpegcv.VideoCaptureCAM("Integrated Camera")
6666
```
6767

68+
## Cross platform
69+
6870
## GPU Accelation
6971
- Support **NVIDIA** card only, test in x86_64 only.
7072
- Works in **Windows**, **Linux** and **Anaconda**.

README_CN.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ffmpegcv提供了基于ffmpeg的视频读取器和视频编写器,比cv2更快
1414
- ffmpegcv可以使用**GPU加速**编码和解码。
1515
- ffmpegcv支持比open-cv更多的**视频编码器**
1616
- ffmpegcv原生支持**RGB**/BGR/灰度像素格式。
17+
- ffmpegcv支持网络**流视频读取** (网线监控相机)。
1718
- ffmpegcv支持ROI(感兴趣区域)操作,可以对ROI进行**裁剪****调整大小****填充**
1819
总之,ffmpegcv与opencv的API非常相似。但它具有更多的编码器,并且不需要安装opencv。
1920

@@ -24,6 +25,7 @@ ffmpegcv提供了基于ffmpeg的视频读取器和视频编写器,比cv2更快
2425
- `VideoCaptureQSV`: 使用Intel集成显卡读取视频文件.
2526
- `VideoCaptureCAM`:读取摄像头。
2627
- `VideoCaptureStream`:读取RTP/RTSP/RTMP/HTTP流。
28+
- `VideoCaptureStreamRT`: 读取RTSP流 (网线监控相机),实时、低延迟。
2729
- `noblock`:在后台读取视频文件(更快),使用多进程。
2830

2931
## 安装
@@ -293,7 +295,7 @@ cap = ffmpegcv.VideoCaptureCAM('FaceTime HD Camera', camsize_wh=(1280,720), camf
293295

294296
2. 在Linux上VideoCaptureCAM无法列出FPS,因为`ffmpeg`无法使用Linux本机的`v4l2`模块查询设备的FPS。不过,让FPS为空也没问题。
295297

296-
## 流读取器 (直播流,IP摄像头
298+
## 流读取器 (直播流,网络监控摄像头
297299
**实验性功能**。ffmpegcv提供了流读取器,与VideoFile读取器一致,更类似于相机。
298300

299301
- 支持`RTSP``RTP``RTMP``HTTP``HTTPS`流。
@@ -325,6 +327,18 @@ while True:
325327
if not ret:
326328
break
327329
pass
330+
331+
# ffmpegcv, 网络监控摄像头
332+
# 例如 海康威视, `101` 主视频流, `102` 子视频流
333+
stream_url = 'rtsp://admin:PASSWD@192.168.1.xxx:8554/Streaming/Channels/102'
334+
cap = ffmpegcv.VideoCaptureStreamRT(stream_url) # 低延迟 & 缓存
335+
cap = ffmpegcv.ReadLiveLast(ffmpegcv.VideoCaptureStreamRT, stream_url) #不缓存
336+
while True:
337+
ret, frame = cap.read()
338+
time.sleep(1/30)
339+
if not ret:
340+
break
341+
pass
328342
```
329343

330344
## FFmpegReaderNoblock

ffmpegcv/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .ffmpeg_writer_stream_realtime import FFmpegWriterStreamRT
77
from .ffmpeg_reader_qsv import FFmpegReaderQSV
88
from .ffmpeg_writer_qsv import FFmpegWriterQSV
9-
from .ffmpeg_noblock import noblock
9+
from .ffmpeg_noblock import noblock, ReadLiveLast
1010
from .video_info import get_num_NVIDIA_GPUs
1111
import shutil
1212
from subprocess import DEVNULL, check_output

ffmpegcv/ffmpeg_reader_camera.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,15 @@ def __init__(self, vid, q):
205205
self.q = q
206206

207207
def run(self):
208+
q = self.q
208209
while True:
209210
if not self.vid.isOpened():
210211
break
211212
ret, img = self.vid.read_()
212213

213-
try:
214-
self.q.put_nowait((ret, img)) # drop frames
215-
except Exception:
216-
pass
217-
continue
214+
if q.full():
215+
q.get() # drop frames
216+
q.put((ret, img))
218217

219218

220219
class FFmpegReaderCAM:

ffmpegcv/ffmpeg_reader_noblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self,
2828
self.shared_array = shared_array
2929
self.vcap_args = vcap_args
3030
self.vcap_kwargs = vcap_kwargs
31-
self.q = Queue(maxsize=(NFRAME-1)*2)
31+
self.q = Queue(maxsize=(NFRAME-2)*2)
3232
self.vcap_fun = vcap_fun
3333
self.has_init = False
3434
self.process = None

ffmpegcv/ffmpeg_reader_stream_realtime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ def VideoReader(
3434
resize_keepratio, resize_keepratioalign)
3535
vid.size = (vid.width, vid.height)
3636

37+
rtsp_opt = '-rtsp_transport tcp ' if stream_url.startswith('rtsp://') else ''
3738
vid.ffmpeg_cmd = (
3839
f"ffmpeg -loglevel warning "
39-
'-rtsp_transport tcp '
40+
f' {rtsp_opt} '
4041
'-fflags nobuffer -flags low_delay -strict experimental '
4142
f' -vcodec {vid.codec} -i {stream_url}'
4243
f" {filteropt} -pix_fmt {pix_fmt} -f rawvideo pipe:"

ffmpegcv/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__='0.3.8'
1+
__version__='0.3.9'

0 commit comments

Comments
 (0)