用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:[email protected]", 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:[email protected] -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

相关推荐
用户967151139167214 小时前
Rust 如何轻松实现 RTMP 流媒体推送?深入解析直播推流场景与解决方案
rust·ffmpeg
小小码农Come on14 小时前
ffmpeg命令整理
ffmpeg
cg501714 小时前
Spring Boot 的配置文件
java·linux·spring boot
暮云星影15 小时前
三、FFmpeg学习笔记
linux·ffmpeg
rainFFrain15 小时前
单例模式与线程安全
linux·运维·服务器·vscode·单例模式
GalaxyPokemon15 小时前
Muduo网络库实现 [九] - EventLoopThread模块
linux·服务器·c++
mingqian_chu15 小时前
ubuntu中使用安卓模拟器
android·linux·ubuntu
GalaxyPokemon17 小时前
Muduo网络库实现 [十] - EventLoopThreadPool模块
linux·服务器·网络·c++
自由鬼17 小时前
开源虚拟化管理平台Proxmox VE部署超融合
linux·运维·服务器·开源·虚拟化·pve