HTML使用VLC WEB插件播放RTSP視頻,並實現視頻截圖

由於工作需要,需要使用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");
	}

}

 

以上均測試沒有問題。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章