video_manager.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>RTSP视频流管理系统</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  15. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  16. min-height: 100vh;
  17. padding: 20px;
  18. }
  19. .container {
  20. max-width: 1400px;
  21. margin: 0 auto;
  22. }
  23. .header {
  24. background: white;
  25. padding: 30px;
  26. border-radius: 10px;
  27. box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  28. margin-bottom: 30px;
  29. }
  30. h1 {
  31. color: #333;
  32. margin-bottom: 10px;
  33. }
  34. .subtitle {
  35. color: #666;
  36. font-size: 14px;
  37. }
  38. .stats {
  39. display: grid;
  40. grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  41. gap: 20px;
  42. margin-bottom: 30px;
  43. }
  44. .stat-card {
  45. background: white;
  46. padding: 20px;
  47. border-radius: 10px;
  48. box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  49. }
  50. .stat-card h3 {
  51. color: #666;
  52. font-size: 14px;
  53. margin-bottom: 10px;
  54. }
  55. .stat-card .value {
  56. color: #333;
  57. font-size: 32px;
  58. font-weight: bold;
  59. }
  60. .content {
  61. background: white;
  62. padding: 30px;
  63. border-radius: 10px;
  64. box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  65. }
  66. .tabs {
  67. display: flex;
  68. gap: 10px;
  69. margin-bottom: 20px;
  70. border-bottom: 2px solid #eee;
  71. }
  72. .tab {
  73. padding: 10px 20px;
  74. background: none;
  75. border: none;
  76. cursor: pointer;
  77. font-size: 16px;
  78. color: #666;
  79. transition: all 0.3s;
  80. }
  81. .tab.active {
  82. color: #667eea;
  83. border-bottom: 2px solid #667eea;
  84. margin-bottom: -2px;
  85. }
  86. .tab-content {
  87. display: none;
  88. }
  89. .tab-content.active {
  90. display: block;
  91. }
  92. .timestamp-list {
  93. display: grid;
  94. gap: 15px;
  95. }
  96. .timestamp-item {
  97. background: #f8f9fa;
  98. padding: 20px;
  99. border-radius: 8px;
  100. border-left: 4px solid #667eea;
  101. }
  102. .timestamp-header {
  103. display: flex;
  104. justify-content: space-between;
  105. align-items: center;
  106. margin-bottom: 10px;
  107. }
  108. .timestamp-name {
  109. font-size: 18px;
  110. font-weight: bold;
  111. color: #333;
  112. }
  113. .timestamp-info {
  114. color: #666;
  115. font-size: 14px;
  116. }
  117. .btn {
  118. padding: 8px 16px;
  119. border: none;
  120. border-radius: 5px;
  121. cursor: pointer;
  122. font-size: 14px;
  123. transition: all 0.3s;
  124. }
  125. .btn-primary {
  126. background: #667eea;
  127. color: white;
  128. }
  129. .btn-primary:hover {
  130. background: #5568d3;
  131. }
  132. .btn-danger {
  133. background: #dc3545;
  134. color: white;
  135. }
  136. .btn-danger:hover {
  137. background: #c82333;
  138. }
  139. .btn-success {
  140. background: #28a745;
  141. color: white;
  142. }
  143. .btn-success:hover {
  144. background: #218838;
  145. }
  146. .video-grid {
  147. display: grid;
  148. grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  149. gap: 20px;
  150. margin-top: 15px;
  151. }
  152. .video-card {
  153. background: white;
  154. border: 1px solid #ddd;
  155. border-radius: 8px;
  156. padding: 15px;
  157. transition: all 0.3s;
  158. }
  159. .video-card:hover {
  160. box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  161. }
  162. .video-name {
  163. font-weight: bold;
  164. color: #333;
  165. margin-bottom: 8px;
  166. }
  167. .video-info {
  168. font-size: 12px;
  169. color: #666;
  170. margin-bottom: 5px;
  171. }
  172. .loading {
  173. text-align: center;
  174. padding: 40px;
  175. color: #666;
  176. }
  177. .error {
  178. background: #f8d7da;
  179. color: #721c24;
  180. padding: 15px;
  181. border-radius: 5px;
  182. margin-bottom: 20px;
  183. }
  184. .success {
  185. background: #d4edda;
  186. color: #155724;
  187. padding: 15px;
  188. border-radius: 5px;
  189. margin-bottom: 20px;
  190. }
  191. .refresh-btn {
  192. float: right;
  193. margin-bottom: 20px;
  194. }
  195. /* 视频播放器样式 */
  196. .video-modal {
  197. display: none;
  198. position: fixed;
  199. top: 0;
  200. left: 0;
  201. width: 100%;
  202. height: 100%;
  203. background: rgba(0, 0, 0, 0.9);
  204. z-index: 1000;
  205. justify-content: center;
  206. align-items: center;
  207. }
  208. .video-modal.active {
  209. display: flex;
  210. }
  211. .video-modal-content {
  212. background: white;
  213. border-radius: 10px;
  214. padding: 20px;
  215. max-width: 90%;
  216. max-height: 90%;
  217. position: relative;
  218. }
  219. .video-modal-header {
  220. display: flex;
  221. justify-content: space-between;
  222. align-items: center;
  223. margin-bottom: 15px;
  224. }
  225. .video-modal-title {
  226. font-size: 18px;
  227. font-weight: bold;
  228. color: #333;
  229. }
  230. .close-btn {
  231. background: #dc3545;
  232. color: white;
  233. border: none;
  234. border-radius: 50%;
  235. width: 35px;
  236. height: 35px;
  237. cursor: pointer;
  238. font-size: 20px;
  239. line-height: 1;
  240. transition: all 0.3s;
  241. }
  242. .close-btn:hover {
  243. background: #c82333;
  244. transform: rotate(90deg);
  245. }
  246. .video-player {
  247. width: 100%;
  248. max-width: 1200px;
  249. max-height: 70vh;
  250. background: #000;
  251. border-radius: 5px;
  252. }
  253. .video-info-panel {
  254. margin-top: 15px;
  255. padding: 15px;
  256. background: #f8f9fa;
  257. border-radius: 5px;
  258. }
  259. .video-info-item {
  260. display: flex;
  261. justify-content: space-between;
  262. margin-bottom: 8px;
  263. font-size: 14px;
  264. }
  265. .video-info-label {
  266. color: #666;
  267. font-weight: bold;
  268. }
  269. .video-info-value {
  270. color: #333;
  271. }
  272. .btn-play {
  273. background: #28a745;
  274. color: white;
  275. margin-right: 5px;
  276. }
  277. .btn-play:hover {
  278. background: #218838;
  279. }
  280. </style>
  281. </head>
  282. <body>
  283. <div class="container">
  284. <div class="header">
  285. <h1>🎥 RTSP视频流管理系统</h1>
  286. <p class="subtitle">查看和管理您的视频流录制文件</p>
  287. </div>
  288. <div class="stats" id="stats">
  289. <div class="stat-card">
  290. <h3>时间戳目录</h3>
  291. <div class="value" id="timestamp-count">-</div>
  292. </div>
  293. <div class="stat-card">
  294. <h3>视频总数</h3>
  295. <div class="value" id="video-count">-</div>
  296. </div>
  297. <div class="stat-card">
  298. <h3>总大小</h3>
  299. <div class="value" id="total-size">-</div>
  300. </div>
  301. </div>
  302. <div class="content">
  303. <div id="message"></div>
  304. <button class="btn btn-success refresh-btn" onclick="loadData()">🔄 刷新</button>
  305. <div class="tabs">
  306. <button class="tab active" onclick="switchTab('timestamps')">时间戳目录</button>
  307. <button class="tab" onclick="switchTab('videos')">所有视频</button>
  308. </div>
  309. <div id="timestamps-tab" class="tab-content active">
  310. <div class="loading">加载中...</div>
  311. </div>
  312. <div id="videos-tab" class="tab-content">
  313. <div class="loading">加载中...</div>
  314. </div>
  315. </div>
  316. </div>
  317. <!-- 视频播放器模态框 -->
  318. <div id="video-modal" class="video-modal">
  319. <div class="video-modal-content">
  320. <div class="video-modal-header">
  321. <div class="video-modal-title" id="video-title">视频播放</div>
  322. <button class="close-btn" onclick="closeVideoPlayer()">×</button>
  323. </div>
  324. <video id="video-player" class="video-player" controls>
  325. 您的浏览器不支持视频播放。
  326. </video>
  327. <div class="video-info-panel" id="video-details">
  328. <!-- 视频详细信息将在这里显示 -->
  329. </div>
  330. </div>
  331. </div>
  332. <script>
  333. const API_BASE = 'http://localhost:8080';
  334. function switchTab(tab) {
  335. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  336. document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
  337. event.target.classList.add('active');
  338. document.getElementById(tab + '-tab').classList.add('active');
  339. }
  340. function formatBytes(bytes) {
  341. if (bytes === 0) return '0 B';
  342. const k = 1024;
  343. const sizes = ['B', 'KB', 'MB', 'GB'];
  344. const i = Math.floor(Math.log(bytes) / Math.log(k));
  345. return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
  346. }
  347. function showMessage(message, type = 'success') {
  348. const messageDiv = document.getElementById('message');
  349. messageDiv.innerHTML = `<div class="${type}">${message}</div>`;
  350. setTimeout(() => {
  351. messageDiv.innerHTML = '';
  352. }, 3000);
  353. }
  354. function playVideo(videoPath, filename, fileSize, createdTime, timestampDir, streamIndex) {
  355. const modal = document.getElementById('video-modal');
  356. const player = document.getElementById('video-player');
  357. const title = document.getElementById('video-title');
  358. const details = document.getElementById('video-details');
  359. // 设置视频标题
  360. title.textContent = `▶ ${filename}`;
  361. // 设置视频源 - 使用相对路径
  362. const relativePath = `${timestampDir}/${filename}`;
  363. const videoUrl = `${API_BASE}/videos/${encodeURIComponent(relativePath)}`;
  364. console.log('设置视频源:', videoUrl);
  365. player.src = videoUrl;
  366. player.load();
  367. // 显示视频详细信息
  368. details.innerHTML = `
  369. <div class="video-info-item">
  370. <span class="video-info-label">📁 文件名:</span>
  371. <span class="video-info-value">${filename}</span>
  372. </div>
  373. <div class="video-info-item">
  374. <span class="video-info-label">📊 文件大小:</span>
  375. <span class="video-info-value">${formatBytes(fileSize)}</span>
  376. </div>
  377. <div class="video-info-item">
  378. <span class="video-info-label">🕒 创建时间:</span>
  379. <span class="video-info-value">${createdTime}</span>
  380. </div>
  381. <div class="video-info-item">
  382. <span class="video-info-label">📂 时间戳目录:</span>
  383. <span class="video-info-value">${timestampDir}</span>
  384. </div>
  385. <div class="video-info-item">
  386. <span class="video-info-label">📍 流索引:</span>
  387. <span class="video-info-value">${streamIndex}</span>
  388. </div>
  389. <div class="video-info-item">
  390. <span class="video-info-label">📍 完整路径:</span>
  391. <span class="video-info-value">${videoPath}</span>
  392. </div>
  393. `;
  394. // 显示模态框
  395. modal.classList.add('active');
  396. // 尝试自动播放
  397. player.play().catch(err => {
  398. console.log('自动播放失败,需要用户交互:', err);
  399. });
  400. }
  401. function closeVideoPlayer() {
  402. const modal = document.getElementById('video-modal');
  403. const player = document.getElementById('video-player');
  404. // 暂停播放
  405. player.pause();
  406. player.src = '';
  407. // 隐藏模态框
  408. modal.classList.remove('active');
  409. }
  410. // 点击模态框背景关闭
  411. document.getElementById('video-modal').addEventListener('click', function(e) {
  412. if (e.target === this) {
  413. closeVideoPlayer();
  414. }
  415. });
  416. // ESC键关闭
  417. document.addEventListener('keydown', function(e) {
  418. if (e.key === 'Escape') {
  419. closeVideoPlayer();
  420. }
  421. });
  422. async function loadStats() {
  423. try {
  424. const [timestampsRes, videosRes] = await Promise.all([
  425. fetch(`${API_BASE}/api/timestamps`),
  426. fetch(`${API_BASE}/api/videos`)
  427. ]);
  428. const timestamps = await timestampsRes.json();
  429. const videos = await videosRes.json();
  430. document.getElementById('timestamp-count').textContent = timestamps.count;
  431. document.getElementById('video-count').textContent = videos.count;
  432. const totalSize = videos.videos.reduce((sum, video) => sum + video.file_size, 0);
  433. document.getElementById('total-size').textContent = formatBytes(totalSize);
  434. } catch (error) {
  435. console.error('加载统计数据失败:', error);
  436. }
  437. }
  438. async function loadTimestamps() {
  439. const container = document.getElementById('timestamps-tab');
  440. container.innerHTML = '<div class="loading">加载中...</div>';
  441. try {
  442. const response = await fetch(`${API_BASE}/api/timestamps`);
  443. const data = await response.json();
  444. if (data.count === 0) {
  445. container.innerHTML = '<div class="loading">暂无时间戳目录</div>';
  446. return;
  447. }
  448. let html = '<div class="timestamp-list">';
  449. for (const ts of data.timestamps) {
  450. html += `
  451. <div class="timestamp-item">
  452. <div class="timestamp-header">
  453. <div>
  454. <div class="timestamp-name">📁 ${ts.timestamp}</div>
  455. <div class="timestamp-info">
  456. ${ts.video_count} 个视频 | ${formatBytes(ts.total_size)}
  457. </div>
  458. </div>
  459. <div>
  460. <button class="btn btn-primary" onclick="viewTimestamp('${ts.timestamp}')">查看</button>
  461. <button class="btn btn-danger" onclick="deleteTimestamp('${ts.timestamp}')">删除</button>
  462. </div>
  463. </div>
  464. <div id="videos-${ts.timestamp}"></div>
  465. </div>
  466. `;
  467. }
  468. html += '</div>';
  469. container.innerHTML = html;
  470. } catch (error) {
  471. container.innerHTML = `<div class="error">加载失败: ${error.message}</div>`;
  472. }
  473. }
  474. async function viewTimestamp(timestamp) {
  475. const container = document.getElementById(`videos-${timestamp}`);
  476. if (container.innerHTML) {
  477. container.innerHTML = '';
  478. return;
  479. }
  480. container.innerHTML = '<div class="loading">加载中...</div>';
  481. try {
  482. const response = await fetch(`${API_BASE}/api/videos/${timestamp}`);
  483. const data = await response.json();
  484. let html = '<div class="video-grid">';
  485. for (const video of data.videos) {
  486. html += `
  487. <div class="video-card">
  488. <div class="video-name">🎬 ${video.filename}</div>
  489. <div class="video-info">📊 大小: ${formatBytes(video.file_size)}</div>
  490. <div class="video-info">🕒 创建时间: ${video.created_time}</div>
  491. <div class="video-info">📍 流索引: ${video.stream_index}</div>
  492. <div style="margin-top: 10px; display: flex; gap: 5px;">
  493. <button class="btn btn-play" style="flex: 1;"
  494. onclick="playVideo('${video.full_path}', '${video.filename}', ${video.file_size}, '${video.created_time}', '${video.timestamp_dir}', '${video.stream_index}')">▶ 播放</button>
  495. <button class="btn btn-danger" style="flex: 1;"
  496. onclick="deleteVideo('${video.full_path}')">删除</button>
  497. </div>
  498. </div>
  499. `;
  500. }
  501. html += '</div>';
  502. container.innerHTML = html;
  503. } catch (error) {
  504. container.innerHTML = `<div class="error">加载失败: ${error.message}</div>`;
  505. }
  506. }
  507. async function loadAllVideos() {
  508. const container = document.getElementById('videos-tab');
  509. container.innerHTML = '<div class="loading">加载中...</div>';
  510. try {
  511. const response = await fetch(`${API_BASE}/api/videos`);
  512. const data = await response.json();
  513. if (data.count === 0) {
  514. container.innerHTML = '<div class="loading">暂无视频文件</div>';
  515. return;
  516. }
  517. let html = '<div class="video-grid">';
  518. for (const video of data.videos) {
  519. html += `
  520. <div class="video-card">
  521. <div class="video-name">🎬 ${video.filename}</div>
  522. <div class="video-info">📁 目录: ${video.timestamp_dir}</div>
  523. <div class="video-info">📊 大小: ${formatBytes(video.file_size)}</div>
  524. <div class="video-info">🕒 创建时间: ${video.created_time}</div>
  525. <div class="video-info">📍 流索引: ${video.stream_index}</div>
  526. <div style="margin-top: 10px; display: flex; gap: 5px;">
  527. <button class="btn btn-play" style="flex: 1;"
  528. onclick="playVideo('${video.full_path}', '${video.filename}', ${video.file_size}, '${video.created_time}', '${video.timestamp_dir}', '${video.stream_index}')">▶ 播放</button>
  529. <button class="btn btn-danger" style="flex: 1;"
  530. onclick="deleteVideo('${video.full_path}')">删除</button>
  531. </div>
  532. </div>
  533. `;
  534. }
  535. html += '</div>';
  536. container.innerHTML = html;
  537. } catch (error) {
  538. container.innerHTML = `<div class="error">加载失败: ${error.message}</div>`;
  539. }
  540. }
  541. async function deleteVideo(path) {
  542. if (!confirm(`确定要删除视频文件吗?\n${path}`)) {
  543. return;
  544. }
  545. try {
  546. const response = await fetch(`${API_BASE}/api/video?path=${encodeURIComponent(path)}`, {
  547. method: 'DELETE'
  548. });
  549. const data = await response.json();
  550. if (data.success) {
  551. showMessage('视频删除成功', 'success');
  552. loadData();
  553. } else {
  554. showMessage('视频删除失败: ' + data.message, 'error');
  555. }
  556. } catch (error) {
  557. showMessage('删除失败: ' + error.message, 'error');
  558. }
  559. }
  560. async function deleteTimestamp(timestamp) {
  561. if (!confirm(`确定要删除整个时间戳目录吗?\n${timestamp}\n\n这将删除该目录下的所有文件!`)) {
  562. return;
  563. }
  564. try {
  565. const response = await fetch(`${API_BASE}/api/timestamp/${timestamp}`, {
  566. method: 'DELETE'
  567. });
  568. const data = await response.json();
  569. if (data.success) {
  570. showMessage('目录删除成功', 'success');
  571. loadData();
  572. } else {
  573. showMessage('目录删除失败: ' + data.message, 'error');
  574. }
  575. } catch (error) {
  576. showMessage('删除失败: ' + error.message, 'error');
  577. }
  578. }
  579. function loadData() {
  580. loadStats();
  581. loadTimestamps();
  582. loadAllVideos();
  583. }
  584. // 页面加载时初始化
  585. window.onload = loadData;
  586. </script>
  587. </body>
  588. </html>