EasyAVFilter code example: convert camera RTSP stream recording into mp4 file for segmented storage

The following is a complete set of development source code for RTSP streaming mp4 segmented storage function. With just a few lines of code, the original ffmpeg complex calling process can be completed, and it can also be integrated and called in your own application, such as java , php, cgo, c++, nodejs, there is no need to call a separate ffmpeg process, the method is very simple:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "EasyAVFilterAPI.h"

#ifdef _WIN32
#pragma comment(lib,"EasyAVFilter.lib")
#endif

Easy_Handle fRTSPHandle = 0;			
int Easy_APICALL __AVFilterCallBack(void* userPtr, EASY_AV_FILTER_STATE_T status, int progress, int errCode, const char *errMsg)
{
    
    
	//各种状态的回调,例如拉流状态/推流状态/转码状态/媒体信息
	return 0;
}

int main(int argc, char** argv)
{
    
    
	// 创建EasyAVFilter实例
	Easy_Handle avFilterHandle = NULL;
	EasyAVFilter_Create(&avFilterHandle);
	// 信息回调
	EasyAVFilter_SetCallback(avFilterHandle,__AVFilterCallBack,0);
	// 将网络流录制成本地MP4或者HLS录像,参考命令:./ffmpeg.exe -re -rtsp_transport tcp -i rtsp://admin:[email protected]:554/ch1/main/av_stream -c:v copy -c:a aac -f segment -segment_list ./20230829150000.m3u8 -segment_time 300 -strftime 1 rec_%Y-%m-%d_%H-%M-%S.ts
	EasyAVFilter_AddInput(avFilterHandle, "rtsp://admin:[email protected]:554/ch1/main/av_stream", 1);
	EasyAVFilter_AddFilter(avFilterHandle, "-vcodec copy -acodec aac");
	EasyAVFilter_AddFilter(avFilterHandle, "-f segment -segment_time 8 -reset_timestamps 1 -strftime 1");
	EasyAVFilter_AddFilter(avFilterHandle, "-segment_list C://temp/20230829150000.m3u8");//是否需要列表文件,可要可不要
	EasyAVFilter_SetOutput(avFilterHandle, "C://temp/output_%Y-%m-%d_%H-%M-%S.mp4", 0);

	// 将本地视频文件转成格式化的MP4或者HLS提供点播,参考命令:./ffmpeg.exe -re -rtsp_transport tcp -i rtsp://admin:[email protected]:554/ch1/main/av_stream -vcodec copy -acodec aac -ac 2 -strict -2 -f flv rtmp://172.81.216.155:3519/live/IbMkUXeVR?sign=SxMk8X6VRz
	EasyAVFilter_AddInput(avFilterHandle, "rtsp://admin:[email protected]:554/ch1/main/av_stream", 1);
	EasyAVFilter_AddFilter(avFilterHandle, "-vcodec copy -acodec aac -ac 2 -strict -2");
	EasyAVFilter_AddFilter(avFilterHandle, "-f flv");
	EasyAVFilter_SetOutput(avFilterHandle, "rtmp://172.81.216.155:3519/live/IbMkUXeVR?sign=SxMk8X6VRz", 0);//H.265 support

	char filterCommand[256] = {
    
     0 };
	EasyAVFilter_GetFilters(avFilterHandle, filterCommand);
	printf("command: %s\n", filterCommand);

	EasyAVFilter_Start(avFilterHandle, 1, 8, 10);//注意,文件转码不需要循环读取,第二个参数从1改成0

	getchar();
	EasyAVFilter_Stop(avFilterHandle);

	getchar();
	EasyAVFilter_Release(&avFilterHandle);

	return 0;
}

The above complete program engineering can be downloaded from EasyDarwin official website: www.easydarwin.org
easyavfilter

Guess you like

Origin blog.csdn.net/xiejiashu/article/details/132757941