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

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

1
2
3
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
#ffmpeg -i test.264 -vcodec copy -f mp4 test.mp4

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.

视频在微信手机端看不了

比如用ffmpeg在电脑端录的mp4视频,拖到微信电脑端是可以看的,但打开微信手机端就不动了,只能看到第一帧。

解决办法是先将mp4格式转为mpg格式,再将mpg格式转为mp4格式,最后得到的mp4就可在微信手机端播放了:

1
2
ffmpeg.exe -i old.mp4 temp.mpg
ffmpeg.exe -i temp.mpg new.mp4

附ffmpeg在windows下录屏方法:

1
ffmpeg -f gdigrab -framerate 30 -offset_x 655 -offset_y 517 -video_size 511x374 -i desktop capture.mpg

ffmpeg在ubuntu下录屏方法:

1
ffmpeg -framerate 25 -f x11grab -s 800x600 -i :0.0+100,200 capture.mp4

转码为mp4的方法:

1
2
3
ffmpeg.exe -ss 5 -sseof 5 -i %1 -vf scale=-2:600 -y output.mp4
 
rem ffmpeg.exe -ss 5 -sseof 5 -i %1 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" output.mp4

refer to:
https://github.com/GyanD/codexffmpeg/releases/tag/2021-12-02-git-4a6aece703
https://www.xzcblog.com/post-173.html

将视频文件变成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