由于工作需要,需要使用RTSP直播摄像头,实现方案是使用VLC页面插件播放。另外需要实现视频的截屏功能,实现方案是使用ffmpeg.exe实现。
- 页面视频直播实现代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>VLC视频预览</title>
</head>
<body>
<!--[if IE]>
<object type='application/x-vlc-plugin' id='vlc' events='True'
classid='clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921' codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab" width="720" height="540">
<param name='mrl' value='rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp' />
<param name='volume' value='50' />
<param name='autoplay' value='true' />
<param name='loop' value='false' />
<param name='fullscreen' value='false' />
</object>
<![endif]-->
<!--[if !IE]><!-->
<!-- 视频预览 使用大华摄像头,不同品牌摄像头RTSP有所区别,这里不做说明-->
<object type='application/x-vlc-plugin' id='vlc' events='True' width="720" height="600" pluginspage="http://www.videolan.org" codebase="http://downloads.videolan.org/pub/videolan/vlc-webplugins/2.2.2/npapi-vlc-2.2.2.tar.xz">
<param name='mrl' value='rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1&proto=Dahua3' />
<param name='volume' value='50' />
<param name='autoplay' value='true' />
<param name='loop' value='false' />
<param name='fullscreen' value='false' />
</object>
<!--<![endif]-->
</body>
</html>
- 使用ffmpeg截图
使用ffmpeg.exe实现截图,需要先下载当前应用,下载地址如下:
链接:https://pan.baidu.com/s/1MEvUXPMe6bDOsQYt5LMIxA 提取码:y177
实现代码只说明一个DEMO,具体业务实现根据自己需要调整。
/**
* 使用ffmpeg.exe的命令执行截图,不要添加任何JAR包。
*
* @author: andy.jia
* @description:
* @version:
* @data:2020年6月13日
*
*/
public class CutImgUtil {
public static String transfer(String inFile, String outFile) {
String size = "600x480"; // 图片大小
String ffmpeg = "D:\\ffmpeg-win64-static\\bin\\ffmpeg.exe";
String command = ffmpeg + " -i " + inFile
+ " -vframes 1 -y -f image2 -t 1 -s " + size + " " + outFile;
try {
Process process = Runtime.getRuntime().exec(command);
InputStreamReader ir = new InputStreamReader(
process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
while ((input.readLine()) != null) {
}
} catch (java.io.IOException e) {
}
return outFile;
}
public static void main(String[] args) {
String rtsp = "rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1&proto=Dahua3";
CutImgUtil.transfer(rtsp, "D:\\file\\" + System.currentTimeMillis()
+ ".jpg");
}
}
以上均测试没有问题。