The goal is to send RTMP stream from an action camera (or any RTMP feed really) to the server running on Android phone and use that as a source for a video encoder (running on the same Android phone) to stream it as SRT HEVC.
To achieve this we need a server that can run on Android and a video encoder.
We'll be using MediaMTX as a server (running in Termux).
IRL Pro
is a great video encoder app. It can stream SRT HEVC with dynamic bitrate and bonding. Unfortunately, it cannot use audio from an RTMP stream, but it can use audio from a phone audio input or a Bluetooth mic connected to the phone.
Another option is to use ffmpeg
in Termux. It can do SRT HEVC with no dynamic bitrate and no bonding. It uses audio from RTMP stream.
MediaMTX will be running in Termux. Install Termux on your phone. Do not use Google Play version.
Start Termux and copy-paste or type the commands below.
To copy commands open this page in the browser of your the phone and tap on commands.
To paste into Termux long tap anywhere on Termux terminal view to bring up context menu and choose Paste
.
If at any time you need a new terminal swipe from the left edge of screen and select New session
button.
Install wget
to allow downloading MediaMTX.
pkg install wget
We need to grab linux_arm64v8
version from one of MediaMTX releases.
(Your phone can have a different architecture, but try this first.)
wget https://github.com/bluenviron/mediamtx/releases/download/v1.11.3/mediamtx_v1.11.3_linux_arm64v8.tar.gz
Unarchive it.
tar -xvzf mediamtx_v1.11.3_linux_arm64v8.tar.gz
Run MediaMTX.
./mediamtx
To stop MediaMTX tap CTRL
button in Termux and type c
.
Create a hotspot with your phone. Your camera will need to connect to your phone's hotspot (be on the same network).
Keep MediaMTX running. Open new Termux terminal by swiping right from the left edge of the screen and tapping New session
button.
Find out your phone's IP address.
ifconfig
Look for IP under swlan0
> inet
.
Configure your camera or video encoder to push to RTMP ingest of your phone.
(Replace IP_OF_YOUR_PHONE
with an actual IP of your phone.)
rtmp://IP_OF_YOUR_PHONE:1935/mystream
Start streaming your camera to MediaMTX server. If it works it works.
There are different ways to do this. Creating a service is a little a bit involved. The lazy way is to add MediaMTX to .bashrc
file. The server will start on new Termux terminal session and will be killed when you exit terminal.
nano .bashrc
Add the following line to the content of .bashrc
file.
./mediamtx
In Nano:
CTRL
+O
,Enter
to write file.CTRL
+X
to quit.
Restart Termux app or create a new terminal session to see it work.
As of March 2025 IRL Pro
doesn't have RTMP ingest feature, so this is a workaround.
Big thanks to Supairyacht
user from IRL Pro
Discord server for this idea.
We'll be pushing into RTMP ingest of MediaMTX and pulling HLS from MediaMTX. MediaMTX can do this without any extra setup.
HLS is essentially an HTML page with a video in it.
We'll create an overlay to display HLS page in IRL Pro
. It can cover the whole view area if you like.
The issue with this idea is that overlays have no audio. IRL Pro
lets you use audio via phone's audio input or Bluetooth mic connected to the phone.
There will be a delay of about 3 seconds between HLS video and phone audio, so you'll have to fix that in OBS (that has SRT media source).
- Add an overlay in
IRL Pro
. Use HLS feed from MediaMTX as an overlay source URL:http://localhost:8888/mystream
- Setup your
IRL Pro
to stream SRT HEVC. - Start your stream in
IRL Pro
. - In OBS add audio delay of about 3000 ms. (Note when you test it in OBS delay is not applied to audio monitoring, only to recording or stream.)
- Done!
Keep MediaMTX running. Open a new Termux terminal and run ffmpeg
in it.
Install ffmpeg
.
pkg install ffmpeg
To encode HEVC with hardware accelation use Mediacodec options. This works on my Samsung S20 FE for example.
Try this first (w/o -codec_name
option):
ffmpeg -i srt://localhost:8890?streamid=read:mystream \
-c:v hevc_mediacodec \
-bitrate_mode 2 \
-b:v 3000K \
-g 250 \
-pix_fmt nv12 \
-c:a copy \
-f mpegts \
srt://YOUR_SRT_URL
Different phones can have different codecs, so if that doesn't work try setting -codec_name
explicitly.
You need to look it up for your phone. Install Codec Info
app and use it to find a codec name on your phone that can do hardware accelation.
Here is what I use. -codec_name
set to OMX.qcom.video.encoder.hevc
:
ffmpeg -i srt://localhost:8890?streamid=read:mystream \
-c:v hevc_mediacodec \
-codec_name OMX.qcom.video.encoder.hevc \
-bitrate_mode 2 \
-b:v 3000K \
-g 250 \
-pix_fmt nv12 \
-c:a copy \
-f mpegts \
srt://YOUR_SRT_URL
Tweak other ffmpeg
options to your liking.
(Optional) Get more details on Mediacodec options:
ffmpeg -help encoder=hevc_mediacodec
For convenience you can create a script and manually run it.
nano ffmpeg.sh
Paste script.
while true; do
ffmpeg -i srt://localhost:8890?streamid=read:mystream \
-c:v hevc_mediacodec \
-bitrate_mode 2 \
-b:v 3000K \
-g 250 \
-pix_fmt nv12 \
-c:a copy \
-f mpegts \
srt://YOUR_SRT_URL
echo "FFmpeg exited. Restarting in 5 seconds."
sleep 5
done
In Nano:
CTRL
+O
,Enter
to write file.CTRL
+X
to quit.
Give executable permissions.
chmod +x ffmpeg.sh
Run script.
./ffmpeg.sh
To stop running CTRL
+ C
a couple of times.
Tested HLS overlay in IRL Pro idea a bit more. Overall, it works fine. The issue I've noticed is that it's skipping frames randomly here and there for me. The same frame is rendered twice, so it has these micro stutters. I had to step through frame by frame in YouTube player to see it. Untrained eyes might not notice it. I tried to fix it by changing resolutions and bitrate in both IRL Pro and ingest stream - no luck. I suspect that's just how overlays work, so I don't think it can be fixed.
As for hardware acceleration for encoding HEVC when ffmpeg and Medicodec - tested that thoroughly too.
It has issues with playback of stream in OBS and SRT players. It's a little flaky. It sometimes works alright for 1080p, but needs a bunch restarts. Weird.
With libx265 -crf 23
I can get somewhat stable 480p stream, that at least is reliably playable in OBS.
This sums state of HEVC with ffmpeg in Termux on Android so far for me.
IRL Pro
Discord threads- This is sort of a continuation of this page that I wrote https://github.com/dimadesu/termux-nginx-rtmp (it's missing a bit with hardware accelarate options though, I'll update it someday).
- I got Mediacodec ideas from https://wiki.x266.mov/docs/encoders_hw/mediacodec