
Recherche avancée
Médias (1)
-
Revolution of Open-source and film making towards open film making
6 octobre 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Sur d’autres sites (2478)
-
How to live video stream using node API(Read file with chunk logic)
28 septembre 2023, par Mukesh Singh ThakurI 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






 
 
 
 



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






package.json


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



-
ffmpeg removes audio from video instead of add audio to the video
23 août 2023, par Jamestrying 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 ?


import { path as ffmpegPath } from '@ffmpeg-installer/ffmpeg';
import ffmpeg from 'fluent-ffmpeg';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import path from 'path';

ffmpeg.setFfmpegPath(ffmpegPath);

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const video = path.resolve(__dirname, 'video3.mp4');
const audio = path.resolve(__dirname, 'video5.mp4');
const destination = path.resolve(__dirname, 'output.mp4');

setTimeout(() => {
 ffmpeg()
 .input(video)
 .input(audio)
 .complexFilter([
 {
 filter: 'amix', options: { inputs: 2, duration: 'longest' }
 }
 ])
 .on('end', async function (output) {
 console.log(output, 'files have been merged and saved.')
 })
 .saveToFile(destination)
}, 3000);



-
Rtsp streaming on nodejs - Blank screen
17 juillet 2024, par theplaceofburakI 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.


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


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


Server-side code :
app.js


const express = require('express');
const Stream = require('node-rtsp-stream');

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

// Start the RTSP stream
const stream = new Stream({
 name: 'rtsp_server_name',
 streamUrl: 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4',
 wsPort: 3000,
 ffmpegOptions: {
 '-stats': '', // an option with no necessary value uses a blank string
 '-r': 30, // options with required values specify the value after the key
 },
});

stream.on('data', data => {
 console.log(data);
});

app.get('/', (req, res) => {
 res.send('Hello World');
});

app.listen(port, () => {
 console.log(`Server running at http://localhost:${port}/`);
});



index.html



 
 <canvas></canvas>
 
 <h1>Test rtsp video</h1>
 <code class="echappe-js"><script type="text/javascript" src='http://stackoverflow.com/feeds/tag/js/jsmpeg.min.js'></script>

<script type="text/javascript">&#xA; player = new JSMpeg.Player(&#x27;ws://localhost:3000&#x27;, {&#xA; canvas: document.getElementById(&#x27;canvas&#x27;), // Canvas should be a canvas DOM element&#xA; });&#xA; </script>




I got no console error when I open index.html but only get blank black screen