This assumes you have a Xiaomi Ants Smart Camera that still has the open RTSP enabled. I think newer firmware might remove this capability. If you Google enough you can find instructions on how to downgrade.
FFMPEG is where most of the magic happens. I use OSX and as such am a fan of using Homebrew to install free software. Here is my ffmpeg install command:
brew install ffmpeg --with-faac --with-fdk-aac --with-ffplay --with-fontconfig --with-freetype --with-frei0r --with-libass --with-libbluray --with-libcaca --with-libquvi --with-libsoxr --with-libssh --with-libvidstab --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-webp --with-x265
It has just about every option enabled. You may want less, I added the --with-rtmpdump
option because I needed to send my stuff over RTMP. This document requires the use of RTMP.
What can one say? Nginx is probably one of the most useful pieces of software in recent years. It has available to it an RTMP module. This allows Nginx to act as a media streaming server.
I also installed this via Homebrew. Here is my command for that:
brew install nginx-full --with-gunzip --with-libressl --with-passenger --with-spdy --with-webdav --with-rtmp-module
Live streaming from a camera requires the following nginx config:
rtmp {
server {
listen 1935;
chunk_size 4000;
# Transcoding (ffmpeg needed)
application media_server {
live on;
hls on;
hls_path /usr/local/media/media_server;
hls_nested on;
hls_variant _low BANDWIDTH=640000;
hls_variant _hi BANDWIDTH=2140000;
# ffmpeg static execution
# this is using direct copy so no re-encoding is done
exec_static /usr/local/bin/ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264
-c:v copy -c:a copy -ar 44100 -f flv rtmp://127.0.0.1/media_server/live
;
}
}
}
Inside the server
block in your nginx.conf
file:
# path to HLS application service
location /media_server {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /usr/local/media;
add_header Cache-Control no-cache;
}
You can change the root
, hls_path
, and location
(and any other configuration paths) to be whatever you want, just make sure you connect all of the dots.
Also be sure to change anything labelled <camera_ip>
to be the IP address of your camera.
I'm not a fan of this method since the stream is already compressed.
ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264 -c:v libx264 -g 50 -preset fast -b:v 4096k -c:a libfdk_aac -ar 44100 -f flv
This is a straight copy over to an RTMP stream.
ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264 -c:v copy -c:a copy -ar 44100 -f flv rtmp://<rtmp.target>
Same as above but with the audio stripped out.
ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264 -c:v copy -c:a copy -an -f flv rtmp://<rtmp.target>
Just some examples I've had success with.
ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264 -c:v copy -c:a copy -ar 44100 -f flv rtmp://live-iad.twitch.tv/app/YOURTWITCHSTREAMINGKEY
ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264 -c:v copy -c:a copy -an -f flv rtmp://live-iad.twitch.tv/app/YOURTWITCHSTREAMINGKEY
ffmpeg -i rtsp://<camera_ip>:554/ch0_0.h264 -c:v copy -c:a copy -ar 44100 -f flv rtmp://<nginx_server_address>/media_server/live
Thanks to asm960 and their Ants Xiaoyi Smart Camera - How to connect via RTSP thread on the MIUI forums. Without it none of this would be possible.