用EasyAVFilter(ffmpeg.dll)实现RTSP流转RTMP推流的demo示例Linux版

ffmpeg.exe做拉流转推流不靠谱,不能产品化;avcodec、avfilter做拉流转推流门槛又太高;用EasyAVFilter将ffmpeg.c改成ffmpeg.dll,用起来刚刚好,直接上示例代码:

cpp 复制代码
#ifdef _WIN32
#include <winsock2.h>
#endif

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


int Easy_APICALL __EasyAVFilterCallBack(void* userPtr, EASY_AV_FILTER_STATE_T status, int progress, int errCode, const char *errMsg)
{
    
    printf("__EasyAVFilterCallBack status: %d  errCode:%d  errMsg:%s\n", __EasyAVFilterCallBack, errCode,  errMsg);
    
    return 0;
}


int main(int argc, char** argv)
{
    printf("main...\n");
    
	Easy_Handle avFilterHandle = NULL;

	EasyAVFilter_Create(&avFilterHandle);
        EasyAVFilter_SetCallback(avFilterHandle, __EasyAVFilterCallBack, avFilterHandle);
#if 0
	// 用法1
	EasyAVFilter_AddInput(avFilterHandle[i], "rtsp://admin:12345@192.168.1.100", 1);
	EasyAVFilter_AddFilter(avFilterHandle[i], "-vcodec copy -acodec aac");
	EasyAVFilter_SetOutput(avFilterHandle[i], "rtmp://192.168.1.200:1935/live/ch1", 0);
#else
	// 用法2
	//const char* pCommand = "-rtsp_transport tcp -i rtsp://admin:12345@192.168.1.100 -vcodec copy -acodec copy -f flv rtmp://192.168.1.200:1935/live/ch1";
	char command[512] = { 0 };
	char* pCommand = (char*)command;
	for (int i = 1; i < argc; i++)
	{
		pCommand += sprintf(pCommand, " %s", argv[i]);
	}

	EasyAVFilter_AddFilter(avFilterHandle, command);
#endif

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

	EasyAVFilter_Start(avFilterHandle, 1, 30, 20);

        printf("Press Enter key to exit...\n");
	getchar();

	EasyAVFilter_Stop(avFilterHandle);

	EasyAVFilter_Release(&avFilterHandle);
        
        
        
        return 0;
}

Demo下载地址:https://www.easydarwin.org/tools/153.html

相关推荐
dvlinker15 分钟前
C++开源项目 VLC 源代码的交叉编译以及库的裁剪方法详解
ffmpeg·mingw-w64·msys2·cygwin·开源vlc·vlc编译·vlc裁剪
冬天vs不冷20 分钟前
Linux用户与权限管理详解
linux·运维·chrome
凯子坚持 c1 小时前
深入Linux权限体系:守护系统安全的第一道防线
linux·运维·系统安全
✿ ༺ ོIT技术༻1 小时前
C++11:新特性&右值引用&移动语义
linux·数据结构·c++
watermelonoops4 小时前
Deepin和Windows传文件(Xftp,WinSCP)
linux·ssh·deepin·winscp·xftp
疯狂飙车的蜗牛5 小时前
从零玩转CanMV-K230(4)-小核Linux驱动开发参考
linux·运维·驱动开发
远游客07137 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
马甲是掉不了一点的<.<7 小时前
本地电脑使用命令行上传文件至远程服务器
linux·scp·cmd·远程文件上传
jingyu飞鸟7 小时前
centos-stream9系统安装docker
linux·docker·centos
超爱吃士力架8 小时前
邀请逻辑
java·linux·后端