async function sequentialCombine(urls, destination) {try {// Process each URL in orderfor (let i = 0; i < urls.length; i++) {const url = urls[i];// Get the current clipconst response = await fetch(url);if (!response.ok) {console.error(`Failed to obtain video clip: ${url}, Error code: ${response.status}`);continue;}// Get a readable streamconst readable = response.body;// Execute pipeTo immediately to write the current clip to the target streamtry {await readable.pipeTo(destination, {preventClose: true // Keep the stream open for subsequent writing});} catch (e) {console.error(`Stream processing errors (${url}): ${e.message}`);}}} catch (err) {console.error(`Merging video streams error: ${err.message}`);} finally {// Close the stream after all fragments are processedconst writer = destination.getWriter();writer.close();writer.releaseLock();}}async function handleRequest(request) {// The URLs of the video clips.const urls = ['https://vod.example.com/stream-01.mov','https://vod.example.comm/stream-02.mov','https://vod.example.com/stream-03.mov',];// Creating a Transformation Flowconst { readable, writable } = new TransformStream();// Get and merge video clips in sequencesequentialCombine(urls, writable);// Returns the merged video stream responsereturn new Response(readable, {headers: {'content-type': 'video/mp4',}});}// Listening for fetch eventsaddEventListener('fetch', event => {event.respondWith(handleRequest(event.request));});

Feedback