How to build rtsp stream from a mp4 file to test EuhatRtsp

First, convert mp4 file to h264 file, save script below named convert.bat

1
2
ffmpeg.exe -i %1 -s 1920x1080 -b:v 1536K -an output.mp4
ffmpeg -i output.mp4 -codec copy -bsf: h264_mp4toannexb -f h264 output.264

drag a mp4 file over convert.bat, after a while, output.264 will be generated. download h264LiveMediaServer.zip, unzip as h264LiveMediaServer.exe, move it to the same directory with output.264, just double click and run h264LiveMediaServer.exe, it will notify you the rtsp url, then input the url in the url edit box on the EuhatRtsp Demo app ui, click begin button, wait several seconds, you will see the video rendering in EuhatRtsp.

Before running h264LiveMediaServer.exe, vc2019 x86 Redistributable must be installed.

Visit H264LiveMediaServer on Github to get the source code.

How to record the H264 stream using EuhatRtsp lib

euhatrtsp/livevideo/RtspOp.cpp

389
390
391
392
393
394
395
396
397
int EuhatRtspOp::decodingProc()
{//frame是原始H264数据,在这里录像最好,此库已经把ffmpeg库编译进去了,直接用ffmpeg库就可以完成录像功能。
//可以网上搜ffmpeg录像api怎么用。
//这就要求会写C++代码,还要加jni接口提供给java端打开或关闭录像功能。
decoder_->decode(frame + 4, *(int *)frame);}

将视频文件变成RTSP流服务

http://ffbinaries.com/downloads下载ffserver到linux系统,

制作server.cfg文件如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
RTSPPort 5454
BindAddress 0.0.0.0
RTSPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 30000
CustomLog -
NoDaemon
#NoDefaults
 
<Stream test.mp4>
File "/home/sdb/work/stream/test.mp4"
Format rtp
</Stream>

命令行运行

1
./ffserver -f server.cfg

这样,任何地方,只要能连接到此linux系统,其IP地址为192.168.1.32,都可以播放

1
rtsp://192.168.1.32:5454/test.mp4