Question / Help Nginx & ffmpeg setup problem

CreeCyan

New Member
Hello guys,

I've been using the awesome guide in archives about how to set up 2 computer streaming without a capture card. I've been following the steps and have managed to do most of it, I've got a stream running, showing on my encoding computer (iMac).

I've set up ffmpeg via Homebrew, it seems to be on the system, with the libx264, as far as I can see. But I'm not getting any luck with making the transcode working. Looks like the stream comes in (verified with VLC) but the transcode doesn't start. AFAIK, the exec ffmpeg command should work on Mac the same as on Linux. Or am I wrong?

My nginx.conf:

Code:
rtmp {
    server {
        listen 1935;
            chunk_size 4096;

        application transcode {
            live on;
            record off;        
            exec ffmpeg -re -i rtmp://localhost:1935/transcode/1000 -vcodec libx264 -preset veryfast -x264opts nal-hrd=cbr:force-cfr=1:keyint=120 -r 60 -b:v 9000k -maxrate 9000k -bufsize 9000k -threads 6 -s 1920x1080 -acodec copy -f flv rtmp://localhost:1935/live/1000;               
        }
        application live {
             live on;
             record off;
             push rtmp://a.rtmp.youtube.com/live2/*youtube_stream_key*;
        }
    }
}
 

Fenrir

Forum Admin
Are you setting your stream key in OBS to 1000? it's not the best idea to hardcode the ingest URL like that, you should be using something like:

Code:
rtmp://localhost:1935/$app/$name

This will ensure any active stream will be properly picked up by the ffmpeg command.

All that aside, does the ffmpeg command work when executed manually? Might give more insight into what is happening.

EDIT: Also, -re has been known to cause issues with live streams. Might want to take that out and see if it helps. I don't use it with any of my transcode commands.
 

CreeCyan

New Member
Thanks, Fenrir! I'm a true noob in this, hence me hard-coding the URLs, thinking it's necessary. I'll test it with $app/$name and report back.
Running the FFmpeg command in Terminal gives me this:

Code:
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man FFmpeg'
 
Last edited:

Fenrir

Forum Admin
Sorry, I meant the full transcode line you have :) When running from command line, you won't have the nginx variables to use, so you'll need to hardcode it to test. The link for nginx RTMP URLS is formatted like this:

rtmp://host/app-name/stream-key

So, for example, in OBS you would put rtmp://localhost/transcode as the custom URL, and then enter anything for stream key (let's call it stream1 for this example), which would be appended to the playback URL. So the full playback URL you'd use for the ffmpeg command line would be rtmp://localhost/transcode/stream1

Make sense? With the nginx variables, you can use $app and $name to handle the application name and stream key parts automatically. Useful if you ever want to stream more than once at a time!
 

CreeCyan

New Member
It works when the full transcode command is run from Terminal. With or without "-re". And the video shows up on YouTube. So for whatever reason, the command isn't executed from the nginx.conf file. Could it be that it is just how it works on Mac and I have to do a similar workaround to what is done on Win to execute the FFmpeg command?

On another note, I was in for an unpleasant surprise - the 4790K in the iMac shoots up to 80% overall usage with spikes up to 90%, four threads running very close to 100% and another four at about 70%. It struggles to encode with the settings I've provided, lags, drops frames, ghosting and artefacts show up in the final video. That's on a clean, new OSX account with nothing else but the basics installed. :(
The 5820k (OC'd to 4.3 GHz, to be fair) on my gaming PC plays the game no problem while encoding the stream at the settings iMac struggled and still runs about 60%-70% load.

That said, I've still learned a fair amount of things that could help me in the future, with a dedicated transcoding PC, built for the purpose.
 

Fenrir

Forum Admin
I'll be perfectly honest that I'm not too familiar with how things work on the macOS side. I use nginx-rtmp pretty extensively (and abuse it quite a lot!) on the linux side, so not really sure if there's any tricks to getting exec working on mac.

And yes, the encode you're trying to do is pretty harsh. 1080p 60fps at veryfast is no small task.
 

CreeCyan

New Member
Thanks, Fenrir! One day I'll just build a transcoding PC with Linux and use what I learned today. :)
For now the encode I want is running OK on my gaming PC, so I'll stick with a single PC setup for now.
 
Top