when i push video on RTMP nginx server ffmpeg error - nginx

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?

Related

nginx live adaptive bitrate streaming:- not able to switch quality manuallly?

I am using Nginx for live adaptive bitrate streaming. My live streaming is working fine.
Also, the chunks are getting created and the master playlist is also getting created as you can see in this image.
My config
application live {
live on; # Allows live input
exec_push /usr/bin/ffmpeg -i rtmp://localhost:1935/$app/$name
-force_key_frames "expr:gte(t,n_forced*3)" -c:v libx264 -vprofile baseline -vlevel 3.1 -s 640x360 -b:v 1200k -strict -2 -c:a aac -ar 44100 -ac 2 -b:a 96k -f flv rtmp://localhost/show/$name_hi
-force_key_frames "expr:gte(t,n_forced*3)" -c:v libx264 -vprofile baseline -vlevel 3.1 -s 240x360 -b:v 1200k -strict -2 -c:a aac -ar 44100 -ac 2 -b:a 96k -f flv rtmp://localhost/show/$name_low;
}
This is my master playlist
This is my each playlist m3u8 file
But when I point the master playlist to the videojs (hlsjs) added it is showing the quality
auto
undefinedp
But when I use some other test stream from online then it is showing me all available quality
using my live stream generated using nginx ffmpeg
using other live stream
You need to add the RESOLUTION attribute to your master playlist in the EXT-X-STREAM-INF tag. This is optional in https://www.rfc-editor.org/rfc/rfc8216#section-4.3.4.2 but it's required by the quality selector UI plugin.
See: https://github.com/chrisboustead/videojs-hls-quality-selector/issues/8
Nginx RTMP module config example:
hls_variant <variant_name> BANDWIDTH=<bandwidth>,RESOLUTION=<resolution>;

End FFMPEG execution when RTMP input is closed

I have an RTMP arut server inside which I call a python script to run an FFMPEG command and create HLS packaging.
Problem is that when I stop the RTMP stream, FFMPEG still run processes in background.
FFMPEG string is like this:
ffmpeg -re -v verbose -i rtmp://localhost:1935/live/testlive -rw_timeout 500 -http_persistent 1 -method PUT -http_user_agent test -f hls -hls_list_size 5 -hls_flags discont_start+delete_segments -vf "scale=426:trunc(ow/a/2)*2" -c:a libfdk_aac -ar 48000 -c:v h264 -profile:v main -crf 24 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type event -preset veryfast -b:v 300k -maxrate 856k -bufsize 1200k -b:a 128k -vcodec libx264 -hls_segment_filename http://mystream/123/v1/testlive/0_%03d.ts http://mystream/123/v1/testlive/index.m3u8
The RTMP server should send an NetStream.Play.Stop event to subscribers (or disconnect them) to signal end of stream. If you are using the nginx rtmp module, look at the play_restart or idle_streams directives.

live stream mosaic to twitch using nginx and ffmpeg

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.

Can't livestream with FFmpeg on Nginx?

I am trying to livestream through RTMP on FFmpeg in Nginx. Doing sudo ffmpeg -re -f video4linux2 -i test.mp4 -vcodec libx264 -vprofile baseline -acodec aac -strict -2 -f flv rtmp://localhost/show/stream gives me ioctl(VIDIOC_QUERYCAP): Inappropriate ioctl for device
test.mp4: Inappropriate ioctl for device
Am I even doing this right?

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

Resources