其他分享
首页 > 其他分享> > 从视频中截取图片--直接调用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)具体代码

 

标签:00,ffmpeg,--,截取,ShExecInfo,mp4,QString,Image
来源: https://www.cnblogs.com/zeliangzhang/p/15612038.html