Product
Streams
Question
Is it possible for bitmovin api to get all audio tracks from video when uploading it to bitmovin?
Streams
Is it possible for bitmovin api to get all audio tracks from video when uploading it to bitmovin?
My code is:
export async function uploadVideo(
file: File,
formData: UploadVideo,
onProgress: (progress: number) => void,
onSuccess: (videoId: string, videoUrl: string) => void
) {
const { title, description } = formData;
// 1. Generate URL for Direct File Upload
const directFileInput =
await bitmovinApi.encoding.inputs.directFileUpload.create(
new DirectFileUploadInput()
);
if (!directFileInput.uploadUrl) {
return;
}
// 2. Upload the file to the generated URL
const request = new XMLHttpRequest();
request.upload.addEventListener("progress", (event) => {
if (event.lengthComputable) {
const progress = (event.loaded / event.total) * 100;
onProgress(progress);
}
});
request.addEventListener("load", async () => {
// Handle successful upload, parse the response, and call onSuccess with the videoId
if (request.status >= 200 && request.status < 300) {
// 3. Create a Stream with the uploaded video
const streamRequest = new StreamsVideoCreateRequest({
assetUrl: `https://api.bitmovin.com/v1/encoding/inputs/direct-file-upload/${directFileInput.id}`,
title,
description,
});
const stream = (await bitmovinApi.streams.video.create(
streamRequest
)) as Video;
// 4. Call onSuccess callback with videoId
onSuccess(stream.id, stream.assetUrl ? stream.assetUrl : "");
} else {
console.error("Upload failed:", request.responseText);
}
});
request.open("PUT", directFileInput.uploadUrl);
request.overrideMimeType(file.type);
request.send(file);