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 to 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.

popen返回NULL

当程序写得越来越大,进程占用的内存也就越来越多,调用popen时会返回空的FILE指针,网上说原因是system或popen这样的系统函数,其内部实现是调用fork函数创建子进程,创建过程中会复制父进程堆、栈等资源,这样就容易造成创建失败,返回NULL。

以下是我写的用vfork替换fork调用的Vpopen类。

Vpopen.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once
 
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
 
class Vpopen
{
        FILE *fp_;
        pid_t pid_;
        int pipeFd_[2];
public:
        Vpopen();
        ~Vpopen();
        FILE *open(const char *cmd, const char *flags);
        void close();
};

阅读更多popen返回NULL