1. 程式人生 > 其它 >從視訊中擷取圖片--直接呼叫ffmpeg

從視訊中擷取圖片--直接呼叫ffmpeg

直接呼叫ffmpeg ,沒用到ffmpeg 程式設計知識。

(1)所需的標頭檔案

#include <Windows.h>
#include <ShellAPI.h>
#include <QTextCodec>
#include <string>
using namespace std;

(2)所需的庫shell32.lib

void FFmpegDemo::on_pictureBtn_clicked()
{
//D:\Demo\FFmpegDemo\Win32\Debug > ffmpeg - i D : \Demo\FFmpegDemo\FFmpegDemo\1.mp4 - r
// 1 - ss 00:00 : 26 - t 00 : 00 : 07 % 03d.png /* 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 表示圖片輸入流格式 */ QTextCodec::setCodecForLocale(QTextCodec::codecForName(
"UTF-8")); QString path = QApplication::applicationDirPath(); // QString paramter = QString("%1/ffmpeg.exe -i %1/1.mp4 -r 1 -ss 00:02:00 -t 00:01:07 %1/Image/Image_%d.bmp ").arg(path); QString paramter = QString("-i %1/1.mp4 -y -framerate 10 -start_number 100 -r 1 -ss 00:02:00 -t 00:01:07 %1/Image/Image_%d.bmp ").arg(path); QString file
= path + "/ffmpeg.exe"; wstring sFile = file.toStdWString(); wstring sParamter = paramter.toStdWString(); 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.lpFile = sFile.c_str(); //ShExecInfo.lpParameters = L"ffmpeg.exe -y -framerate 10 -start_number 1 -i E:\Image\Image_%d.bmp E:\test.mp4"; ShExecInfo.lpParameters = sParamter.c_str(); ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE;//視窗狀態為隱藏 ShExecInfo.hInstApp = NULL; if (ShellExecuteEx(&ShExecInfo)) { if (ShExecInfo.hProcess) { WaitForSingleObject(ShExecInfo.hProcess, INFINITE); } } }

(3)具體程式碼