从视频中截取图片--直接调用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 @   泽良_小涛  阅读(221)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示