C++ opencv ffmpeg圖片序列化實現(xiàn)代碼解析
更新時間:2020年08月27日 08:35:47 作者:njit_77
這篇文章主要介紹了C++ opencv ffmpeg圖片序列化實現(xiàn)代碼解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
0、如果路徑中存在空格,用""把路徑包括起來
1、使用ffmpeg命令
ffmpeg -y -framerate 10 -start_number 1 -i E:\Image\Image_%d.bmp E:\test.mp4 -y 表示輸出時覆蓋輸出目錄已存在的同名文件 -framerate 10 表示視頻幀率 -start_number 1 表示圖片序號從1開始 -i E:\Image\Image_%d.bmp 表示圖片輸入流格式
2、c++ 實現(xiàn) ffmpeg命令
2.1、system方式
// 代碼中執(zhí)行過程中會出現(xiàn)黑屏的閃爍,無法隱藏
system("ffmpeg.exe -y -framerate 10 -start_number 1 -i E:\Image\Image_%d.bmp E:\test.mp4");
2.2、ShellExecuteEx方式
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:\Image\Image_%d.bmp E:\test.mp4";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;//窗口狀態(tài)為隱藏
ShExecInfo.hInstApp = NULL;
if (ShellExecuteEx(&ShExecInfo))
{
if (ShExecInfo.hProcess)
{
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
}
}
3、使用opencv
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);
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++?Cartographer源碼中關(guān)于MapBuilder的聲明與構(gòu)造
這篇文章主要介紹了C++?Cartographer源碼中關(guān)于MapBuilder的聲明與構(gòu)造,前面已經(jīng)談到了Cartographer中添加軌跡的方法和傳感器的數(shù)據(jù)流動走向。在添加軌跡的時候,除了添加位姿估計器還有采樣器,訂閱回調(diào)函數(shù)之外,最重要的是通過map_builder_bridge添加了一條軌跡2023-03-03

