live stream mosaic to twitch using nginx and ffmpeg - nginx

I've been trying to make a mosaic of two rtmp streams and resend it to Twitch, i´m using a nginx with a rtmp module and ffmpeg. I've come out with this but doesnt work:
exec /usr/bin/ffmpeg - report -i rtmp://localhost/app/input -i rtmp://localhost/app/input -filter_complex "[0:v]scale=480:-1,setsar=1[l];[1:v]scale=480:-1,setsar=1[r];[l][r]hstack;[0:a][1:a]amerge=inputs=2[a]" -map v -map "[a]" -c:v libx264 -preset veryfast -ar 44100 -f flv rtmp://live-mia.twitch.tv/app/xxxxxxxxxx
The report shows an endless loop
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
how do I get this stream working?

At last, this the code I' been able to make work
exec /usr/bin/ffmpeg - report -i rtmp://localhost/app/input -i rtmp://localhost/app/input2 -filter_complex "[0:v]scale=480:-1,setsar=1[l];[1:v]scale=480:-1,setsar=1[r];[l][r]hstack[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -c:v libx264 -preset veryfast -ac 2 -f flv rtmp://live-mia.twitch.tv/app/xxxxxxxxxx
It must be re-encoded the stream in order to Twitch been able to shown it. Also , as im runing ffmpeg in a nginx, the nginx's user must have root permissions.

Related

when i push video on RTMP nginx server ffmpeg error

when i push the video file using this command
ffmpeg -re -i "output.mkv" -c:v copy -c:a aac -ar 44100 -ac 1 -f flv rtmp://localhost/live/stream
that time showing this error
[flv # 0x5593e18e4080] Failed to update header with correct duration.
[flv # 0x5593e18e4080] Failed to update header with correct filesize.
what can i do?

How to limit bitrate for NGNIX RMTP server

We have an NGINX RMTP module installed and while testing the same we came to know that the bitrate for the output was a around 7Mbps irrespective of the input stream's bitrate and as we have a lot of people watching these streams I would like to know how to reduce the same to about 4Mbps for this module?
Also, does NGNIX's RTMP module support H.265 instead of the standard H.264 which can help set the bitrate to about 2Mbps.
You can transcode the incoming rtmp stream with ffmpeg with maxrate & b:v in this case you can control the maximum bitrate. Here is a simple example(for this example use another app show as well):
application live {
live on;
exec_push ffmpeg -i rtmp://localhost/$app/$name -async 1 -vsync -1
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2000k -maxrate 3000k -f flv -preset superfast -profile:v baseline rtmp://localhost:1935/show/$name_with_maxrate
}

Sometimes ffmpeg crashes and the process still on task manager in windows

I'm using ffmpeg for transcoding my videos on my servers.
Some times ffmpeg carshes in transode during, and that process stalled on task manager and it used ram,but not consumed cpu(it seems ffmpeg crashed).
1- Is there any solution for knowing that how can I manage this process on my servers?
2- Must be handle that from web server side or can I manage it from ffmpeg side?
I mean, ffmpeg has there any property for when transcoding take a long time,that stops.
Or Can I handle this from server side(iis recycling stops the process in run time transcoding, i don't want to use that, maybe I'm wrong, just help me).
What is the best solution ?
I used this code for example:
ffmpeg -i kata.mp4 -filter_complex
[0:v]drawtext=fontfile=OpenSansRegular.ttf:text=localhost/Parsa:fontcolor
=white:r=25:box=1:boxcolor=black#0.3:boxborderw=3:fontsize=15:x=15:y=(h-text_h-
15)[v];[v]split=4[s0][s1][s2][s3];[s0]scale=hd720[v0];[s1]scale=hd480[v1];
[s2]scale=nhd[v2];[s3]scale=cga[v3] -map [v0] -map [v1] -map [v2] -map [v3] -map
a? -c:v libx264 -c:a aac -f tee -g 48 -threads 0 "
[select='v\:0,a':f=hls:hls_list_size=0]../video/720p/out.m3u8|
[select='v\:1,a':f=hls:hls_list_size=0]../video/480p/out.m3u8|
[select='v\:2,a':f=hls:hls_list_size=0]../video/360p/out.m3u8|
[select='v\:3,a':f=hls:hls_list_size=0]../video/200p/out.m3u8"

Use FFMPEG to restream RTMP source to YouTube - no video stream in output

I am attempting to grab the .m3u8 file from an nginx-rtmp server and pass it along to YouTube rtmp. I believe this to be possible (for example here: https://stackoverflow.com/a/11978820/1552594 although this is on the same host). The command I am using is:
ffmpeg -analyzeduration 0 -i \
http://source.rtmp.server/hls/stream.m3u8 -pix_fmt yuv420p \
-f flv rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx
However the output contains only audio and YouTube doesn't like it. The command produces following:
As you can see no Video stream in output metadata, stream mapping shows only audio and the trace shows 0kb of Video for 651kb of Audio
Any help much appreciated
MORE INFO
Improved version of the command lifted from this article:
https://judge2020.com/restreaming-a-m3u8-hls-stream-to-youtube-using-ffmpeg/
"Restreaming a m3u8 HLS stream to Youtube using FFMPEG" AKA exactly what I am trying to do.
The command I am sending is now:
ffmpeg -re -i "http://source.rtmp.server/hls/stream.m3u8" \
-strict -2 -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -flags \
+global_header -bsf:a aac_adtstoasc -bufsize 3000k -f flv \
"rtmp://a.rtmp.youtube.com/live2/xxx-xxxx-xxxx-xxxx"
I got pretty much exactly the same response except with the Audio being read and output using aac codec.
MORE MORE INFO
I have found that adding a mapping can force the video stream into the output:
ffmpeg -re -i "http://source.rtmp.server/hls/stream.m3u8" \
-strict -2 -c:v copy -c:a -map 0:0 -map 0:1 -ar 44100 -ab 128k -ac 2 \
-flags +global_header -bsf:a aac_adtstoasc -bufsize 1000k \
-f flv "rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx"
This throws up the error that has presumably been resulting in the video stream being silently dropped:
Finally worked it out. The last issue above was a red herring and was due to missing a codec argument for the audio -c:a.
The complete working command is as follows:
ffmpeg -probesize 100M -analyzeduration 20M -re \
-i "http://source.rtmp.server/hls/stream.m3u8" -strict -2 -c:v \
libx264 -pix_fmt yuv420p -c:a aac -map 0:0 -map 0:1 -ar 44100 \
-ab 128k -ac 2 -b:v 2567k -flags +global_header -bsf:a aac_adtstoasc \
-bufsize 1000k -f flv "rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx"
The important parts are -probesize and -analyeduration - these need tweaking until they work. The -re flag is important to indicate restreaming. The various video codec declarations are also important - -c:v libx264 -pix_fmt yuv420p or it will throw errors about the output size being 0x0. Finally the map flags ensure that both streams are included in the output: -map 0:0 -map 0:1

Detect Live streaming stopped and resume in nginx

I'm trying to use Nginx to do live stream to combine two stream into one, so I need to spawn FFMpeg, like so
ffmpeg -i "rtmp://in/1" -i "rtmp://in/2" -filter_complex "overlay=70:50" -vcodec libx264 -preset ultrafast -f flv rtmp://out
However, is there a way to detect if one of the incoming stream drops, and I can continue the stream? From what I'm reading, it is not possible, and ffmpeg task will be killed.

Resources