first commit
This commit is contained in:
317
public/css/style.css
Normal file
317
public/css/style.css
Normal file
@@ -0,0 +1,317 @@
|
||||
:root {
|
||||
--bg-dark: #0f172a;
|
||||
--panel-bg: rgba(30, 41, 59, 0.7);
|
||||
--panel-border: rgba(255, 255, 255, 0.1);
|
||||
--text-primary: #f8fafc;
|
||||
--text-secondary: #94a3b8;
|
||||
--accent: #3b82f6;
|
||||
--accent-hover: #2563eb;
|
||||
--accent-glow: rgba(59, 130, 246, 0.5);
|
||||
--font-main: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-main);
|
||||
background-color: var(--bg-dark);
|
||||
color: var(--text-primary);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.background-effects {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: -1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.glow-orb {
|
||||
position: absolute;
|
||||
width: 600px;
|
||||
height: 600px;
|
||||
border-radius: 50%;
|
||||
filter: blur(80px);
|
||||
opacity: 0.4;
|
||||
animation: float 20s infinite ease-in-out alternate;
|
||||
}
|
||||
|
||||
.orb-1 {
|
||||
top: -200px;
|
||||
left: -100px;
|
||||
background: radial-gradient(circle, #3b82f6, transparent 70%);
|
||||
}
|
||||
|
||||
.orb-2 {
|
||||
bottom: -200px;
|
||||
right: -100px;
|
||||
background: radial-gradient(circle, #8b5cf6, transparent 70%);
|
||||
animation-delay: -10s;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0% { transform: translate(0, 0); }
|
||||
100% { transform: translate(100px, 50px); }
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
padding: 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: -1px;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
header h1 span {
|
||||
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
header p {
|
||||
color: var(--text-secondary);
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.dashboard {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr;
|
||||
gap: 2rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.glass-panel {
|
||||
background: var(--panel-bg);
|
||||
backdrop-filter: blur(16px);
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 16px;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.5rem;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-header h2 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
padding: 0.5rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.icon-btn:hover {
|
||||
color: var(--text-primary);
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.video-list {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-height: 500px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.video-list::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
.video-list::-webkit-scrollbar-thumb {
|
||||
background: var(--panel-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.video-item {
|
||||
padding: 1rem;
|
||||
border-radius: 12px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid transparent;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.video-item:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.video-item.active {
|
||||
background: rgba(59, 130, 246, 0.2);
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 15px var(--accent-glow);
|
||||
}
|
||||
|
||||
.video-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(135deg, #1e293b, #334155);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.video-info {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.video-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.video-meta {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary);
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.player-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
aspect-ratio: 16/9;
|
||||
background: #000;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
|
||||
}
|
||||
|
||||
#video-player {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.player-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
z-index: 10;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.player-overlay h3 {
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.player-overlay p {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.now-playing {
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1.5rem;
|
||||
border-top: 1px solid var(--panel-border);
|
||||
}
|
||||
|
||||
.now-playing h3 {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.now-playing p {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.spinner-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 0;
|
||||
gap: 1rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 3px solid rgba(255,255,255,0.1);
|
||||
border-radius: 50%;
|
||||
border-top-color: var(--accent);
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Responsive adjustments */
|
||||
@media (max-width: 900px) {
|
||||
.dashboard {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.video-list-section {
|
||||
order: 2;
|
||||
}
|
||||
|
||||
.player-section {
|
||||
order: 1;
|
||||
}
|
||||
}
|
||||
66
public/index.html
Normal file
66
public/index.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>S3 Video Streaming Boilerplate</title>
|
||||
<!-- Use Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
<!-- hls.js for HLS streaming support -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="background-effects">
|
||||
<div class="glow-orb orb-1"></div>
|
||||
<div class="glow-orb orb-2"></div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>S3 Media <span>Transcoder</span></h1>
|
||||
<p>Seamlessly stream videos from AWS S3 dynamically via FFmpeg HLS Transcoding</p>
|
||||
</header>
|
||||
|
||||
<main class="dashboard">
|
||||
<section class="video-list-section glass-panel">
|
||||
<div class="section-header">
|
||||
<h2>Available Videos</h2>
|
||||
<button id="refresh-btn" class="icon-btn" title="Refresh List">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
<div id="loading-spinner" class="spinner-container">
|
||||
<div class="spinner"></div>
|
||||
<p>Fetching S3 Objects...</p>
|
||||
</div>
|
||||
<ul id="video-list" class="video-list hidden">
|
||||
<!-- Video items injected by JS -->
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="player-section glass-panel">
|
||||
<div class="player-wrapper">
|
||||
<div id="player-overlay" class="player-overlay">
|
||||
<h3>Select a video to start transcoding</h3>
|
||||
</div>
|
||||
<div id="transcoding-overlay" class="player-overlay hidden">
|
||||
<div class="spinner"></div>
|
||||
<h3>Transcoding via FFmpeg...</h3>
|
||||
<p>Generating HLS segments, please wait.</p>
|
||||
</div>
|
||||
<video id="video-player" controls preload="auto" class="hidden"></video>
|
||||
</div>
|
||||
<div id="now-playing" class="now-playing hidden">
|
||||
<h3>Now Playing</h3>
|
||||
<p id="current-video-title">video.mp4</p>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
146
public/js/main.js
Normal file
146
public/js/main.js
Normal file
@@ -0,0 +1,146 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const videoListEl = document.getElementById('video-list');
|
||||
const loadingSpinner = document.getElementById('loading-spinner');
|
||||
const refreshBtn = document.getElementById('refresh-btn');
|
||||
const playerOverlay = document.getElementById('player-overlay');
|
||||
const transcodingOverlay = document.getElementById('transcoding-overlay');
|
||||
const videoPlayer = document.getElementById('video-player');
|
||||
const nowPlaying = document.getElementById('now-playing');
|
||||
const currentVideoTitle = document.getElementById('current-video-title');
|
||||
|
||||
let currentPollInterval = null;
|
||||
|
||||
// Fetch list of videos from the backend
|
||||
const fetchVideos = async () => {
|
||||
videoListEl.classList.add('hidden');
|
||||
loadingSpinner.classList.remove('hidden');
|
||||
videoListEl.innerHTML = '';
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/videos');
|
||||
if (!res.ok) throw new Error('Failed to fetch videos. Check S3 Config.');
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
loadingSpinner.classList.add('hidden');
|
||||
videoListEl.classList.remove('hidden');
|
||||
|
||||
if (data.videos.length === 0) {
|
||||
videoListEl.innerHTML = '<p style="color: var(--text-secondary); text-align: center; padding: 2rem;">No MP4 videos found in the S3 bucket.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
data.videos.forEach(key => {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'video-item';
|
||||
li.innerHTML = `
|
||||
<div class="video-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m22 8-6 4 6 4V8Z"/><rect width="14" height="12" x="2" y="6" rx="2" ry="2"/></svg>
|
||||
</div>
|
||||
<div class="video-info">
|
||||
<div class="video-title" title="${key}">${key.split('/').pop()}</div>
|
||||
<div class="video-meta">H264 / AAC</div>
|
||||
</div>
|
||||
`;
|
||||
li.addEventListener('click', () => selectVideo(key, li));
|
||||
videoListEl.appendChild(li);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
loadingSpinner.innerHTML = `<p style="color: #ef4444;">Error: ${err.message}</p>`;
|
||||
}
|
||||
};
|
||||
|
||||
// Handle video selection and trigger transcode
|
||||
const selectVideo = async (key, listItemNode) => {
|
||||
// Update UI
|
||||
document.querySelectorAll('.video-item').forEach(n => n.classList.remove('active'));
|
||||
listItemNode.classList.add('active');
|
||||
|
||||
// Reset player UI
|
||||
stopPolling();
|
||||
playerOverlay.classList.add('hidden');
|
||||
videoPlayer.classList.add('hidden');
|
||||
videoPlayer.pause();
|
||||
|
||||
nowPlaying.classList.remove('hidden');
|
||||
currentVideoTitle.textContent = key.split('/').pop();
|
||||
|
||||
transcodingOverlay.classList.remove('hidden');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/transcode', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ key })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error) throw new Error(data.error);
|
||||
|
||||
// Wait/Poll for HLS playlist to be ready
|
||||
pollForHlsReady(key, data.hlsUrl);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
transcodingOverlay.innerHTML = `<p style="color: #ef4444;">Transcode Failed: ${err.message}</p>`;
|
||||
}
|
||||
};
|
||||
|
||||
// Poll the backend to check if the generated m3u8 file is accessible
|
||||
const pollForHlsReady = (key, hlsUrl) => {
|
||||
let attempts = 0;
|
||||
const maxAttempts = 60; // 60 seconds max wait for first segment
|
||||
|
||||
currentPollInterval = setInterval(async () => {
|
||||
attempts++;
|
||||
try {
|
||||
const res = await fetch(`/api/status?key=${encodeURIComponent(key)}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ready) {
|
||||
stopPolling();
|
||||
playHlsStream(data.hlsUrl);
|
||||
} else if (attempts >= maxAttempts) {
|
||||
stopPolling();
|
||||
transcodingOverlay.innerHTML = `<p style="color: #ef4444;">Timeout waiting for HLS segments.</p>`;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Poll Error:", err);
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const stopPolling = () => {
|
||||
if (currentPollInterval) {
|
||||
clearInterval(currentPollInterval);
|
||||
currentPollInterval = null;
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize HLS Player
|
||||
const playHlsStream = (url) => {
|
||||
transcodingOverlay.classList.add('hidden');
|
||||
videoPlayer.classList.remove('hidden');
|
||||
|
||||
if (Hls.isSupported()) {
|
||||
const hls = new Hls();
|
||||
hls.loadSource(url);
|
||||
hls.attachMedia(videoPlayer);
|
||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
videoPlayer.play().catch(e => console.log('Auto-play blocked'));
|
||||
});
|
||||
} else if (videoPlayer.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
// Safari uses native HLS
|
||||
videoPlayer.src = url;
|
||||
videoPlayer.addEventListener('loadedmetadata', () => {
|
||||
videoPlayer.play().catch(e => console.log('Auto-play blocked'));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Bind events
|
||||
refreshBtn.addEventListener('click', fetchVideos);
|
||||
|
||||
// Initial load
|
||||
fetchVideos();
|
||||
});
|
||||
Reference in New Issue
Block a user