用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

相关推荐
小安运维日记18 分钟前
Linux云计算 |【第四阶段】NOSQL-DAY1
linux·运维·redis·sql·云计算·nosql
CoolTiger、3 小时前
【Vmware16安装教程】
linux·虚拟机·vmware16
学习3人组4 小时前
CentOS 中配置 OpenJDK以及多版本管理
linux·运维·centos
厨 神5 小时前
vmware中的ubuntu系统扩容分区
linux·运维·ubuntu
Karoku0665 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
geek_Chen015 小时前
虚拟机共享文件夹开启后mnt/hgfs/下无sharefiles? --已解决
linux·运维·服务器
(⊙o⊙)~哦5 小时前
linux 解压缩
linux·运维·服务器
牧小七6 小时前
Linux命令---查看端口是否被占用
linux
鸡鸭扣8 小时前
虚拟机:3、(待更)WSL2安装Ubuntu系统+实现GPU直通
linux·运维·ubuntu
友友马8 小时前
『 Linux 』HTTP(一)
linux·运维·服务器·网络·c++·tcp/ip·http