ffmpeg视频转码压缩

1、准备工作:

http://ffmpeg.org/download.html
下载之后,正常安装,然后将bin目录加入全局环境变量;
查看是否安装好,以及软件版本:

ffmpeg -version

ffmpeg视频转码压缩_第1张图片

官方文档:
http://ffmpeg.org/ffmpeg.html

压缩视频之前,我们要了解原视频的详细信息,利用MediaInfo可以查看视频的详细信息;
具体如下:
ffmpeg视频转码压缩_第2张图片

2、关键的参数就几个:

  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. 音频部分的位深度:单个声道的采样数据大小

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

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

4、举例子:

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

ffmpeg -i C:\Users\10375\Desktop\learner-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

你可能感兴趣的:(Windows,Linux)