fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.96k stars 881 forks source link

No such file or directory for rtsp url #1260

Open mselgamal opened 8 months ago

mselgamal commented 8 months ago

Version information

Code to reproduce

ffmpegProcess = ffmpeg()
        .input("'rtsp://172.16.1.21:554/stream0?username=admin&password=<insert-pass>'")
        .inputOptions([
            '-loglevel debug',
            '-hide_banner',
            '-fflags nobuffer',
            '-flags low_delay',
            '-rtsp_transport udp'
        ])
        .outputOptions([
            '-c:v copy',
            '-an',
            '-preset veryfast',
            '-ssrc 0x'+ssrc,
            '-f rtp'
        ])
        .output("'rtp://52.86.222.93:43900?rtcpport=47929&pkt_size=1200'")
        .on('start', (commandLine) => {
            console.log('Spawned Ffmpeg with command: ' + commandLine);
        })
        .on('error', (err, stdout, stderr) => {
            console.error('An error occurred: ' + err.message);
            console.log('ffmpeg stdout:', stdout);
            console.log('ffmpeg stderr:', stderr);
        })
        .on('end', () => {
            console.log('Stream ended for camera');
        });

ffmpegProcess.run();

Expected results

ffmpeg process that streams rtp to a media server (output path)

everything works fine when using CLI to run identical command

Observed results

"rtsp://172.16.1.21:554/stream0?username=admin&password=E10ADC3949BA59ABBE56E057F20F883E": No such file or directory

Checklist

johnnykoo84 commented 3 months ago

I am not sure if I have similar issue. I can send stream videos to my client with files ok, but with rtsp url, I cannot.

i get these logs and cannot play rtps url

2024-08-07 21:51:08 Processing: undefined% done
2024-08-07 21:51:08 Processing error
2024-08-07 21:51:08 File not exist
2024-08-07 21:51:21 Processing: undefined% done
2024-08-07 21:51:21 Processing error
2024-08-07 21:51:21 File not exist
2024-08-07 21:51:21 Processing: undefined% done
2024-08-07 21:51:21 Processing error
2024-08-07 21:51:21 File not exist
2024-08-07 21:51:28 Processing: undefined% done
2024-08-07 21:51:28 Processing error
2024-08-07 21:51:28 File not exist
2024-08-07 21:51:41 Processing: undefined% done
2024-08-07 21:51:41 Processing error
2024-08-07 21:51:41 File not exist

my code is below

ffmpeg(rtspUrl, { timeout: 432000 })
    .addOptions([
      "-profile:v baseline",
      "-fflags -nobuffer",
      "-probesize 32",
      "-s 480x360",
      "-level 3.0",
      "-start_number 0",
      "-hls_time 2",
      "-hls_list_size 0",
      "-f hls",
    ])
    .output("videos/output.m3u8")
    .on("end", () => {
      console.log("end");
    })
    .on("progress", function (progress: { percent: string }) {
      console.log("Processing: " + progress.percent + "% done");

      fs.access("videos/output.m3u8", fs.constants.F_OK, function (err: any) {
        if (err) {
          console.log("Processing error");
          console.log("File not exist");
        } else {
          if (headersSent === false) {
            console.log("Processing success");
            console.log("File exists");

            console.log("==========");
            console.log("==========m3u8 file detected==========");
            console.log("==========");

            headersSent = true;

            res.sendStatus(200);
          }
        }
      });
    })
    .run();

update

I got it work with below code and options


ffmpeg(rtspUrl, { timeout: 432000 })
    .addOptions([
      "-rtsp_transport tcp", // Use TCP for RTSP
      "-c:v libx264", // Set video codec to H.264
      "-profile:v baseline", // Use baseline profile for HLS compatibility
      "-fflags -nobuffer", // Disable buffering
      "-probesize 32", // Set probe size
      "-s 480x360", // Set output resolution
      "-level 3.0", // Set H.264 level
      "-start_number 0", // Start segment numbering
      "-hls_time 2", // Set segment duration to 2 seconds
      "-hls_list_size 3", // Unlimited playlist size
      "-hls_delete_threshold 5",
      "-hls_flags delete_segments",
      "-f hls", // Set output format to HLS
    ])
    .output(path.join(videosDir, "output.m3u8"))
    .on("end", () => {
      console.log("end");
    })
    .on("progress", function (progress: { percent: string }) {
      console.log("Processing: " + progress.percent + "% done");

      fs.access("videos/output.m3u8", fs.constants.F_OK, function (err: any) {
        if (err) {
          console.log("Processing error");
          console.log("File not exist");
          console.log(err);
        } else {
          if (headersSent === false) {
            console.log("Processing success");
            console.log("File exists");

            console.log("==========");
            console.log("==========m3u8 file detected==========");
            console.log("==========");

            headersSent = true;

            res.sendStatus(200);
          }
        }
      });
    })
    .run();