我是靠谱客的博主 清秀裙子,这篇文章主要介绍C++ opencv ffmpeg图片序列化实现代码解析,现在分享给大家,希望可以做个参考。

0、如果路径中存在空格,用""把路径包括起来

1、使用ffmpeg命令

复制代码
1
2
3
4
5
ffmpeg -y -framerate 10 -start_number 1 -i E:ImageImage_%d.bmp E:test.mp4 -y 表示输出时覆盖输出目录已存在的同名文件 -framerate 10 表示视频帧率 -start_number 1 表示图片序号从1开始 -i E:ImageImage_%d.bmp 表示图片输入流格式

2、c++ 实现 ffmpeg命令

2.1、system方式

// 代码中执行过程中会出现黑屏的闪烁,无法隐藏
system("ffmpeg.exe -y -framerate 10 -start_number 1 -i E:ImageImage_%d.bmp E:test.mp4");

2.2、ShellExecuteEx方式

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SHELLEXECUTEINFO ShExecInfo = { 0 }; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = L"open"; ShExecInfo.lpFile = L"ffmpeg.exe"; ShExecInfo.lpParameters = L"ffmpeg.exe -y -framerate 10 -start_number 1 -i E:ImageImage_%d.bmp E:test.mp4"; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE;//窗口状态为隐藏 ShExecInfo.hInstApp = NULL; if (ShellExecuteEx(&ShExecInfo)) { if (ShExecInfo.hProcess) { WaitForSingleObject(ShExecInfo.hProcess, INFINITE); } }

3、使用opencv

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cv::Mat image; int fps = 10;//视频帧率 /*cv::VideoWriter::fourcc('M', 'P', '4', 'V')生成MP4格式视频*/ /*cv::VideoWriter::fourcc('M', 'J', 'P', 'G')生成avi格式视频,大小比'X', 'V', 'I', 'D'大*/ /*cv::VideoWriter::fourcc('X', 'V', 'I', 'D')生成avi格式视频*/ cv::VideoWriter writer("video_out.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), fps, cv::Size(3840, 2748)/*图片大小,一定不能出错*/, 0); for (size_t i = 1; i <= 100; i++) { image = cv::imread("Image_" + std::to_string(i) + ".bmp", cv::IMREAD_GRAYSCALE); if (!image.empty()) { writer.write(image); } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是清秀裙子最近收集整理的关于C++ opencv ffmpeg图片序列化实现代码解析的全部内容,更多相关C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部