Add ffmpeg download progress

This commit is contained in:
WardPearce
2024-09-10 18:29:45 +12:00
parent c719156f4f
commit 82d744abc5
3 changed files with 18 additions and 3 deletions
+2 -1
View File
@@ -73,7 +73,8 @@
"downloadSteps": {
"merging": "Merging video & audio together",
"video": "Downloading video",
"audio": "Downloading audio"
"audio": "Downloading audio",
"ffmpeg": "Downloading ffmpeg library & components"
},
"noPlaylists": "No playlists",
"unableToLoadComments": "Unable to load comments",
+10 -1
View File
@@ -125,8 +125,13 @@ export async function mergeMediaFromDASH(
video?: (progress: number) => void,
audio?: (progress: number) => void,
merging?: (progress: number) => void,
loadingFfmpeg?: (completed: boolean) => void;
}
) {
if (progressCallbacks?.loadingFfmpeg) {
progressCallbacks.loadingFfmpeg(false);
}
const FFmpeg = await import('@ffmpeg/ffmpeg');
const ffmpeg = new FFmpeg.FFmpeg();
@@ -144,6 +149,10 @@ export async function mergeMediaFromDASH(
workerURL: await toBlobURL('/ffmpeg/ffmpeg-core.worker.js', 'text/javascript')
});
if (progressCallbacks?.loadingFfmpeg) {
progressCallbacks.loadingFfmpeg(true);
}
const { videoUrl, audioUrl } = selectedQuality;
ffmpeg.writeFile('input.mp4', await fetchFile(videoUrl, progressCallbacks?.video));
@@ -156,7 +165,7 @@ export async function mergeMediaFromDASH(
const url = URL.createObjectURL(mergedFile);
const a = document.createElement('a');
a.href = url;
a.download = `${fileName}.mp4`;
a.download = `${fileName} - ${selectedQuality.resolution}.mp4`;
document.body.appendChild(a);
a.click();
@@ -414,6 +414,10 @@
downloadStage = undefined;
}
}
function onLoadingFFmpeg(completed: boolean) {
downloadStage = $_('player.downloadSteps.ffmpeg');
}
</script>
<svelte:head>
@@ -541,7 +545,8 @@
await mergeMediaFromDASH(quality, data.video.title, {
video: onVideoDownloadProgress,
audio: onAudioDownloadProgress,
merging: onMergingProgress
merging: onMergingProgress,
loadingFfmpeg: onLoadingFFmpeg
})}>{quality.resolution}</a
>
{/each}