I have to make a semi-live-stream. I used Nginx-rtmp module and then pushed content to it via ffmpeg using:
ffmpeg -re -i content.mp4 -r 25 -f fvl \"rtmp://rtmp.
Your input video uses H.264
with a high
profile.
If you want compatibility with both iOS and Android you must use the baseline
profile. Newer iPhones support the main
and high
profiles but the Android documentation only mentions baseline
:
-c:v libx264 -profile baseline
Don't use the native aac
as audio codec, use libfdk_aac
since it's the highest quality encoder available for FFmpeg and it will help you produce a valid AAC stream:
-c:a libfdk_aac
Make sure the audio rate is suported. The FLV
video format only supports sample rates of 11025, 22050, and 44100.
-ar 44100
The ffprobe
shows an unsupported stream Stream #0:1: Data: none
. Use map
to skip it:
-map 0:0 -map 0:2
(MPEG-TS only) If you use a .ts
file as input make sure to remove the AAC ADTS header:
-bsf:a aac_adtstoasc
Eg:
ffmpeg -re -i content.mp4 -map 0:0 -map 0:2 -c:v libx264 -vprofile baseline -preset ultrafast -tune zerolatency -r 25 -pix_fmt yuv420p -c:a libfdk_aac -ac 2 -ar 44100 -f flv rtmp://...
First, I suggest you add more details about the file (ffprobe
) so it could be compared with the server output.
Alternatively, be more strict in your ffmpeg
command and set a specific output.
That's a command I use to push RTMP to YouTube:
ffmpeg -i any_file.mp4 -strict experimental -acodec aac -ac 1 -ar 44100 -vcodec libx264 -pix_fmt yuv420p -g 30 -vb 512k -profile:v main -preset ultrafast -r 30 -f flv -s 854x480 rtmp://a.rtmp.youtube.com/live2/your-channel.stream_code
With you last update, there already is a difference between ffmpeg
output and the server's: ffmpeg
creates a 25fps stream while ffprobe
sees a 20fps stream.
Is there a place in the server you set other output parameters? try setting the ffmpeg
output accordingly.
See if changing the ffmpeg
output affects the server output, and try go with h264 main profile.
Regarding the ffprobe
error message, if your original file also contains 3 streams, perhaps the server doesn't like it so remove that 'Data' stream using map
like this:
ffmpeg -i content.mp4 -map 0:0 -map 0:2 ...
RTMP protocol usage is very limited and primarily being used for video recording. There is no reason to use it for playback as mobile devices don't support RTMP natively, you don't think it can be a good idea to advice mobile users to install VLC or similar app on the device?
Plugin nginx-rtmp-module has been incorporated to Nginx+ to make a comprehensive recording media server out of Nginx as a replacement to Wowza Media Server or implement HLS for playaback via HTTP. This plugin can be used with Nginx open source edition.
To make your video content available to mobile devices you have only 2 options, each of them work via HTTP(s), not RTMP:
HTTP Live Streaming, see the example:
location / {
hls;
hls_fragment 5s;
hls_buffers 10 10m;
hls_mp4_buffer_size 1m;
hls_mp4_max_buffer_size 5m;
root /var/video/;
}
HTTP pseudo streaming, see the example
location /video/ {
mp4;
mp4_buffer_size 1m;
mp4_max_buffer_size 5m;
mp4_limit_rate on;
mp4_limit_rate_after 30s;
}
The other side is security. How to protect the video streaming URL? Pre-generated time-expired URLs is good approach, you can try, see my example there.