
Recherche avancée
Autres articles (53)
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Ecrire une actualité
21 juin 2013, parPrésentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
Vous pouvez personnaliser le formulaire de création d’une actualité.
Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)
Sur d’autres sites (7780)
-
Overlaying a text stream on a video stream with ffmpeg in Node.js
16 mai 2023, par TchouneI am creating a streaming system with Node.js that uses ffmpeg to send video and text streams to a local RTMP server, then combines those streams and sends them to Twitch.


I'm using canvas to create a text image with a transparent background, and I need to change that text every time a new video in the playlist starts.


Currently in stream I see only the video stream of my video and not the text. But if I go via VLC to see each more separate, I see them


However, I'm running into a problem where the text stream doesn't appear in the final video stream on Twitch. In addition, I get the following error message :


Combine stderr: [NULL @ 0x1407069f0] Unable to find a suitable output format for 'rtmp://live.twitch.tv/app/streamKey'
rtmp://live.twitch.tv/app/streamKey: Invalid argument



Here is my current Node.js code :



const createTextImage = (runner) => {
 return new Promise((resolve, reject) => {
 const canvas = createCanvas(1920, 1080);
 const context = canvas.getContext('2d');

 // Fill the background with transparency
 context.fillStyle = 'rgba(0,0,0,0)';
 context.fillRect(0, 0, canvas.width, canvas.height);

 // Set the text options
 context.fillStyle = '#ffffff';
 context.font = '24px Arial';
 context.textAlign = 'start';
 context.textBaseline = 'middle';

 // Draw the text
 context.fillText(`Speedrun by ${runner}`, canvas.width / 2, canvas.height / 2);

 // Define the images directory
 const imagesDir = path.join(__dirname, 'images', 'runners');

 // Ensure the images directory exists
 fs.mkdirSync(imagesDir, { recursive: true });

 // Define the file path
 const filePath = path.join(imagesDir, runner + '.png');

 // Create the write stream
 const out = fs.createWriteStream(filePath);

 // Create the PNG stream
 const stream = canvas.createPNGStream();

 // Pipe the PNG stream to the write stream
 stream.pipe(out);

 out.on('finish', () => {
 console.log('The PNG file was created.');
 resolve();
 });

 out.on('error', reject);
 });
}
const streamVideo = (video) => {
 ffmpegLibrary.ffprobe(video.video, function (err, metadata) {
 if (err) {
 console.error(err);
 return;
 }
 currentVideoDuration = metadata.format.duration;

 // Annulez le délai précédent avant d'en créer un nouveau
 if (nextVideoTimeoutId) {
 clearTimeout(nextVideoTimeoutId);
 }

 // Déplacez votre appel setTimeout ici
 nextVideoTimeoutId = setTimeout(() => {
 console.log('Fin de la vidéo, passage à la suivante...');
 nextVideo();
 }, currentVideoDuration * 1000 + 10000);
 })


 ffmpegVideo = childProcess.spawn('ffmpeg', [
 '-nostdin', '-re', '-f', 'concat', '-safe', '0', '-i', 'playlist.txt',
 '-vcodec', 'libx264',
 '-s', '1920x1080',
 '-r', '30',
 '-b:v', '5000k',
 '-acodec', 'aac',
 '-preset', 'veryfast',
 '-f', 'flv',
 `rtmp://localhost:1935/live/video` // envoie le flux vidéo au serveur rtmp local
 ]);

 createTextImage(video.runner).then(() => {
 ffmpegText = childProcess.spawn('ffmpeg', [
 '-nostdin', '-re',
 '-loop', '1', '-i', `images/runners/${video.runner}.png`, // Utilise l'image créée par Puppeteer
 '-vcodec', 'libx264rgb', // Utilise le codec PNG pour conserver la transparence
 '-s', '1920x1080',
 '-r', '30',
 '-b:v', '5000k',
 '-acodec', 'aac',
 '-preset', 'veryfast',
 '-f', 'flv',
 `rtmp://localhost:1935/live/text` // envoie le flux de texte au serveur rtmp local
 ]);

 ffmpegText.stdout.on('data', (data) => {
 console.log(`text stdout: ${data}`);
 });

 ffmpegText.stderr.on('data', (data) => {
 console.error(`text stderr: ${data}`);
 });
 }).catch(error => {
 console.error(`Erreur lors de la création de l'image de texte: ${error}`);
 });

 ffmpegCombine = childProcess.spawn('ffmpeg', [
 '-i', 'rtmp://localhost:1935/live/video',
 '-i', 'rtmp://localhost:1935/live/text',
 '-filter_complex', '[0:v][1:v]overlay=main_w-overlay_w:0',
 '-s', '1920x1080',
 '-r', '30',
 '-vcodec', 'libx264',
 '-b:v', '5000k',
 '-acodec', 'aac',
 '-preset', 'veryfast',
 '-f', 'flv',
 `rtmp://live.twitch.tv/app/${twitchStreamKey}` // envoie le flux combiné à Twitch
 ]);

 ffmpegVideo.stdout.on('data', (data) => {
 console.log(`video stdout: ${data}`);
 });

 ffmpegVideo.stderr.on('data', (data) => {
 console.error(`video stderr: ${data}`);
 });

 ffmpegCombine.stdout.on('data', (data) => {
 console.log(`Combine stdout: ${data}`);
 });

 ffmpegCombine.stderr.on('data', (data) => {
 console.error(`Combine stderr: ${data}`);
 });

 ffmpegCombine.on('close', (code) => {
 console.log(`ffmpeg exited with code ${code}`);
 if (currentIndex >= playlist.length) {
 console.log('End of playlist');
 currentIndex = 0;
 }
 });
}




Locally I use nginx with rtmp module to manage multi-streams and combined into one to send to twitch


In NGINX it's my nginx.conf for module :


rtmp {
 server {
 listen 1935; # le port pour le protocole RTMP
 
 application live {
 live on; # active le streaming en direct
 record off; # désactive l'enregistrement du flux
 
 # définit l'endroit où les flux doivent être envoyés
 push rtmp://live.twitch.tv/app/liveKey;
 }
 
 application text {
 live on; # active le streaming en direct
 record off; # désactive l'enregistrement du flux
 }
 }
}



I have checked that the codecs, resolution and frame rate are the same for both streams. I am also overlaying the text stream on top of the video stream with the -filter_complex command, but I am not sure if it works correctly.


Does each stream have to have the same parameters ?


I would like to know if anyone has any idea what could be causing this problem and how to fix it. Should I use a different format for the output stream to Twitch ? Or is there another approach I should consider for layering a dynamic text stream over a video stream ?


Also, I'm wondering if I'm handling updating the text stream correctly when the video changes. Currently, I create a new text image with Canvas every time the video changes, then create a new ffmpeg process for the text stream. Is this the right approach, or is there a better way to handle this ?


Thanks in advance for any help or advice.


-
Convert wma stream to mp3 stream with C# and ffmpeg
24 septembre 2012, par user1363468Is it possible to convert a wma stream to an mp3 stream real time ?
I have tried doing something like this but not having any luck :
WebRequest request = WebRequest.Create(wmaUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
int block = 32768;
byte[] buffer = new byte[block];
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.ErrorDialog = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "c:\\ffmpeg.exe";
p.StartInfo.Arguments = "-i - -y -vn -acodec libspeex -ac 1 -ar 16000 -f mp3 ";
StringBuilder output = new StringBuilder();
p.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
{
output.AppendLine(e.Data);
//eventually replace this with response.write code for a web request
}
};
p.Start();
StreamWriter ffmpegInput = p.StandardInput;
p.BeginOutputReadLine();
using (Stream dataStream = response.GetResponseStream())
{
int read = dataStream.Read(buffer, 0, block);
while (read > 0)
{
ffmpegInput.Write(buffer);
ffmpegInput.Flush();
read = dataStream.Read(buffer, 0, block);
}
}
ffmpegInput.Close();
var getErrors = p.StandardError.ReadToEnd();Just wondering if what I am trying to do is even possible (Convert byte blocks of wma to byte blocks of mp3). Open to any other possible C# solutions if they exist.
Thanks
-
Test if YouTube stream key is still active
17 avril 2022, par codingmaster398I'm making a service to stream to YouTube, simply put.


If the live stream ends or the stream key is no longer being used, we need to know. So far, it plays a short 3 second clip every once in a while, and if FFMpeg stops before it streams, we assume that the stream key is invalid. However, once we start a stream with the correct stream key, then end it and reset the stream key in another stream, the stream key still is being picked up as active.


Is there any API to see if the stream key is still being used ?