I create a m3u8 file using ffmpeg, I need to play that file, for that i used a npm package called react-hls-player but it is not playing, what the mistake i make, below is my code
I used below code to create a m3u8 file using ffmpeg in nodejs
const ffmpeg = require('fluent-ffmpeg')
const ffmpegInstaller = require('#ffmpeg-installer/ffmpeg')
ffmpeg.setFfmpegPath(ffmpegInstaller.path)
ffmpeg('uploads/malayalam.mp4').addOptions([
'-c:a',
'aac',
'-ar',
'48000',
'-b:a',
'128k',
'-c:v',
'h264',
'-profile:v',
'main',
'-crf',
'20',
'-g',
'48',
'-keyint_min',
'48',
'-sc_threshold',
'0',
'-b:v',
'2500k',
'-maxrate',
'2675k',
'-bufsize',
'3750k',
'-hls_time',
'4',
'-hls_playlist_type',
'vod',
'-hls_segment_filename',
'uploads/video/720p_%03d.ts'
]).output('uploads/video/output.m3u8').on('end',(err,data)=>{
console.log(data)
console.log('end')
}).run()
below is the screenshot of my m3u8 file directory
I used react-hls-player to play the m3u8 file my nodejs server running on port:5000
below is the reactjs code
import React from 'react'
import ReactHlsPlayer from 'react-hls-player';
function M3u8_player() {
return (
<div className="userlist">
<ReactHlsPlayer
src="http://localhost:5000/uploads/video/output.m3u8"
autoPlay={false}
controls={true}
width="100%"
height="auto"
/>
</div>
)
}
export default M3u8_player
Here i cant play the m3u8 file someone please help me , is there any mistake i made creating m3u8 file
I think the problem that you need to pass an Authentication header within the hls player
Related
Composing 3 mp4 into 1. This code below add no fade, only concatenates, but I would apply fading.
ffmpeg()
.input(`./media/001.mp4`)
.inputFormat('mp4')
.input(`/tmp/looped_video.mp4`)
.inputFormat('mp4')
.input(`./media/003.mp4`)
.inputFormat('mp4')
.noAudio()
.videoCodec('libx264')
.format('mp4')
.complexFilter([
'[0]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v0]',
'[1]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v1]',
`[2]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v2]`,
`[v0][v1][v2]concat=n=3:v=1:a=0`,
])
.outputOptions([
'-tune animation',
'-loop 1',
'-profile:v baseline',
'-level 3.0',
'-preset medium',
'-threads 4',
])
.output(`/tmp/output.mp4`)
I tried add fading like this:
.complexFilter([
'[0]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v0]',
'[1]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v1]',
`[2]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v2]`,
`[v0][v1]overlay=format=yuv420:eof_action=endall:x=0:y=0,fade=t=in:st=0:d=1,fade=t=out:st=3:d=1[v01]`,
`[v01][v2]overlay=format=yuv420:eof_action=endall:x=0:y=0,fade=t=in:st=0:d=1,fade=t=out:st=3:d=1[v02]`,
`[v0][v01][v02]concat=n=3:v=1:a=0[out]`,
])
but this raise an error:
/Users/janoskukoda/Workspace/test/node_modules/fluent-ffmpeg/lib/processor.js:182
handleExit(new Error('ffmpeg exited with code ' + code));
^
Error: ffmpeg exited with code 1: Stream specifier 'v0' in filtergraph description [0]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[2]pad=1080:1080:-1:-1,setsar=1,fps=30,format=yuv420p[v2];[v0][v1]overlay=format=yuv420:eof_action=endall:x=0:y=0,fade=t=in:st=0:d=1,fade=t=out:st=3:d=1[v01];[v01][v2]overlay=format=yuv420:eof_action=endall:x=0:y=0,fade=t=in:st=0:d=1,fade=t=out:st=3:d=1[v02];[v0][v01][v02]concat=n=3:v=1:a=0[out] matches no streams.
using this ffmpeg module:
"ffmpeg": "^0.0.4",
What is wrong?
I need to display the live streaming vidoe(rtsp) on a website(http, vue framework) with nodejs and vue framework.
I've looked it up a lot and got the basic logic of what they are and how it works.
So I'm planning on to convert rtsp to hls with nodejs using socket.io and display it on a web.(let me know if there's more efficient way way to do it)
The thing is, for some reason, when I try to develop it in my backend(nodejs), node just keep sends me an error that FFMpeg module wasn't found. It's been over a week.. please help.
Btw, all works with ffmpeg cmd(window powerShell).
How I set up(ffmpeg):
downloaded ffmpeg from https://ffmpeg.org/
added to system path: C:\Users\Marie\Desktop\ffmpeg-4.3.1-2020-11-19-full_build\bin\
tested with window powerShell and converted rstp to m3u8:
ffmpeg -i 'rtsp://ip.ip.ip/media/video1' -hls_time 3 -hls_wrap 10 'C:\Users\Marie\Desktop\tmp\hls/streaming.m3u8'
below is a screen shot of no. 3 result
how I set up(nodejs)
npm i ffmpeg fluent-ffmpeg rtsp-ffmpeg
I've just copied and pasted the example working code and changed rtsp link to mine. e.g: (https://www.npmjs.com/package/rtsp-ffmpeg)
=> didn't work out, error says can't find ffmpeg module
set up path manually e.g.) ffmpeg.setFfmpegPath(path)
=> didn't work out. error says can't find ffmpeg module
...
I've seriously tried almost everything like delete, re-install ffmpeg, changed path, added path manyally, .. Please help....
Edited:
package.json
{
"name": "streaming",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"ffmpeg": "0.0.4",
"fluent-ffmpeg": "^2.1.2",
"jsmpeg": "^1.0.0",
"node-media-server": "^2.2.4",
"node-onvif": "^0.1.7",
"node-rtsp-stream": "0.0.9",
"rtsp-ffmpeg": "0.0.15",
"socket.io": "^3.0.4",
"ws": "^7.4.1"
}
}
app.js
const Stream = require('node-rtsp-stream')
// let path = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin/ffmpeg.exe'
// let path = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin/'
let path = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin'
const ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfmpegPath(path)
stream = new Stream({
name: 'name',
streamUrl: 'rtsp://ip.ip.ip.ip/media/video1',
wsPort: 9999,
ffmpegOptions: { // options ffmpeg flags
'-stats': '', // an option with no neccessary value uses a blank string
'-r': 30 // options with required values specify the value after the key
}
})
Error: spawn ffmpeg ENOENT
app.js (for another test)
const app = require( 'express' )(),
server = require( 'http' ).Server( app ),
io = require( 'socket.io' )( server ),
rtsp = require( 'rtsp-ffmpeg' )
process.env.FFMPEG_PATH = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin/ffmpeg.exe'
// console.log( rtsp.FFMpeg )
server.listen( 6147 )
var uri = 'rtsp://ip.ip.ip.ip/media/video1',
stream = new rtsp.FFMpeg( { input: uri } )
io.on( 'connection', function ( socket )
{
var pipeStream = function ( data )
{
socket.emit( 'data', data.toString( 'base64' ) )
}
stream.on( 'data', pipeStream )
socket.on( 'disconnect', function ()
{
stream.removeListener( 'data', pipeStream )
} )
} )
app.get( '/', function ( req, res )
{
res.sendFile( __dirname + '/index.html' )
} )
error:
FMpeg executable wasn't found. Install this package and check FFMpeg.cmd property
nodejs version = 10.16.3
Turns out, this library doesn't work properly in windows. Changed to rtsp-ffmpeg and I got it work.
related git issue: https://github.com/kyriesent/node-rtsp-stream/issues/28
You have to add ffmepg.exe in your project folder to trigger ffmpeg in nodejs. This library can find the path properly in Linux/Unix. Also, many of other functions from this library doesn't work properly (maybe on windows only) so I do not suggest it to anyone who needs to develop it on window, web, and nodejs based environment.
The one I've got it work:
https://www.npmjs.com/package/rtsp-ffmpeg
I want to download the subtitle of a YouTube playlist with the following specifications:
Only in English
In srt format
Just the subtitles files and not the video itself
I have tried the following code snippet. But it is downloading the subtitles in all available languages and in vtt format.
ydl_opts = {
'allsubtitles': True,
'writesubtitles': True,
'convertsubtitles':True,
'skip_download':True,
'outtmpl': 'C:/Users/shrayani.mondal/Desktop/Personal/Python Projects/Speech to text/Subtitles/%(title)s.%(ext)s',
#'subtitlesformat': 'srt'
'subtitleslangs':'en',
'postprocessors': [{
'key': 'FFmpegSubtitlesConvertor',
'format': 'srt',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=Lp7E973zozc&list=PLQltO7RlbjPJnbfHLsFJWP-DYnWPugUZ7'])
My second objective is to use auto-generated English subtitles for videos that do not have subtitles available. How do I include the if statement for that?
# if convert vtt into srt:
# use postprocessors code snippet given below
ytdlp_option = {
"progress_hooks": [self.track_progress],
"logger": DownloadVideo.Logger(self),
"noplaylist": True,
"format": f'{self.selected_file.get(VIDEO, {}).get("format_id")}+{self.selected_file.get(AUDIO, {}).get("format_id")}',
"paths": {"home": self.video_download_path},
"outtmpl": {"default": f"{self.video_file_path}.{self.output_extension}"},
"postprocessors": [
{
"key": "FFmpegSubtitlesConvertor",
"format": "srt",
}
]
"writesubtitles": True,
"subtitlesformat": "vtt"
"subtitleslangs": ["en"],
}
you can download subtitle only use this way.
youtube-dl --write-sub --write-auto-sub --skip-download YOURLINK
Default download subtitle language is Eng.
more option have in this link or youtube-dl --help (enter link description here
default subtitle format is vtt. can you convert to srt. try with youtube-dl or simply convertor have in internet.
I'm trying to spawn a ffmpeg process to encode some audio files to hls compatible mpegts files. I need to feed the data via pipe in order to handle the live stream part. I'm using the code below to spawn my process:
var file = fs.createReadStream('./audio.mp3');
var child = spawn('ffmpeg',
['-y', '-i', 'pipe:', '-c', 'aac', '-b:a', '32k', '-hls_segment_type', 'mpegts', '-hls_time', 1, '-hls_list_size', 0, './' + req.body.uri + '_32k.m3u8'], {
env: process.env,
stdio: ['pipe', 1, 2]
}
);
file.pipe(child.stdin);
strangely I get pipe:: Permission denied from stderr of ffmpeg.
Im using node.js together with ffmpeg to receive an rtmp-stream and output this into m3u8-format.
[ '-y',
'-fflags',
'nobuffer',
'-analyzeduration',
'1000000',
'-i',
'rtmp://localhost:1935/live/ANMZJ2ZRUiMhKaAoygRXwAfHe',
'-c:v',
'copy',
'-c:a',
'aac',
'-f',
'tee',
'-map',
'0:a?',
'-map',
'0:v?',
'-y',
'-an',
'[hls_time=10:hls_list_size=0]./media/live/ANMZJ2ZRUiMhKaAoygRXwAfHe/SX3otgDdf6/index.m3u8|' ]
Together with this functionality I would also like to output a thumbnail. I tried to do this using the following format but without success.
[ '-y',
'-fflags',
'nobuffer',
'-analyzeduration',
'1000000',
'-i',
'rtmp://localhost:1935/live/ANMZJ2ZRUiMhKaAoygRXwAfHe',
'-c:v',
'copy',
'-c:a',
'aac',
'-f',
'tee',
'-map',
'0:a?',
'-map','0:v?',
'-y',
'-an',
'-vf' ,
'fps=1',
'C:/Users/media/out.png'
'[hls_time=10:hls_list_size=0]./media/live/ANMZJ2ZRUiMhKaAoygRXwAfHe/SX3otgDdf6/index.m3u8|' ]
The way I send this information to ffmpeg is by
this.ffmpeg_exec = spawn(ffmpeg_path, args);
Im unable to create a thumbnail using this approach. Does anyone know the problem/solution?
You have a log of extra arguments in the second command! You really only need the input, number of frames, and output.
[ '-i',
'rtmp://localhost:1935/live/ANMZJ2ZRUiMhKaAoygRXwAfHe',
'-frames:v',
'1',
'C:/Users/media/out.png'
]
Docs for -frames:v
https://ffmpeg.org/ffmpeg.html#Video-Options
fluent-ffmpeg support stream input and output :
var FfmpegCommand = require('fluent-ffmpeg');
var ffmpeg = FfmpegCommand();
ffmpeg.input(stream)
.seekInput("00:00:01.000")
.outputFormat("image2")
.pipe(res,{end:true});