修复NVIDIA编码错误
This commit is contained in:
@@ -75,6 +75,7 @@
|
||||
<div id="now-playing" class="now-playing hidden">
|
||||
<h3>Now Playing</h3>
|
||||
<p id="current-video-title">video.mp4</p>
|
||||
<button id="transcode-btn" class="play-btn hidden">Start Transcode</button>
|
||||
<button id="play-btn" class="play-btn hidden">Play</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -9,12 +9,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const videoPlayer = document.getElementById('video-player');
|
||||
const nowPlaying = document.getElementById('now-playing');
|
||||
const currentVideoTitle = document.getElementById('current-video-title');
|
||||
const transcodeBtn = document.getElementById('transcode-btn');
|
||||
const playBtn = document.getElementById('play-btn');
|
||||
const progressInfo = document.getElementById('progress-info');
|
||||
const progressText = document.getElementById('progress-text');
|
||||
const progressFill = document.getElementById('progress-fill');
|
||||
|
||||
let currentPollInterval = null;
|
||||
let selectedKey = null;
|
||||
let ws = null;
|
||||
let wsConnected = false;
|
||||
let subscribedKey = null;
|
||||
@@ -87,6 +89,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
progressFill.style.width = '0%';
|
||||
};
|
||||
|
||||
if (transcodeBtn) {
|
||||
transcodeBtn.addEventListener('click', () => {
|
||||
startTranscode();
|
||||
});
|
||||
}
|
||||
|
||||
if (playBtn) {
|
||||
playBtn.addEventListener('click', () => {
|
||||
videoPlayer.play().catch(e => console.log('Play blocked:', e));
|
||||
@@ -207,7 +215,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
};
|
||||
|
||||
// Handle video selection and trigger transcode
|
||||
const selectVideo = async (key, listItemNode) => {
|
||||
const selectVideo = (key, listItemNode) => {
|
||||
// Update UI
|
||||
document.querySelectorAll('.video-item').forEach(n => n.classList.remove('active'));
|
||||
listItemNode.classList.add('active');
|
||||
@@ -217,21 +225,33 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
playerOverlay.classList.add('hidden');
|
||||
videoPlayer.classList.add('hidden');
|
||||
videoPlayer.pause();
|
||||
if (transcodeBtn) {
|
||||
transcodeBtn.disabled = false;
|
||||
transcodeBtn.textContent = 'Start Transcode';
|
||||
transcodeBtn.classList.remove('hidden');
|
||||
}
|
||||
if (playBtn) {
|
||||
playBtn.disabled = true;
|
||||
playBtn.textContent = '等待转码完成';
|
||||
playBtn.classList.remove('hidden');
|
||||
playBtn.classList.add('hidden');
|
||||
}
|
||||
resetProgress();
|
||||
|
||||
selectedKey = key;
|
||||
currentVideoKey = key;
|
||||
subscribeToKey(key);
|
||||
|
||||
nowPlaying.classList.remove('hidden');
|
||||
currentVideoTitle.textContent = key.split('/').pop();
|
||||
};
|
||||
|
||||
const startTranscode = async () => {
|
||||
if (!selectedKey) return;
|
||||
if (transcodeBtn) {
|
||||
transcodeBtn.disabled = true;
|
||||
transcodeBtn.textContent = 'Starting...';
|
||||
}
|
||||
stopPolling();
|
||||
transcodingOverlay.classList.remove('hidden');
|
||||
setProgress({ status: 'Starting transcoding...', percent: 0, details: 'Starting transcoding...' });
|
||||
setProgress({ status: 'Starting download...', percent: 0, details: 'Starting download...' });
|
||||
|
||||
try {
|
||||
const codec = codecSelect?.value || 'h264';
|
||||
@@ -239,14 +259,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const res = await fetch('/api/transcode', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ key, codec, encoder })
|
||||
body: JSON.stringify({ key: selectedKey, codec, encoder })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error) throw new Error(data.error);
|
||||
|
||||
if (!wsConnected) {
|
||||
pollForMp4Ready(key, data.mp4Url);
|
||||
pollForMp4Ready(selectedKey, data.mp4Url);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
Reference in New Issue
Block a user