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"); QProcess *clipProcess = new QProcess(this); clipProcess->start(program, arguments); 当视频截取完成后,进程会发生信号finished(int),并被QProcess捕捉到,这样可以调用 clipVideoFinished函数来通知程序视频裁剪完成了。 0 什么是ffmpeg? Libav(旧称:FFmpeg)是一个自由软件,可以运行音频和视频多种格式的录影、转档、流功能[1],包含了libavcodec libav的旧称"FFmpeg"这个单词中的 "FF" 指的是 "Fast Forward"[2]。有些新手写信给"FFmpeg"的项目负责人,询问FF是不是代表“Fast http://zh.wikipedia.org/wiki/Libav 一 下载ffmpeg 官方网站: http://ffmpeg.zeranoe.com/ 访问 http://ffmpeg.zeranoe.com/builds/ 下载ffmpeg windows下发布版 FFmpeg 二 在命令行下学会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: Advanced options: Video options: 三 利用QT4做个简单图形界面工具 这里主要用了QProcess这个类,可以调用外部程序。 关键代码: QString program = "D:\\maxview_video_demo\\ffmpeg\\ffmpeg-git-985e768-win64-static\\bin\\ffmpeg.exe"; QString outputPath = QFileInfo(sourceFile).absolutePath() +"/clip.mp4"; QFile destFile(outputPath); { QString startTime = ui->videoStartTimeEdit->time().toString("hh:mm:ss"); QProcess *clipProcess = new QProcess(this); clipProcess->start(program, arguments); 当视频截取完成后,进程会发生信号finished(int),并被QProcess捕捉到,这样可以调用 clipVideoFinished函数来通知程序视频裁剪完成了。
QString len= ui->videoLengthTimeEdit->time().toString("hh:mm:ss");
QStringList arguments;
arguments << "-i" << inputPath << "-r" << "25"<<"-ss";
arguments <
connect(clipProcess,SIGNAL(finished(int)),this,SLOT(clipVideoFinished(int)));
─这是一个用于多个专案中音频和视频的解码器库,以及 libavformat ——一个音频与视频格式转换库。
Free”或者“Fast Fourier”等意思,"FFmpeg"的项目负责人回信说“Just for the record, the original meaning of "FF" in FFmpeg is "Fast Forward"...”
git-f514695 32-bit Shared (Latest)
-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)
-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
-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
QString inputPath = ui->videopathLineEdit->text();
QFile sourceFile(inputPath);
if(!sourceFile.exists()){
QMessageBox::information(this,QString::fromUtf8("提示"),QString::fromUtf8("找不到源文件"));
return;
}
if(destFile.exists())
destFile.remove();
}
QString len= ui->videoLengthTimeEdit->time().toString("hh:mm:ss");
QStringList arguments;
arguments << "-i" << inputPath << "-r" << "25"<<"-ss";
arguments <
connect(clipProcess,SIGNAL(finished(int)),this,SLOT(clipVideoFinished(int)));