我想定期拍摄RTMP直播视频流的快照.我可以使用VLC看到rtmp视频流.这是rtmp网址:
rtmp://antena3fms35livefs.fplive.net/antena3fms35live-live/stream-antena3_1
Run Code Online (Sandbox Code Playgroud)
我使用下面的命令来捕获快照,根据官方的FFmpeg网站在这里:
ffmpeg -i rtmp://antena3fms35livefs.fplive.net/antena3fms35live-live/stream-antena3_1 -f image2 -vf fps=fps=1 out%d.png
Run Code Online (Sandbox Code Playgroud)
该命令产生以下输出:
ffmpeg version N-64667-gd595361 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 14 2014 22:09:48 with gcc 4.8.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzl
libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amr
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --ena
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 47.100 / 55. 47.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 10.100 / 4. 10.100 …Run Code Online (Sandbox Code Playgroud) 我的目标是每秒从rtmp流中捕获一个帧,并使用OpenCV处理它.我正在使用带有Java接口的FFmpeg版本N-71899-g6ef3426和OpenCV 2.4.9(但我首先尝试使用Python).目前,我只能采用简单而肮脏的解决方案,即使用FFmpeg捕获图像,将它们存储在磁盘中,然后从我的OpenCV程序中读取这些图像.这是我正在使用的FFmpeg命令:
ffmpeg -i "rtmp://antena3fms35livefs.fplive.net:1935/antena3fms35live-live/stream-lasexta_1 live=1" -r 1 capImage%03d.jpg
Run Code Online (Sandbox Code Playgroud)
这对我来说是有用的,至少对于这个具体的rtmp来源.然后我需要以适当的方式从我的OpenCV程序中读取这些图像.我实际上没有实现这部分,因为我正在努力寻找更好的解决方案.
我认为理想的方法是直接从OpenCV捕获rtmp帧,但我找不到这样做的方法.这是我正在使用的Python代码:
cv2.namedWindow("camCapture", cv2.CV_WINDOW_AUTOSIZE)
cap = cv2.VideoCapture()
cap.open('"rtmp://antena3fms35livefs.fplive.net:1935/antena3fms35live-live/stream-lasexta_1 live=1"')
if not cap.open:
print "Not open"
while (True):
err,img = cap.read()
if img and img.shape != (0,0):
cv2.imwrite("img1", img)
cv2.imshow("camCapture", img)
if err:
print err
break
cv2.waitKey(30)
Run Code Online (Sandbox Code Playgroud)
而不是read()函数,我也尝试使用grab()和retrieve()函数而没有任何好的结果.read()函数每次都在执行,但没有收到"img"或"err".还有其他办法吗?或者也许没有办法从这样的流中直接从OpenCV 2.4.9获取帧?
我读过OpenCV使用FFmpeg来完成这类任务,但正如你所看到的,在我的情况下,FFmpeg能够从流中获取帧而OpenCV则不能.
在我无法找到直接从OpenCV获取帧的方法的情况下,我的下一个想法是以某种方式管道,FFmpeg输出到OpenCV,这似乎更难实现.
不知道,谢谢!
更新1: 我在Windows 8.1中.因为我从Eclipse PyDev运行python脚本,所以这次我从cmd运行它,我收到以下警告:
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)
Run Code Online (Sandbox Code Playgroud)
就我所知,这个警告意味着文件路径错误,或者编解码器不受支持.现在,问题是一样的.OpenCV无法从此来源获取帧吗?
我正在使用JPA和Hibernate进行持久化,并使用Spring Boot提供的一些自动配置帮助.我正在运行一个JUnit测试,它在JPA存储库中保存了一些记录.然后它实例化一个新的Spring托管线程,它由ThreadPoolTaskExecutor运行.该线程将尝试获取之前添加的记录但没有成功.
以下是测试和可运行线程的相关代码:
public class RtmpSpyingTests extends AbstractTransactionalJUnit4SpringContextTests {
@Autowired
ThreadPoolTaskExecutor rtmpSpyingTaskExecutor;
@Autowired
ApplicationContext ctx;
@Autowired
RtmpSourceRepository rtmpRep;
@Test
public void test() {
RtmpSource rtmpSourceSample = new RtmpSource("test");
rtmpRep.save(rtmpSourceSample);
rtmpRep.flush();
List<RtmpSource> rtmpSourceList = rtmpRep.findAll(); // Here I get a list containing rtmpSourceSample
RtmpSpyingTask rtmpSpyingTask = ctx.getBean(RtmpSpyingTask.class,
"arg1","arg2");
rtmpSpyingTaskExecutor.execute(rtmpSpyingTask);
}
}
public class RtmpSpyingTask implements Runnable {
@Autowired
RtmpSourceRepository rtmpRep;
String nameIdCh;
String rtmpUrl;
public RtmpSpyingTask(String nameIdCh, String rtmpUrl) {
this.nameIdCh = nameIdCh;
this.rtmpUrl = rtmpUrl;
}
public void run() { …Run Code Online (Sandbox Code Playgroud)