ffmpeg合并、压缩、截取视频及提取音频教程

您所在的位置:网站首页 ffmpeg合并视频命令 ffmpeg合并、压缩、截取视频及提取音频教程

ffmpeg合并、压缩、截取视频及提取音频教程

2022-05-23 09:18| 来源: 网络整理| 查看: 265

压缩视频之前,我们要了解原视频的详细信息,利用MediaInfo可以查看视频的详细信息;具体如下:

关键的参数就几个

1.视频尺寸:指的就是视频的分辨率,常见的分辨率有4096*2304,1920*1080,720*576等。

2.视频编码:视频编码方式就是指通过特定的压缩技术,将某个视频格式的文件转换成另一种视频格式文件的方式。视频编码格式常见到的有:MPEG-2 TS、Divx、Xvid、H.264、WMV-HD和VC-1。

3.音频编码:音频编码方式指通过特定的压缩技术对音频数据进行处理的方法。

4.帧率:帧率(即视频更新率)是用于测量显示帧数的量度。测量单位为“每秒显示帧数”(Frame Per Second,FPS,帧率)或“赫兹”,单位用FPS用来描述视频每秒播放多少帧,而单位用赫兹用来描述显示器的画面每秒更新多少次。 一般帧率越高,视频画面越流畅。

5.比特率:指每秒传送的比特(bit)数,即每秒传输的文件大小。比特率规定使用“比特每秒”(bit/s 或 bps)为单位。比特率越高,每秒传送的数据越大。

6.采样率:采样率的单位是Hz,表示每秒采样的次数。单位时间内取样率越大,精度就越高,处理过的视频文件就越接近没有处理过的视频文件。

7.码率:码率就是数据传输时单位时间传送的数据位数,一般我们用的单位是kbps即千位每秒。码率与体积成正比:码率越大,体积越大;码率越小,体积越小。由于文件体积与取样率是成正比的,所以几乎所有的编码格式都想用最低的码率达到最少的失真,“码率”就是失真度,码率越高越清晰,反之则画面粗糙而且马赛克多。

8.视频部分的位深度:用于指定图像中的每个像素可以使用的颜色信息数量,用“位即bit”为单位。

9.音频部分的位深度:单个声道的采样数据大小

一般来说音频影响不大,我们就重点说视频压缩

压缩用到的参数:-i 输入文件的路径或者url;-s 设置输出文件的分辨率,wxh;-b:v 输出文件的码率,一般500k左右即可,人眼看不到明显的闪烁,这个是与视频大小最直接相关的;

举例子

转换视频格式,顺便压缩:

ffmpeg -i C:Users10375Desktoplearner-demo.m4v -b:v 400k -s 960x540 newfiles/learner-demo.mp4

经过上面的解释应该知道是啥意思了,将桌面一个叫learner-demo.m4v的视频转换成mp4格式,并且放到当前问目录下的newfiles文件夹下面,设置输出视频的分辨率为960x540,码率为400k。我为什么这么设置,是有原因的,这个视频动态画面较少,类似于翻ppt,所以可以设置低一点,原视频是1920x1080的分辨率,但是实际上我们网站放的时候960的宽度就行了。这就是最基本的用法了,这个软件是非常强大的,视频频也是可以转换,剪切、截图的,音频也一样,而且还可以分离音视频。压缩完成之后,视频大小变为原来的1/4,而且还是很清楚!比市面上成品的压缩软件强太多!!!高级用法:

批量转换视频:

http://blog.csdn.net/zhezhebie/article/details/79263537

详细参数:

Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfi le}... Getting help: -h -- print basic options -h long -- print more options -h full -- print all options (including all format and codec specific option s, very long) -h type=name -- print all options for the named decoder/encoder/demuxer/muxe r/filter/bsf See man ffmpeg for detailed description of the options. Print help / information / capabilities: -L show license -h topic show help -? topic show help -help topic show help --help topic show help -version show version -buildconf show build configuration -formats show available formats -muxers show available muxers -demuxers show available demuxers -devices show available devices -codecs show available codecs -decoders show available decoders -encoders show available encoders -bsfs show available bit stream filters -protocols show available protocols -filters show available filters -pix_fmts show available pixel formats -layouts show standard channel layouts -sample_fmts show available audio sample formats -colors show available color names -sources device list sources of the input device -sinks device list sinks of the output device -hwaccels show available HW acceleration methods Global options (affect whole program instead of just one file: -loglevel loglevel set logging level -v loglevel set logging level -report generate a report -max_alloc bytes set maximum size of a single allocated block -y overwrite output files -n never overwrite output files -ignore_unknown Ignore unknown stream types -filter_threads number of non-complex filter threads -filter_complex_threads number of threads for -filter_complex -stats print progress report during encoding -max_error_rate maximum error rate ratio of errors (0.0: no errors, 1.0: 100% e rrors) above which ffmpeg returns an error instead of success. -bits_per_raw_sample number set the number of bits per raw sample -vol volume change audio volume (256=normal) Per-file main options: -f fmt force format -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 -to time_stop record or transcode stop time -fs limit_size set the limit file size in bytes -ss time_off set the start time offset -sseof time_off set the start time offset relative to EOF -seek_timestamp enable/disable seeking by timestamp with -ss -timestamp time set the recording timestamp ('now' to set the current time) -metadata string=string add metadata -program title=string:st=number... add program with specified streams -target type specify target file type ("vcd", "svcd", "dvd", "dv" or "dv5 0" with optional prefixes "pal-", "ntsc-" or "film-") -apad audio pad -frames number set the number of frames to output -filter filter_graph set stream filtergraph -filter_script filename read stream filtergraph description from a file -reinit_filter reinit filtergraph on input parameter changes -discard discard -disposition disposition Video options: -vframes number set the number of video frames to output -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 -vn disable video -vcodec codec force video codec ('copy' to copy stream) -timecode hh:mm:ss[:;.]ff set initial TimeCode value. -pass n select the pass number (1 to 3) -vf filter_graph set video filters -ab bitrate audio bitrate (please use -b:a) -b bitrate video bitrate (please use -b:v) -dn disable data Audio options: -aframes number set the number of audio frames to output -aq quality set audio quality (codec-specific) -ar rate set audio sampling rate (in Hz) -ac channels set number of audio channels -an disable audio -acodec codec force audio codec ('copy' to copy stream) -vol volume change audio volume (256=normal) -af filter_graph set audio filters Subtitle options: -s size set frame size (WxH or abbreviation) -sn disable subtitle -scodec codec force subtitle codec ('copy' to copy stream) -stag fourcc/tag force subtitle tag/fourcc -fix_sub_duration fix subtitles duration -canvas_size size set canvas size (WxH or abbreviation) -spre preset set the subtitle options to the indicated preset ffmpeg截取视频 按时间截取 ffmpeg -i ./SN.mp4 -vcodec copy -acodec copy -ss 00:00:00 -to 00:00:05 ./cutout1.mp4 -y 按帧数截取 ffmpeg -i ./input.mp4 -vf "select=between(n,20,200)" -y -acodec copy ./output.mp4 举例 ffmpeg -i ./plutopr.mp4 -vcodec copy -acodec copy -ss 00:00:10 -to 00:00:15 ./cutout1.mp4 -y

-ss time_off      set the start time offset 设置从视频的哪个时间点开始截取,上文从视频的第10s开始截取

-to 截到视频的哪个时间点结束。上文到视频的第15s结束。截出的视频共5s.

如果用-t 表示截取多长的时间如 上文-to 换位-t则是截取从视频的第10s开始,截取15s时长的视频。即截出来的视频共15s.

注意的地方是:

如果将-ss放在-i ./plutopr.mp4后面则-to的作用就没了,跟-t一样的效果了,变成了截取多长视频。一定要注意-ss的位置。

参数解析

-vcodec copy表示使用跟原视频一样的视频编解码器。

-acodec copy表示使用跟原视频一样的音频编解码器。

-i 表示源视频文件

-y 表示如果输出文件已存在则覆盖。

ffmpeg提取音频

如何把视频文件中的音频数据提取出来,网络上有不少音频提取工具,但作为技术人员提到音视频处理,肯定会想到FFmpeg。本文介绍了如何基于FFmpeg从视频中提取音频,然后将音频保存为mp3格式的音频文件。

1.执行音频提取 root@jackfan: ~$ ffmpeg -i test.mp4 -f mp3 -vn test.mp3

参数解释:

-i 表示input,即输入文件

-f 表示format,即输出格式

-vn表示vedio not,即输出不包含视频

对比源视频文件和提取得到的音频文件大小,可以看到源视频文件为约23M,而提取出来的音频文件大小为3M。

root@jackfan: ~$

2.获取视频扩展信息

FFmpeg还提供了很多有用的工具可以查看和处理音视频文件,如:

查看视频文件的音视频编解码格式,视频时长,比特率等,如下:

root@jackfan: ~$ ffmpeg -i test.mp3


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3