利用qt和ffmpeg软件来制作视频裁剪工具

1、ffmpeg+QT开发环境搭建 开发环境搭建 1、开发库的选择 (1)音视频开发库 每个主流平台基本都有自己的音视频开发库(API),用以处理音视频数据,比如: iOS:AVFoundation、AudioUnit 等 Android:MediaPlayer、MediaCodec 等 Windows:DirectShow 等 但是有一个跨平台的库:FFmpeg 库。 其实只要你掌握了FFmpeg,也可以很快上手其他音视频开发库,因为底层原理都是一样的,你最终操作的都是一样的数据,比如MP3、MP4文件。 补充:openGL 是什么东 阅读详情

0 什么是ffmpeg?

Libav(旧称:FFmpeg)是一个自由软件,可以运行音频和视频多种格式的录影、转档、流功能[1],包含了libavcodec ─这是一个用于多个专案中音频和视频的解码器库,以及 libavformat ——一个音频与视频格式转换库。

libav的旧称"FFmpeg"这个单词中的 "FF" 指的是 "Fast Forward"[2]。有些新手写信给"FFmpeg"的项目负责人,询问FF是不是代表“Fast Free”或者“Fast Fourier”等意思,"FFmpeg"的项目负责人回信说“Just for the record, the original meaning of "FF" in FFmpeg is "Fast Forward"...”

http://zh.wikipedia.org/wiki/Libav

 

 一 下载ffmpeg

官方网站:     http://ffmpeg.zeranoe.com/

访问               http://ffmpeg.zeranoe.com/builds/

下载ffmpeg windows下发布版

FFmpeg git-f514695 32-bit Shared (Latest) 

 

二 在命令行下学会ffmpeg使用

cd 进入ffmpeg解压缩目录下的bin目录

ffmpeg.exe -i D:/source.avi -vcodec copy -y -r 25 -ss 8 -t 971 D:/demo.mp4  >> D:\clip_info.txt 2>&1

 

这里-vcodec copy参数一定要加,这样裁剪的时候不会改变视频的编码方式,裁剪非常快。

 

ffmpeg主要参数一览

Hyper fast Audio and Video encoder

usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Main options:
-L                  show license
-h                  show help
-?                  show help
-help               show help
--help              show help
-version            show version
-formats            show available formats
-codecs             show available codecs
-bsfs               show available bit stream filters
-protocols          show available protocols
-filters            show available filters
-pix_fmts           show available pixel formats
-sample_fmts        show available audio sample formats
-loglevel loglevel  set libav* logging level
-v loglevel         set libav* logging level
-debug flags        set debug flags
-report             generate a report
-max_alloc bytes    set maximum size of a single allocated block
-f fmt              force format
-i filename         input file name
-y                  overwrite output files
-n                  do not overwrite output files
-c codec            codec name
-codec codec        codec name
-pre preset         preset name
-map_metadata outfile[,metadata]:infile[,metadata]  set metadata information of outfile from infile
-t duration         record or transcode "duration" seconds of audio/video
-fs limit_size      set the limit file size in bytes
-ss time_off        set the start time offset
-itsoffset time_off  set the input ts offset
-itsscale scale     set the input ts scale
-timestamp time     set the recording timestamp ('now' to set the current time)
-metadata string=string  add metadata
-dframes number     set the number of data frames to record
-timelimit limit    set max runtime in seconds
-target type        specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...)
-xerror             exit on error
-frames number      set the number of frames to record
-tag fourcc/tag     force codec tag/fourcc
-filter filter_list  set stream filterchain
-stats              print progress report during encoding
-attach filename    add an attachment to the output file
-dump_attachment filename  extract an attachment into a file
-bsf bitstream_filters  A comma-separated list of bitstream filters
-dcodec codec       force data codec ('copy' to copy stream)

Advanced options:
-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_s  set input stream mapping
-map_channel file.stream.channel[:syncfile.syncstream]  map an audio channel from one stream to another
-map_chapters input_file_index  set chapters mapping
-benchmark          add timings for benchmarking
-dump               dump each input packet
-hex                when dumping packets, also dump the payload
-re                 read input at native frame rate
-loop_input         deprecated, use -loop
-loop_output        deprecated, use -loop
-vsync              video sync method
-async              audio sync method
-adrift_threshold threshold  audio drift threshold
-copyts             copy timestamps
-copytb source      copy input stream time base when stream copying
-shortest           finish encoding within shortest input
-dts_delta_threshold threshold  timestamp discontinuity delta threshold
-copyinkf           copy initial non-keyframes
-q q                use fixed quality scale (VBR)
-qscale q           use fixed quality scale (VBR)
-streamid streamIndex:value  set the value of an outfile streamid
-muxdelay seconds   set the maximum demux-decode delay
-muxpreload seconds  set the initial demux-decode delay
-fpre filename      set options from indicated preset file

Video options:
-vframes number     set the number of video frames to record
-r rate             set frame rate (Hz value, fraction or abbreviation)
-s size             set frame size (WxH or abbreviation)
-aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number  set the number of bits per raw sample
-croptop size       Removed, use the crop filter instead
-cropbottom size    Removed, use the crop filter instead
-cropleft size      Removed, use the crop filter instead
-cropright size     Removed, use the crop filter instead
-padtop size        Removed, use the pad filter instead
-padbottom size     Removed, use the pad filter instead
-padleft size       Removed, use the pad filter instead
-padright size      Removed, use the pad filter instead
-padcolor color     Removed, use the pad filter instead
-vn                 disable video
-vcodec codec       force video codec ('copy' to copy stream)
-sameq              use same quantizer as source (implies VBR)
-same_quant         use same quantizer as source (implies VBR)
-pass n             select the pass number (1 or 2)
-passlogfile prefix  select two pass log file name prefix
-vf filter list     video filters
-b bitrate          video bitrate (please use -b:v)
-dn                 disable data

 

三 利用QT4做个简单图形界面工具

 

 

这里主要用了QProcess这个类,可以调用外部程序。

关键代码: 

 

    QString program = "D:\\maxview_video_demo\\ffmpeg\\ffmpeg-git-985e768-win64-static\\bin\\ffmpeg.exe";
    QString inputPath = ui->videopathLineEdit->text();
    QFile sourceFile(inputPath);
    if(!sourceFile.exists()){
        QMessageBox::information(this,QString::fromUtf8("提示"),QString::fromUtf8("找不到源文件"));
        return;
    }

    QString outputPath = QFileInfo(sourceFile).absolutePath() +"/clip.mp4";

    QFile destFile(outputPath);
    if(destFile.exists()){
        destFile.remove();
    }

    QString startTime = ui->videoStartTimeEdit->time().toString("hh:mm:ss");
    QString len= ui->videoLengthTimeEdit->time().toString("hh:mm:ss");
    QStringList arguments;
    arguments << "-i" << inputPath << "-r" << "25"<<"-ss";
    arguments <<startTime<< "-t" << len<< outputPath;

    QProcess *clipProcess = new QProcess(this);
    connect(clipProcess,SIGNAL(finished(int)),this,SLOT(clipVideoFinished(int)));

    clipProcess->start(program, arguments);

 

当视频截取完成后,进程会发生信号finished(int),并被QProcess捕捉到,这样可以调用

clipVideoFinished函数来通知程序视频裁剪完成了。

ffmpeg(一) ffmpeg+QT开发环境搭建 (exe 程序编译的时候只需要包含 xxx.dll.a 静态导入库,运行的时候才需要 xxx.dll 文件)这个 .pro 文件的配置,是指导程序编译的时候,可以找到对应的动态库。值得一提的是,在Windows中,静态链接库(Static Link Library)的扩展名也是.lib、.dll.a。其实只要你掌握了FFmpeg,也可以很快上手其他音视频开发库,因为底层原理都是一样的,你最终操作的都是一样的数据,比如MP3、MP4文件。导入库:不包含函数的具体实现代码(函数的具体实现代码存储在dll中) 阅读详情

相关推荐

Qt 视频剪辑软件开发:实现视频双向拖动与剪辑

当滑块移动时,根据滑块的位置调整视频的播放进度;在主窗口的构造函数中,我们将这些控件添加到合适的布局管理器中,并通过信号槽机制连接 QMediaPlayer 控件的 durationChanged 和 positionChanged 信号到 MainWindow 类的 durationChanged() 和 positionChanged() 槽函数。当鼠标左键按下时,我们记录下当前的鼠标位置,当鼠标移动时,计算出鼠标在 X 轴上的移动距离,并根据当前播放位置调整视频的播放进度。

CodeVorter的博客 574

使用FFmpeg实现精确剪切视频

基本的剪切命令: 用-ss和-t选项, 从第 30 秒开始,向后截取 10 秒的视频,并保存: ffmpeg -i input.wmv -ss 00:00:30.0 -c copy -t 00:00:10.0-codec copy output.wmv ffmpeg -i input.wmv -ss 30 -c copy -t 10 -codec copy output.wmv 达成相同效果,也可以用-ss和-to选项, ffmpeg -i input.wm...

yunxiaobaobei的博客 3万+

基于Qt的视频处理工具实战:裁剪、抽帧与图片转视频

视频处理作为多媒体领域的核心技术,贯穿于安防监控、影视制作、智能分析及人机交互等关键行业。随着4K/8K高清视频与流媒体服务的普及,高效编码(如H.265)、精准编辑与实时分析能力成为系统性能的核心指标。本章系统介绍视频的基本构成——包括帧类型(I/P/B帧)、常见编码标准与封装格式(MP4、AVI),并解析裁剪、抽帧、合成等操作的技术本质。结合教育录播中知识点切片、自动驾驶中视觉感知等场景,展现视频处理在实际工程中的枢纽作用,为后续深入算法实现与工具链整合奠定认知基础。

weixin_42594427的博客 1087

学习OpenCV3.2+QT5+ffmpeg实战开发视频编辑器视频教程

OpenCV3.2+QT5+ffmpeg实战开发视频编辑器视频培训课程概况:教程中会讲解到基于opencv视频和摄像机录制、播放和播放进度控制,多视频图像合并、多视频图像融合、剪切、视频亮度、对比度、尺寸(近邻插值(手动实现),双线性插值,图像金字塔)、颜色格式(灰度图,二值化(阈值)),旋转镜像,视频裁剪(ROI),视频水印(ROI+weight),导出处理后的视频(包含音频,使用ffmpeg工具对音频进行抽取、剪切和终于opencv处理的视频合并)。

Qt 基于FFmpeg的视频播放器 - QtFFmpegPlayer

- `本文基于FFmpeg,使用Qt制作了一个极简的视频播放器. 如图所示:` - FFmpeg版本信息:`ffmpeg-n7.0-latest-win64-lgpl-shared-7.0`

做减求空 3889

【QT window】ffmpeg实现手动绘图(裁剪)、缩放、拍照,显示fps等功能

QT进行摄像头相关的开发,除了可以使用自带的多媒体模块,以及opencv(前面已经分享相关博文),还可以用专注底层细节的音视频处理工具ffmpeg。在对硬件有要求的条件下,用ffmpeg才能实现极致优化(低延迟等),opencv在图片处理上非常厉害,在视频播放上不一定很全面,项目对fps有高要求时,需要结合ffmpeg库进行开发。

ocy的博客 1090

基于FFMPEG的音视频截取(C++Qt 版)

基于FFMPEG的音视频截取(C++Qt 版) 这篇博客是基于上篇博客的: https://blog.csdn.net/liyuanbhu/article/details/121744275 上篇博客实现了文件封装转换。我们在这个基础上再加一点功能。实现可以任意截取一段时间范围内的音视频。 下面是代码: QlyAVFormatContext inFile, outFile; inFile.openFile(QString("D:\\AV36_1.avi")); inFile.dumpFormat(); QS

Ivan 的专栏 2693

视频剪辑新体验:基于FFmpeg的Windows GUI工具开发

FFmpeg是一个跨平台的开源项目,最初是由Fabrice Bellard发起的,并逐渐发展成为一个广泛应用于视频处理领域的工具集。它支持几乎所有的音频和视频编码格式,以及多种音视频处理功能,如转码、流处理、过滤器使用等。Qt允许开发者重写控件的事件处理函数来改变控件的行为。例如,可以重写来响应鼠标点击事件,或使用自定义控件来实现特定的用户界面需求。protected:在这个例子中,MyWidget重写了事件处理函数来识别鼠标左键的点击,并输出相应的信息。

weixin_32005771的博客 1156

Qt5.12下视频剪辑器(基于Opencv、ffmpeg)

本文介绍了如何通过 Qt ,OpenCV,ffmpeg 实现一个简单的视频剪辑器。通过该工具,用户可以轻松地对视频进行剪辑、处理和导出。在实际开发中,还可以进一步扩展功能,比如支持更多的视频格式、增加滤镜效果等。

该博主有点懒,什么也没写 2011

基于DPLL算法解决3-SAT问题(C++实现)

近日看到一个3-SAT问题(Boolean SATisfiability Problem, 布尔逻辑可满足性问题),试着写了个算法求解。

qq_63241496的博客 2223

Nginx反向代理HTTPS服务报错排查:The plain HTTP request was sent to HTTPS port

在Web服务架构中,反向代理是连接客户端与后端应用的关键组件,它通过转发请求实现负载均衡和安全隔离。其工作原理涉及监听端口、解析协议头部,并根据配置将请求路由至上游服务器。这一机制的技术价值在于提升系统可扩展性、简化部署,并增强安全性。在HTTPS场景下,代理服务器需正确处理SSL/TLS终止与传递,若配置不当,常引发协议不匹配问题。例如,当Nginx将解密后的HTTP请求转发至期待HTTPS的后端,或客户端直接向SSL端口发送明文请求时,便会出现经典报错“The plain HTTP request wa

weixin_33391446的博客 435

QT ffmpeg视频剪辑

ffmpeg cmd指令:source.avi视频从8秒开始时长为971秒剪辑 25帧率,保存到D:/demo.mp4。 //ffmpeg.exe -i D:/source.avi -vcodec copy -y -r 25 -ss 8 -t 971 D:/demo.mp4 >> D:\clip_info.txt 2>&1 QString program=QCo...

leng3667的博客 1297

S32K3的STCU2模块详解:从硬件FSM到MCAL配置,搞懂BIST在线测试全流程

本文深入解析S32K3系列MCU的STCU2模块,从硬件FSM架构到MCAL配置,详细讲解BIST在线测试全流程。通过分区的安全策略和实战代码示例,帮助开发者掌握汽车电子系统中的功能安全实现,提升系统可靠性和安全性。

weixin_42525328的博客 454
上一篇: windows下GStreamer开发介绍
下一篇: 在谷歌地图上随机生成指定数量的点,测试负载能力的代码。
飞羽飞之猪
博客等级 码龄21年 127粉丝 85原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址