ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
14.22k stars 831 forks source link

Cannot read m3u8 files #534

Closed xaviernaves closed 1 year ago

xaviernaves commented 1 year ago

Describe the bug

To Reproduce Steps to reproduce the behavior:

import { FFmpeg } from "@ffmpeg/ffmpeg";
import { toBlobURL, fetchFile } from "@ffmpeg/util";
const baseURL = "https://unpkg.com/@ffmpeg/core@0.12.1/dist/esm";
const ffmpeg = new FFmpeg();
await ffmpeg.load({
    coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"),
    wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, "application/wasm"),
});

const source = "https://res.cloudinary.com/dannykeane/video/upload/sp_full_hd/q_80:qmax_90,ac_none/v1/dk-memoji-dark.m3u8";

await ffmpeg.writeFile("input.m3u8", await fetchFile(source));
await ffmpeg.exec([
    "-i",
    "input.m3u8",
    "-c",
    "copy",
    "-bsf:a",
    "aac_adtstoasc",
    "output.mp4",
]);
const data = await ffmpeg.readFile("output.mp4");    // This outputs said error

Expected behavior Output the file in mp4

Desktop (please complete the following information):

jeromewu commented 1 year ago

It is highly recommended to listen to log events to diagnose the problem:

const ffmpeg = new FFmpeg();
ffmpeg.on("log", ({ message }) => {
  console.log(message);
});

And for you question, I have tried with follow parameters and sadly it is not working due to lack of openssl lib:

await ffmpeg.exec([
    "-i",
    "https://res.cloudinary.com/dannykeane/video/upload/sp_full_hd/q_80:qmax_90,ac_none/v1/dk-memoji-dark.m3u8",
    "-c",
    "copy",
    "-bsf:a",
    "aac_adtstoasc",
    "output.mp4",
]);

image

I remembered I tried to compile with openssl once in the past, but encountered errors regarding network protocol. It is unlikely I can successfully build one even now.

I think the best bet you have is to download .m3u8 file and parse the file until you got .ts file URLs, then you can concat those *.ts files together. example here: https://github.com/ffmpegwasm/ffmpeg.wasm/blob/main/apps/vanilla-app/public/concatDemuxer.html

Hope it helps.

xaviernaves commented 1 year ago

Thank you, I managed to make it work with the information you provided.

I will close the issue.