ffmpeg transcode to youtube live bad video container - nginx

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.

Related

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
}

NGinx RTMP live stream text overlay and push to multiple

I have been banging my head against this wall for a long time. Hoping you all can get me over.
I have a live stream coming from an IP Camera to my computer.
Nginx publishes to YouTube and to an FFmpeg stream that takes a frame every minute to use for a static webcam image.
Here is the code with the exec_push that I've tried to use with no success. The YouTube stream and frame capture work fine. I have FFmpeg installed with freetype. This is all on MacOS X 10.15.4 Catalina with home-brew FFmpeg --HEAD installed.
Update: I should also say I have tried outputting the overlay using command line FFmpeg and it works great with this command:
/usr/local/bin/ffmpeg -i rtmp://localhost:1935/live/68.1. -vf drawtext="fontfile=/System/Library/Fonts/Supplemental/Arial.ttf:text='Stack Overflow': fontcolor=white: fontsize=24: box=1: boxcolor=black#0.5: boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2" /Users/user/Desktop/test.mp4
So it seems that the output portion is the part FFmpeg doesn't like in Nginx.conf
My thought is I should be passing the overlayed FFmpeg stream to the "overlay" app and have the stream published to Youtube and the frame capture from there. (And also potentially recorded).
Update: When I have tried point to a sh file to run the command rather than the direct FFmpeg exec_push I get:
[alert] 56849#0: kevent() error on 15 filter:-1 flags:4002 (2: No such file or directory)
Thanks so much!
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
exec_push /usr/local/bin/ffmpeg -i rtmp://localhost:1935/live/68.1. -vf drawtext="fontfile=/System/Library/Fonts/Supplemental/Arial.ttf:textfile=/Users/Shared/overlayescaped.txt: reload=1: fontcolor=white: fontsize=20: box=1: boxcolor=black#1: boxborderw=75: x=70: y=925" -c:v libx264 -maxrate 6000k -bufsize 4000k -c:a aac -b:a 160k -ar 44100 -b:a 128k -f mp4 rtmp://localhost:1935/overlay/test;
#push rtmp://localhost:1935/overlay;
}
application overlay {
live on;
record off;
push rtmp://a.rtmp.youtube.com app=live2 playpath=yourstreamkey;
exec_push /usr/local/bin/ffmpeg -i rtmp://localhost:1935/overlay/$name -vf fps=1/60 /Users/Shared/stream/netcam.jpg;
}
}
}
The answer was:
a) I must invoke the Ffmpeg command through a file for this to work. I'm not entirely sure why, but that is just the way it is.
b) I wasn't able before to get logging info from Ffmpeg. It was because I was logging to the wrong spot. I needed to log to /tmp/ because of the unprivileged (nobody) user used by Nginx. Makes sense.
c) At that point once the command was working from a file, I could see the actual errors that Ffmpeg was throwing and could troubleshoot them. Which had a lot to do with option placement, spacing, and ensuring it is a flv container, not an mp4 container.
Here is the Nginx rtmp configuration I ended up with:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
meta copy;
exec /Users/Shared/ffmpegcommand.sh $name;
}
application overlay {
live on;
record off;
meta copy;
push rtmp://a.rtmp.youtube.com app=live2 playpath=stream-key;
exec_push /usr/local/bin/ffmpeg -i rtmp://localhost:1935/overlay/$name -vf fps=1/60 /Users/Shared/stream/netcam.jpg;
}
}
}
And here is the Ffmpeg command I am using in the command file for the text overlay (now using -filter_complex, as -vf wasn't the proper option in this case).
/usr/local/bin/ffmpeg -i rtmp://localhost:1935/live/68.1. -filter_complex drawtext="fontfile=/System/Library/Fonts/Supplemental/Verdana.ttf: textfile=/Users/Shared/overlayescaped.txt: reload=1: fontcolor=white: fontsize=17: box=1: boxcolor=black#1: boxborderw=80: x=80: y=935" -c:v libx264 -level 4.1 -maxrate 6000k -bufsize 4000k -c:a copy -f flv rtmp://localhost:1935/overlay/newlive 2>>/tmp/ffmpeg.error
I also modified the audio options so that they copy straight from source as no encoding is needed.
Finally, I created the overlay text file from a text file I already had. The existing overlay had a % symbol for humidity so I had to escape that character using sed in a bash script.
escovlfiletmp='/Users/Shared/overlayescapedtmp.txt'
escovlfile='/Users/Shared/overlayescaped.txt'
overlaysearch="% B:"
overlayreplace="\\\\\\% B:"
sed -e "s/${overlaysearch}/${overlayreplace}/g" ${overlayfile} > ${escovlfile}
I've attached a screen cap of the final video stream result. The entire black area is the overlay.
Very happy.
Thank you for all the resources on this website and elsewhere. It took me 4 days and many hours of constant searching but managed to piece it all together.
enter image description here

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

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,

Record not working (permission checked)

I've been struggling to get recording working with nginx-rtmp module. The folder for the recording has broad permissions (777), I tried both manual via control endpoint or automatic recording. Nothing seems to work.
application stream {
live on;
record all;
record_suffix .flv;
record_path /tmp/recordings;
record_unique on;
exec ffmpeg -i rtmp://localhost:1935/stream/$name
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs;
}
RTMP streaming is working, I also have HLS working fine, but nothing gets written to the /tmp/recordings folder.
Nothing on the error logs.
The source can be found here: https://github.com/viniciusccarvalho/docker-nginx-rtmp-1
Configuration:
Nginx 1.12.0 (compiled from source )
nginx-rtmp-module 1.1.11 (compiled from source)
ffmpeg 3.3.2 (compiled from source)
Any ideas?

re-stream other stream with niginx software

Goodday everybody,
I have question about Nginx streaming software and the resteaming from other streams.
I wanne restream another stream (third party) with nginx because this way I wanne create so called thumbs from the (third party) stream and stream it on my own site .
The thumbs part is what I all know , the part of the restream is the unkown part for me .
Long story short now .
1. The stream link what I like restream is
http://154.57.145.83/flv/5285079c2c9e5/testat123.flv
As out going stream on my site I wanne have it like :
rtmp://145.44.194.308:1935/myapp/flv:test.flv
I have found this like on stackoverflow as well but it haven't help me out so far . (How to restream an udp live stream using nginx rtmp module?)
This is my code what I have used and dont seems to work .
exec_pull ffmpeg -i
http://154.57.145.83/flv/5285079c2c9e5/testat123.flv -c:v libx264 -c:a
libfaac -ar 44100 -ac 2 -f flv rtmp://145.44.194.308:1935/myapp/test;
So I hope someone here can help me out because I think other people will like to do same thing as well
Greatings and have yourself an great day
I have found the anwers for someone that wanne use it as well
exec_pull ffmpeg -re -i
http://154.57.145.83/flv/5285079c2c9e5/testat123.flv -c:a libmp3lame
-ar 44100 -ac 1 -f flv rtmp://415.493.196.188:1935/myapp/test 2>>/tmp/log/ffmpeg.log;

Resources