C++调用ffmpeg命令推流【详细代码】

2021/6/2 12:21:21

本文主要是介绍C++调用ffmpeg命令推流【详细代码】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

      我们可以使用ffmpeg命令进行很多工作,也可以在代码中调用ffmpeg指令进行相关操作,例如推流,录屏等,线面介绍C++调用ffmpeg命令进行rtmp推流。命令如下:

                                                      ffmpeg.exe -re -i qqq.flv -c copy -f flv rtmp地址

      推流前,先打开rtmp服务器。下面的代码是C++调用ffmpeg指令本地flv文件rtmp推流:

#include#includeusing namespace std;

int main()
{
	wstring strFfmpegPath = L"D:\\DevLib\\FFmpeg\\ffmpeg.exe";  //ffmpeg.exe所在的位置的完整路径
	wstring strCmdContent = L"/c " + strFfmpegPath + L" -re -i " + L"D:\\TestFiles\\qqq.flv -c copy -f flv rtmp://192.168.227.129/live";

	SHELLEXECUTEINFO ShExecInfo = { 0 };
	ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
	ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
	ShExecInfo.hwnd = NULL;
	ShExecInfo.lpVerb = NULL;
	ShExecInfo.lpFile = L"C:\\Windows\\System32\\cmd.exe";
	ShExecInfo.lpParameters = strCmdContent.c_str();
	ShExecInfo.lpDirectory = NULL;
	ShExecInfo.nShow = SW_HIDE;
	ShExecInfo.hInstApp = NULL;
	ShellExecuteEx(&ShExecInfo);
	WaitForSingleObject(ShExecInfo.hProcess, INFINITE);

	cout << "调用结束" << endl;
	return 0;
}

   代码说明:

           (1)用windows API ShellExecuteEx可以调用外部exe程序,注意exe的路径。 

           (2)windows API有些涉及到宽字节unicode编码,建议在编程时使用unicode, wstring替代string等基本编程规则,uicode与多字节涉及到数据类型转转,很坑。



这篇关于C++调用ffmpeg命令推流【详细代码】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程