Recherche avancée

Médias (1)

Mot : - Tags -/lev manovitch

Sur d’autres sites (2478)

  • How to live video stream using node API(Read file with chunk logic)

    28 septembre 2023, par Mukesh Singh Thakur

    I want to make a live video streaming API and send the video buffer chunk data to an HTML.
I am using rtsp URL.
The chunk logic does not work. The video only plays for 5 seconds then stops.

    


    index.js file

    


    const express = require('express');
const ffmpeg = require('fluent-ffmpeg');
const fs = require('fs');
const path = require('path');

const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.sendFile(__dirname + "/index.html");
});

const rtspUrl = 'rtsp://zephyr.rtsp.stream/movie?streamKey=64fd08123635440e7adc17ba31de2036';
const chunkDuration = 5; // Duration of each chunk in seconds


app.get('/video', (req, res) => {
  const outputDirectory = path.join(__dirname, 'chunks');
  if (!fs.existsSync(outputDirectory)) {
    fs.mkdirSync(outputDirectory);
  }

  const startTime = new Date().getTime();
  const outputFileName = `chunk_${startTime}.mp4`;
  const outputFilePath = path.join(outputDirectory, outputFileName);

  const command = ffmpeg(rtspUrl)
    .inputFormat('rtsp')
    // .inputOptions(['-rtsp_transport tcp'])
    .videoCodec('copy')
    .output(outputFilePath)
    .duration(chunkDuration)
    .on('start', () => {
      console.log(`start ${outputFileName}`);
    })
    .on('end', () => {
      console.log(`Chunk ${outputFileName} saved`);
      res.setHeader('Content-Type', 'video/mp4');
      res.sendFile(outputFilePath, (err) => {
        if (err) {
          console.error('Error sending file:', err);
        } else {
          fs.unlinkSync(outputFilePath); // Delete the chunk after it's sent
        }
      });
    })
    .on('error', (error) => {
      console.error('Error: ', error);
    });

  command.run();
});

app.listen(port, () => {
  console.log(`API server is running on port ${port}`);
});


    


    index.html

    


    &#xA;&#xA;&#xA;&#xA;  &#xA;  &#xA;  &#xA;  &#xA;&#xA;&#xA;&#xA;  <video width="50%" controls="controls" autoplay="autoplay">&#xA;    <source src="/video" type="video/mp4"></source>&#xA;    Your browser does not support the video tag.&#xA;  </video>&#xA;&#xA;&#xA;&#xA;

    &#xA;

    package.json

    &#xA;

    {&#xA;.....&#xA;  "scripts": {&#xA;    "test": "echo \"Error: no test specified\" &amp;&amp; exit 1",&#xA;    "start": "nodemon index.js"&#xA;  },&#xA;.....&#xA;}&#xA;

    &#xA;

  • ffmpeg removes audio from video instead of add audio to the video

    23 août 2023, par James

    trying to add background audio to a video in nodejs express, but instead of adding audio to the video it removes the audio from video how to fix ?

    &#xA;

    import { path as ffmpegPath } from &#x27;@ffmpeg-installer/ffmpeg&#x27;;&#xA;import ffmpeg from &#x27;fluent-ffmpeg&#x27;;&#xA;import { fileURLToPath } from &#x27;url&#x27;;&#xA;import { dirname } from &#x27;path&#x27;;&#xA;import path from &#x27;path&#x27;;&#xA;&#xA;ffmpeg.setFfmpegPath(ffmpegPath);&#xA;&#xA;const __filename = fileURLToPath(import.meta.url);&#xA;const __dirname = dirname(__filename);&#xA;&#xA;const video = path.resolve(__dirname, &#x27;video3.mp4&#x27;);&#xA;const audio = path.resolve(__dirname, &#x27;video5.mp4&#x27;);&#xA;const destination = path.resolve(__dirname, &#x27;output.mp4&#x27;);&#xA;&#xA;setTimeout(() => {&#xA;  ffmpeg()&#xA;    .input(video)&#xA;    .input(audio)&#xA;    .complexFilter([&#xA;      {&#xA;        filter: &#x27;amix&#x27;, options: { inputs: 2, duration: &#x27;longest&#x27; }&#xA;      }&#xA;    ])&#xA;    .on(&#x27;end&#x27;, async function (output) {&#xA;      console.log(output, &#x27;files have been merged and saved.&#x27;)&#xA;    })&#xA;    .saveToFile(destination)&#xA;}, 3000);&#xA;

    &#xA;

  • Rtsp streaming on nodejs - Blank screen

    17 juillet 2024, par theplaceofburak

    I am currently working on a Node.js project where I need to implement streaming using ffmpeg. However, I am facing an issue with the streaming process, as I am getting an empty blank screen instead of the expected video stream.

    &#xA;

    Here's a brief overview of what I have done so far on the server-side :

    &#xA;

    Installed ffmpeg and made sure it is accessible in the environment.&#xA;Configured the server-side code for the streaming process.&#xA;However, despite these efforts, the stream is not working correctly, and I am unable to see the video stream on the client-side.

    &#xA;

    Server-side code :&#xA;app.js

    &#xA;

    const express = require(&#x27;express&#x27;);&#xA;const Stream = require(&#x27;node-rtsp-stream&#x27;);&#xA;&#xA;const app = express();&#xA;const port = 4000;&#xA;&#xA;// Start the RTSP stream&#xA;const stream = new Stream({&#xA;  name: &#x27;rtsp_server_name&#x27;,&#xA;  streamUrl: &#x27;rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4&#x27;,&#xA;  wsPort: 3000,&#xA;  ffmpegOptions: {&#xA;    &#x27;-stats&#x27;: &#x27;&#x27;, // an option with no necessary value uses a blank string&#xA;    &#x27;-r&#x27;: 30, // options with required values specify the value after the key&#xA;  },&#xA;});&#xA;&#xA;stream.on(&#x27;data&#x27;, data => {&#xA;  console.log(data);&#xA;});&#xA;&#xA;app.get(&#x27;/&#x27;, (req, res) => {&#xA;  res.send(&#x27;Hello World&#x27;);&#xA;});&#xA;&#xA;app.listen(port, () => {&#xA;  console.log(`Server running at http://localhost:${port}/`);&#xA;});&#xA;

    &#xA;

    index.html

    &#xA;

    &#xA;  &#xA;    <canvas></canvas>&#xA;  &#xA;  <h1>Test rtsp video</h1>&#xA;  <code class="echappe-js">&lt;script type=&quot;text/javascript&quot; src='http://stackoverflow.com/feeds/tag/js/jsmpeg.min.js'&gt;&lt;/script&gt;&#xA;  &lt;script type=&quot;text/javascript&quot;&gt;&amp;#xA;    player = new JSMpeg.Player(&amp;#x27;ws://localhost:3000&amp;#x27;, {&amp;#xA;      canvas: document.getElementById(&amp;#x27;canvas&amp;#x27;), // Canvas should be a canvas DOM element&amp;#xA;    });&amp;#xA;  &lt;/script&gt;&#xA;&#xA;

    &#xA;

    I got no console error when I open index.html but only get blank black screen
    &#xA;Blank Screen

    &#xA;