caffco / get-video-duration

Get the duration of a video file
MIT License
138 stars 17 forks source link

Docker ERROR [ExceptionsHandler] No duration found! [swimexpress] [2023-03-04 10:14:22] Error: No duration found! #293

Closed SebaBoler closed 1 year ago

SebaBoler commented 1 year ago

Hello,

i used

await getVideoDurationInSeconds(createReadStream()), 

on local computer MacOs works but when I will use function on docker ( Digitial Ocean ) I always receive

ERROR [ExceptionsHandler] No duration found!

I must install some lib etc in Docker ?

Sumolari commented 1 year ago

Hi @SebaBoler

Is createReadStream() returning a valid read stream?

You don’t need any additional libs installed, the error comes from ffprobe not being able to parse the input stream so the libs are probably already there and available, double check the input stream because the issue is probably there

SebaBoler commented 1 year ago

createReadStream is valid. Without any problem is uploaded to cloud . I have checked 5 times and this same file on the local server works perfectly with getVideoDuration.

Other media info apps read from stream all info that I need without any issue.

SebaBoler commented 1 year ago

I tried other ways and replace stream with filename but every time I have the error -1 fullPath/filename No such file or directory In the mutation of Graphql, I used FileUpload and the file is exists but not in the directory /src

SebaBoler commented 1 year ago

Its nice example on local env :

    Logger.log(`${await getVideoDurationInSeconds(createReadStream())}`);  return properly number
    duration from promise return issue : No found duration
        const { createReadStream } = await data.videoFile;
        Logger.log(`${await getVideoDurationInSeconds(createReadStream())}`);

        let duration: number;
        await new Promise<void>((resolve, reject) => {
          const stream = createReadStream();

          // Listen for any errors that might occur when creating the stream
          stream.on('error', (error) => {
            reject(error);
          });

          // Pass the stream to getVideoDurationInSeconds
          getVideoDurationInSeconds(stream).then((value) => {
            duration = value;
            resolve();
          });
Sumolari commented 1 year ago

There are some codecs that don't work properly with the stream-based API, this is something that happen in matroska container but can happen in other containers, too (see this issue), for instance). This limitation happens because those formats don't include the duration information in the header, and the underlying ffprobe cannot extract the duration without parsing the entire stream

For those situations I suggest keeping a local copy of the stream and extracting its duration before uploading them into your cloud provider or alternatively downloading the file from the cloud provider, parsing it locally and then storing the duration

SebaBoler commented 1 year ago

@Sumolari thanks. I have change strategy - media data we are extract on Frontend before upload