Skip to content

Commit

Permalink
+ fixed bitrate and sync issue !
Browse files Browse the repository at this point in the history
  • Loading branch information
zonetecde committed Aug 28, 2024
1 parent d9c0c1f commit 0a00f11
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async fn do_file_exist(path: String) -> bool {
async fn download_youtube_video(format: String, url: String, path: String) -> bool {
let format_flag = match format.as_str() {
"mp3" => {
vec!["-x", "--audio-format", "mp3"]
// Specify bitrate for MP3 format (example: 192kbps CBR)
vec!["-x", "--audio-format", "mp3", "--audio-quality", "192K"]
}
"mp4" => {
vec!["--format", "mp4"]
Expand Down Expand Up @@ -101,4 +102,3 @@ async fn download_youtube_video(format: String, url: String, path: String) -> bo
}
}
}

8 changes: 8 additions & 0 deletions src/lib/components/assetsmanager/AssetsManager.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
}).then((result) => {
if (result === null) return;
toast(
'Please make sure that your audio/video have a constant bitrate, otherwise you might encounter synchronization issues.',
{
duration: 5000,
icon: '⚠️'
}
);
// Add the selected files to the store
addAssets(result);
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/components/preview/VideoPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
}
if (currentAudio && audioComponent)
audioComponent.currentTime = ($cursorPosition - currentAudio.start) / 1000;
// hh:mm:ss
console.log(secondsToHHMMSS(audioComponent.currentTime));
setTimeout(() => {
console.log(secondsToHHMMSS(audioComponent.currentTime));
}, 1000);
}
/**
Expand Down Expand Up @@ -164,7 +170,7 @@
const interval = setInterval(() => {
if ($isPreviewPlaying && (videoComponent || audioComponent)) {
// Réajuste la position du curseur pour éviter des problèmes de sync
reajustCursorPosition();
reajustCursorPosition(true);
// Si on arrive à la fin de la timeline, on scroll un peu pour voir la fin
if ($zoom === 30 && $cursorPosition > 5000 && ($cursorPosition * $zoom) % 1000 < 300) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/subtitles/WordsSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
const audioElement = document.getElementById('audio-preview') as HTMLAudioElement;
const currentTimeMs = audioElement.currentTime * 1000;
reajustCursorPosition();
reajustCursorPosition(false);
// Vérifie qu'on est pas au 0
if (currentTimeMs < 100) {
Expand Down
15 changes: 7 additions & 8 deletions src/lib/ext/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export async function importAndReadFile(
* Reajust the cursor position according to the video or the audio
* @param useVideoPreview If true, the cursor position will be reajusted according to the video preview, otherwise it will be reajusted according to the audio preview
*/
export function reajustCursorPosition() {
const mediaPreviewElement =
(document.getElementById('audio-preview') as any) ||
(document.getElementById('video-preview') as any);
export function reajustCursorPosition(useVideoPreview: boolean) {
const mediaPreviewElement = document.getElementById(
useVideoPreview ? 'video-preview' : 'audio-preview'
) as any;

if (mediaPreviewElement) {
// Vérifie que c'est la seul vidéo dans la timeline (sinon on prend la pos du curseur)
Expand All @@ -94,10 +94,9 @@ export function reajustCursorPosition() {
// Si il y a plusieurs vidéos ont doit aussi ajouter la durée de toutes les vidéos d'avant
let totalDuration = 0;

const clips =
mediaPreviewElement instanceof HTMLVideoElement
? get(currentProject).timeline.videosTracks[0].clips
: get(currentProject).timeline.audiosTracks[0].clips;
const clips = useVideoPreview
? get(currentProject).timeline.videosTracks[0].clips
: get(currentProject).timeline.audiosTracks[0].clips;

for (let i = 0; i < clips.length; i++) {
const video = clips[i];
Expand Down

0 comments on commit 0a00f11

Please sign in to comment.