mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat(voice-notes): convert recordings to WAV on download
MediaRecorder gives us WebM/Opus, and that is exactly what we stored and served back. Browsers and desktop players read it, but no editing suite does: DaVinci Resolve, Premiere and Final Cut all refuse the container outright, so a voice note downloaded byte-for-byte was useless to the editor it was recorded for. The browser already decodes these formats in order to play them, so the conversion costs nothing but a RIFF header. lib/audio-to-wav.ts decodes through an OfflineAudioContext and writes interleaved 16-bit PCM. This runs at download time rather than at record time, so the stored object stays the small Opus file, uploads keep their 10MB limit, and self-hosted installs gain no server-side ffmpeg dependency. Voice comments had no download control at all, only a play button, so reviewers were saving files straight off the audio element and getting a bare UUID. They now get a download button on both comments and replies, named after the reviewer and the frame they were talking about, gated on the same download permission as the video and asset downloads. Audio assets get a WAV / Original menu. Files already in an editable container (wav, mp3, m4a) are handed over untouched: audio assets are not only recordings, and decoding an uploaded master back out would resample it to 48 kHz and requantise it to 16 bit for no gain. When a browser cannot decode the stored format at all, the original is saved and the user is told.
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import type { VideoAsset } from '@/components/video-page/types';
|
||||
import type { AssetDownloadPreference, VideoAsset } from '@/components/video-page/types';
|
||||
import { apiRequestError, toastApiError } from '@/lib/client/api-error';
|
||||
|
||||
type BunnyDownloadPreference = 'original' | 'compressed';
|
||||
import { downloadAudioAsWav } from '@/lib/client/download-file';
|
||||
|
||||
type CreateAssetPayload = {
|
||||
provider: 'R2_IMAGE' | 'YOUTUBE' | 'BUNNY' | 'R2_AUDIO' | 'R2_VIDEO';
|
||||
@@ -234,7 +233,7 @@ export function useVideoAssets({
|
||||
);
|
||||
|
||||
const downloadAsset = useCallback(
|
||||
async (asset: VideoAsset, preference: BunnyDownloadPreference = 'compressed') => {
|
||||
async (asset: VideoAsset, preference: AssetDownloadPreference = 'compressed') => {
|
||||
if (!canDownloadAssets) {
|
||||
toast.error('Asset downloads require an authenticated account');
|
||||
return;
|
||||
@@ -248,6 +247,20 @@ export function useVideoAssets({
|
||||
try {
|
||||
let downloadUrl = `/api/videos/${videoId}/assets/${asset.id}/download`;
|
||||
|
||||
// A voice note is stored as MediaRecorder wrote it, and no editing suite
|
||||
// reads WebM/Opus. Convert it in the browser so the download opens in the
|
||||
// timeline it was recorded for; 'original' is there for anyone who wants
|
||||
// the stored bytes instead.
|
||||
if (asset.provider === 'R2_AUDIO' && preference !== 'original') {
|
||||
const result = await downloadAudioAsWav(downloadUrl, asset.displayName);
|
||||
if (result === 'failed') {
|
||||
toast.error('Failed to download voice note');
|
||||
} else if (result === 'conversion-unsupported') {
|
||||
toast.warning('This browser cannot convert the recording. Downloaded the original.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (asset.provider === 'BUNNY') {
|
||||
const prepareRes = await fetch(`${downloadUrl}?source=${preference}&prepare=1`, {
|
||||
cache: 'no-store',
|
||||
|
||||
Reference in New Issue
Block a user