从视频中截取图片--直接调用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 表示图片输入流格式

-r:每秒提取的帧数,如上面为每秒1帧,即一张图像


-q:v :图片质量


-f:图片格式,上述为image2


image-%d.jpeg:生成图像的文件名,可以加上完整路径,%d会使文件名按整数编号,如上述生成图像为image-1.jpeg, image-2.jpeg, ...


还有其他参数:


-t:持续时间,如-t 4表示持续4s


-ss:起始时间,如-ss 01:30:14,从01:30:14开始


-vframes:指定抽取的帧数,如-vframes 120,指定抽取120张


-s:格式大小,如-s 640x360


-y:覆盖,直接使用

*/
    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)具体代码

 

posted @ 2021-11-27 15:21  泽良_小涛  阅读(216)  评论(0编辑  收藏  举报