Sometimes HLS chunks does not generate in /tmp/hls directory - nginx

I am working on an adaptive HLS solution using Nginx RTMP module as a streaming server and VideoJs as a client. I have completed the setup i.e. NGINX configurations and client sample in VideoJs.
NGINX Configurations:
nginx.txt
I am using this Ffmpeg command to generate stream:
ffmpeg -re -i /home/user/Downloads/test.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://192.168.1.68/live
My problem is that sometimes the Nginx does not generate .ts and .m3u8 files in /tmp/hls directory when I issue the above ffmpeg command. I have also enabled the nginx-rtmp module logs but they are only giving me access information and I am not getting any logs in error logs.
Do let me know if more information is required. Any help will be appreciated.
Thanks,

Related

RTMP proxy to crop original video and send it to another RTMP server

I need to crop the video from an RTMP stream and send it to another RTMP server which always change. My understanding is that I should use nginx-proxy and ffmpeg, can anybody help me on how to set it up?
I suppose that i need to send the stream to an endpoint like /stream/:stream-key/:next-server-ip process the stream with ffmpeg and then send it to the :next-server-ip, what language should I use in the backend for this?
There are 2 strategies for processing such task:
"Pull"
You have some published rtmp stream and use ffmpeg to pull it, convert and send result to another server:
ffmpeg -i rtmp://source-server/stream -filter:v "crop=out_w:out_h:x:y" -vcodec h264 -acodec copy -f flv rtmp://next-server/stream
"Push"
RTMP stream is pushed to your server which processes it and sends result to another server. For such task you can use nginx-rtmp module for nginx and setup ffmpeg command using exec_push directive:
application src {
live on;
exec_push ffmpeg -i rtmp://localhost/src/$name -filter:v "crop=out_w:out_h:x:y" -vcodec h264 -acodec copy -f flv rtmp://next-server/stream 2>>/var/log/ffmpeg-$name.log;
}
When someone start to stream to rtmp://your-server/src/stream_name this ffmpeg command will be executed and the processing will begin
For additional information about video cropping and related ffmpeg parameters see https://video.stackexchange.com/a/4571

how to play nginx & rtmp based hls live stream on a remote machine

I have installed nginx, rtmp and ffmpeg based hls live streaming working on ubuntu machine. I use this command to stream hls
sudo ffmpeg -re -i sample.mp4 -vcodec libx264 -vprofile high -g 30 -acodec aac -strict -2 -f flv rtmp://localhost/show/stream2
when I try to play this stream using VLC using following commands on the same machine it works well.
http://myIp:8080/hls/stream2.m3u8
or
http://localhost:8080/hls/stream2.m3u8
However when I try to access from remote computer connected to same WIFI, not able to play. VLC gives an error that unable to play the file.
Solution to this problem has to be in two places
1. open ports in ufw
2. enable pings in home router

ffmpeg transcode to youtube live bad video container

I've been attempting to transcode a stream produced by obs studio to my nginx server and send it off to youtube. Now I've made it work with twitch and I know these settings are actually transcoding it mostly correctly and is viewable. The problem being that youtube live picks it up as Bad video settings and tells me to change the current video container format. The other side effect that is probly unrelated is the stream looks really poorly on youtube. Looks like it was streamed at a poor bitrate and stuff but the real problem is the bad video settings error.
The ffmpeg command being used is as follows
ffmpeg -i rtmp://localhost/Private/Private1 -vb 6000k -minrate 6000k -maxrate 6000k -bufsize 6000k -s 1280x720 -c:v libx264 -preset faster -r 50 -g 100 -keyint_min 50 -x264opts nal-hrd=cbr:force-cfr=1 -sws_flags lanczos -tune film -pix_fmt yuv420p -c:a copy -f flv -threads 6 -strict normal rtmp://a.rtmp.youtube.com/live2/{key}
I've tried with different framerates and been googling for awhile and found nothing or interpreted everything wrongly. Either way I would be very happy for some help here.
System info.
OS: Ubuntu Server 16.04 LTS
Ram: 10gb
Processor: AMD Phenom(tm) II X6 1090T
GPU: Geforce GT 520
Internet.
Upload 15mbit
Download 150mbit
If you need any more info I will gladly send it. Thanks for reading.
Edit 1
After some googling about what I'm doing wrong I decided to try and change stuff slightly and came up with this command
ffmpeg -re -i rtmp://localhost/(app)/(key) -c:v libx264 -r 50 -g 100 -keyint_min 100 -x264opts "keyint=100:min-keyint=100:no-scenecut" -sws_flags lanczos -profile:v baseline -preset veryfast -vb 6000K -minrate 6000k -maxrate 6000k -bufsize 6000k -s 1280x720 -tune film,zerolatency -pix_fmt yuv420p -f flv -c:a copy -ac 1 -strict normal rtmp://(output site)/(output app)/(output key)
which as of my current testing seems to at least have a healthy stream for longer than 2 minutes if i only output to youtube live directly. Ive found output to my nginx server then youtube live breaks things.
my nginx rtmp settings are on this link https://pastebin.com/siE99Tv8
Edit 2
If I push the stream to a site like restream to stream it to youtube then it seems to be working. tested for 25 minutes with no change of them saying bad video container or anything. So I'm going to say nginx is partly to blame in how its distributing the files? Unsure what I'm doing wrong. I am pretty sure ffmpeg isn't to blame here at least
Seems YouTube does not like nginx. I found two solutions for this.
Solution 1
Add "meta copy;" to you nginx config as follow:
rtmp {
server {
listen 1935;
application youtube{
live on;
meta copy;
push rtmp://a.rtmp.youtube.com/live2/(key);
}
}
}
Solution 2
Modify nginx-rtmp-module/ngx_rtmp_codec_module.c and replace the line:
ngx_string("Server"),
with
ngx_string("xtradata"),
then recompile nginx.

Transcode H264 stream into mpeg2 with ffmpeg and nginx-rtmp module

I am using nginix web server and nginx-rtmp module for managing my video stream encoded in h264. Here is my nginx conf:
rtmp {
server {
listen 1935;
application big {
live on;
exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec
libx264 -vprofile baseline -acodec libvo_aacenc -ac 1 -ar 441000
-f flv rtmp://localhost:1935/hls/${name};
}
}
application hls
{
live on;
hls_path /usr/local/nginx/html/video;
}
}
it works well in browser, however because my mobile client is Adobe Air it would only work on Android but not Apple, because Apple doesn't support H264 encoding through AIR applications, so I was trying to transcode the stream to something supported for example mpeg. And this is how I changed my ffmpeg:
exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec
mpeg2video -acodec copy -b:v 10M -b:a 128k
-f mpegts rtmp://localhost:1935/hls/${name};
However it just won't show the video not in a browser nor on device, my assumption is that it probably failed to transcode.
Maybe I am missing something ? Any ideas are highly appreciated.
Thank you.
You probably got your answer already, but just in case:
You are not using the module properly,
1) On iOS you need to point your browser to http://localhost:80/hls/${name} to get the HLS stream.
2) You are missing in the config the http section to generate the HLS stream
See here for details: How can we transcode live rtmp stream to live hls stream using ffmpeg?

capture RTSP stream and forward to RTMP

I am trying to tunnel RTSP h264 encoded data to nginx RTMP server witth ffmpeg, but its not working
my cmd line:
ffmpeg -y -i rtsp://192.168.1.84:6880/test.264 -c:v copy -an -map 0:0 -f mp4 -rtmp_buffer 100 -rtmp_live live rtmp://localhost/live/streamNam
VLC is able to decode rtsp://192.168.1.84:6880/test.264 fine.. Are there any additional options I can forward to ffmpeg for simple tunneling operation? Right now it stalls for a good amount of time doing probing - how to get rid of that too?

Resources