brocolli
brocolli
CCConvex Community
Created by brocolli on 9/5/2024 in #support-community
Video processing
Hi I need to transcode a mp4 into mp3 to get the audio from a video, but since convex is serverless, dont have access to file system, and convex functions are on the cloud so they dont have access to my localhost either, are there any solutions for this?
export async function extractAudioFromVideo(
videoBuffer: ArrayBuffer,
outputFileName: string = 'test-sample',
options: ExtractAudioOptions = {}
): Promise<ArrayBuffer> {
const apiUrl = 'https://api.apyhub.com/extract/video/audio/file';
const token = process.env.CONVEX_APY_TOKEN;

if (!token) {
throw new Error('CONVEX_APY_TOKEN environment variable is not set');
}

const params = new URLSearchParams();
params.append('output', outputFileName);
if (options.startTime) params.append('start_time', options.startTime);
if (options.duration) params.append('duration', options.duration);
if (options.outputFormat) params.append('output_format', options.outputFormat);

const response = await fetch(`${apiUrl}?${params.toString()}`, {
method: 'POST',
headers: {
'apy-token': token,
'Content-Type': 'application/octet-stream',
},
body: videoBuffer
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

return response.arrayBuffer();
}
export async function extractAudioFromVideo(
videoBuffer: ArrayBuffer,
outputFileName: string = 'test-sample',
options: ExtractAudioOptions = {}
): Promise<ArrayBuffer> {
const apiUrl = 'https://api.apyhub.com/extract/video/audio/file';
const token = process.env.CONVEX_APY_TOKEN;

if (!token) {
throw new Error('CONVEX_APY_TOKEN environment variable is not set');
}

const params = new URLSearchParams();
params.append('output', outputFileName);
if (options.startTime) params.append('start_time', options.startTime);
if (options.duration) params.append('duration', options.duration);
if (options.outputFormat) params.append('output_format', options.outputFormat);

const response = await fetch(`${apiUrl}?${params.toString()}`, {
method: 'POST',
headers: {
'apy-token': token,
'Content-Type': 'application/octet-stream',
},
body: videoBuffer
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

return response.arrayBuffer();
}
2 replies