"FFmpeg Mastering" study notes (a)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/asd501823206/article/details/92798749

EDITORIAL

Recently read "FFmpeg from entry to the master," this book, combined with Raytheon's blog, audio and video - knowledge and learning in the learning process, also recorded some summary. Because it is watched in mind, so some points in time to see the back of, in turn, need to sort out front. I used the proper way cloud notes written in markdown can not add pictures, so we put out this distribution. Follow-up will be a step by step for content and layout optimization, if you are this messy hot content to the eyes, please understand ha ha ha ~

2019.06.18

The first chapter FFmpeg Introduction
Chapter FFmpeg tool base


Brief introduction

The book begins with a few examples of the operation, so read operation on the FFmpeg has an intuitive understanding. Several methods, for example, the following:

Longitudinal half mirror inversion
ffmpeg -i 1.jpg -vf "split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip];[main][flip] overlay=0:H/2" 2.jpg

Here Insert Picture Description
Meanings indicated above operation: The main picture is divided into two portions and tmp, tmp taken on half of the inversion, merge in the lower half position

Artwork

Here Insert Picture Description

Renderings

Here Insert Picture Description

ffmpeg -i input.mp4 output.avi  ->  ffmpeg -i input.mp4 -f avi out.dat

The main work flow of ffmpeg

1 decapsulates demuxing
2 decoding Decoding
. 3 encoding Encoding
. 4 Package Muxing

Which need to go through six steps

1 读取输入源
2 进行音视频的解封装 (调用libavformat中的接口实现)
3 解码每一帧音视频数据 (调用libavcodec中的接口实现)
3.5 转换参数
4 编码每一帧音视频数据(调用libavcodec中的接口实现)
5 进行音视频重新封装(调用libavformat中的接口实现)
6 输出到目标

除了ffmpeg(提供转码、转封装等功能),还有ffplay(负责播放相关)和ffprobe(多媒体分析器)

ffprobe -show_streams 1.mp4

Here Insert Picture Description

ffmpeg常用命令
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
ffmpeg的查询
ffmpeg -decoders   (类似:ffmpeg --encoders)

Decoders:
V… = Video
A… = Audio
S… = Subtitle
.F… = Frame-level multithreading
…S… = Slice-level multithreading
…X… = Codec is experimental
…B. = Supports draw_horiz_band
…D = Supports direct rendering method 1
V…D     012v    Uncompressed 4:2:2 10-bit
V…D     4xm      4X Movie
V…D     8bps      QuickTime 8BPS video
V…D     aasc      Autodesk RLE
V…D     aic      Apple Intermediate Codec
V…D     alias_pix      Alias/Wavefront PIX image
V…D     amv      AMV Video
V…D     anm      Deluxe Paint Animation
V…D     ansi      ASCII/ANSI art
VF…D   apng      APNG (Animated Portable Network Graphics) image

第一列包含6个字段,第一个字段用来表示此编码器为音频、视频还是字幕,第二个字段表示帧级别的多线程支持,第三个字段表示段级别的多线程,第四个字段表示该编码器为实验版本,第五个字段表示draw horiz band模式支持,第六个字段表示直接渲染模式支持
第二列是编码格式
第三列是编码格式的详细说明

ffmpeg -filters  (滤镜)

… acrossfade      AA->A      Cross fade two input audio streams.
T… adelay         A->A      Delay one or more audio channels.
… aecho         A->A      Add echoing to the audio.
… aeval          A->A      Filter audio signal according to a specified expression.
T… afade        A->A      Fade in/out input audio.
… aformat        A->A      Convert the input audio to one of the specified formats.
… ainterleave       N->A      Temporally interleave audio inputs.
… allpass        A->A      Apply a two-pole all-pass filter.
… amerge        N->A      Merge two or more audio streams into a single multi-channel stream.
… amix         N->A      Audio mixing.
… anull         A->A      Pass the source unchanged to the output.
T… apad         A->A      Pad audio with silence.
… aperms        A->A      Set permissions for the output audio frame.
… aphaser       A->A      Add a phasing effect to the audio.
… aresample      A->A      Resample audio data.
… areverse        A->A      Reverse an audio clip.
… aselect         A->N      Select audio frames to pass in output.
… asendcmd       A->A      Send commands to filters.
… asetnsamples     A->A      Set the number of samples for each output audio frames.
… asetpts        A->A      Set PTS for the output audio frame.
… asetrate        A->A      Change the sample rate without altering the data.
… asettb        A->A      Set timebase for the audio output link.
… ashowinfo      A->A      Show textual information for each audio frame.
… asplit        A->N      Pass on the audio input to N audio outputs.
… astats        A->A      Show time domain statistics about audio frames.
… astreamsync    AA->AA      Copy two streams of audio data in a configurable order.
… asyncts       A->A      Sync audio data to timestamps
…C atempo      A->A      Adjust audio tempo.
… atrim        A->A      Pick one continuous section from the input, drop the rest.
… azmq         A->A      Receive commands through ZMQ and broker them to filters.
… bandpass      A->A      Apply a two-pole Butterworth band-pass filter.
… bandreject      A->A      Apply a two-pole Butterworth band-reject filter.
… bass         A->A      Boost or cut lower frequencies.
… biquad        A->A      Apply a biquad IIR filter with the given coefficients.
… bs2b          A->A      Bauer stereo-to-binaural filter.
… channelmap      A->A      Remap audio channels.
… channelsplit      A->N      Split audio into per-channel streams.
… chorus        A->A      Add a chorus effect to the audio.
… compand      A->A      Compress or expand audio dynamic range.
T… dcshift        A->A      Apply a DC shift to the audio.
… dynaudnorm     A->A      Dynamic Audio Normalizer.
… earwax        A->A      Widen the stereo image.
… ebur128       A->N      EBU R128 scanner.
… equalizer      A->A      Apply two-pole peaking equalization (EQ) filter.
… flanger        A->A      Apply a flanging effect to the audio.
… highpass      A->A      Apply a high-pass filter with 3dB point frequency.
… join          N->A      Join multiple audio streams into multi-channel output.
…C ladspa      N->A      Apply LADSPA effect.
… lowpass      A->A      Apply a low-pass filter with 3dB point frequency.
… pan          A->A      Remix channels with coefficients (panning).
… replaygain      A->A      ReplayGain scanner.
… resample      A->A      Audio resampling and conversion.
… sidechaincompress   AA->A      Sidechain compressor.
… silencedetect     A->A      Detect silence.
… silenceremove    A->A      Remove silence.
… treble        A->A      Boost or cut upper frequencies.
T.C volume      A->A      Change input volume.

(首先请原谅我的弟弟排版,尽力了。。)

第一列总共有三个字段,第一个字段是时间轴支持,第二个字段是分片线程处理支持,第三个字段是命令支持
第二列是滤镜名
第三列是转换方式,如音频转音频,视频转视频,创建音频,创建视频等
第四列是滤镜作用说明

查看ffmpeg支持的具体某一种demuxer、muxer类型,可以通过ffmpeg -h查看该类型的详细参数
ffmpeg -h muxer=flv

Muxer flv [FLV (Flash Video)]:
  Common extensions: flv.
  Mime type: video/x-flv.
  Default video codec: flv1.
  Default audio codec: mp3.

ffmpeg的封装转换 (参数 书P37)
ffmpeg的基本转码原理

ffmpeg工具的主要用途为编码、解码、转码以及媒体格式转换。

ffmpeg -i 1.mp4 -vcodec mpeg4 -b:v 200k -r 15 -an output2.avi

Here Insert Picture Description

以上命令中参数含义:
1.转封装格式从mp4转为avi
2.视频编码从h264转换为mpeg4格式
3.视频码率从原来的16278 kb/s转换为200 kb/s
4.视频帧率从原来的24.15 fps转换为15 fps
5.转码后的文件不包括音频(-an参数)

ffprobe常用命令

ffmpeg-多媒体处理工具 ffprobe-多媒体查看工具

ffprobe -show_packets 1.mp4

Here Insert Picture Description

 ffprobe -show_format 1.mp4

Here Insert Picture Description

ffprobe -show_frames 1.mp4

Here Insert Picture Description
[FRAME]
media_type=video 帧的类型
stream_index=0 帧所在的索引区域
key_frame=1 是否为关键帧
pkt_pts=0 Frame包的pts
width=1080 帧显示的宽度
height=2248 帧显示的高度
pix_fmt=yuv420p 帧的图像色彩格式
pict_type=I 帧类型
[/FRAME]

ffprobe -show_streams 1.mp4

Here Insert Picture Description
[STREAM]
index=0 流所在的索引区域
codec_name=h264 编码名
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 编码全名
profile=Baseline 编码的profile
codec_type=video 编码类型
codec_time_base=1/180000 编码的时间戳计算基础单位
codec_tag_string=avc1 编码的标签数据
coded_width=1088 图像的宽度
coded_height=2256
has_b_frames=0 包含B帧的信息
pix_fmt=yuv420p 图像显示的色彩格式
r_frame_rate=145/6 实际帧率
avg_frame_rate=5000/207 平均帧率
time_base=1/90000 事件基数(用来进行timestamp计算)
bit_rate=16278017 码率
max_bit_rate=N/A 最大码率
nb_frames=165 帧数
[/STREAM]

ffprobe默认使用key-value的格式输出,可以通过-of xml(ini,json,csv,flat)来进行相应的格式输出,例如:

ffprobe -of json -show_streams 1.mp4

-select_streams可以选择值馋看音频(a)、视频(v)、字幕(s)信息

ffprobe -show_frames -select_streams v -of json 1.mp4
ffplay

As the player may be a graphical analysis tool as many audio and video data, you can see the estimated direction of a video image, audio data, etc. through waveform ffplay

parameter:

x forcibly set the video display window width
Y
S provided a video display width and height
fs force full-screen display
an audio shielding
vn shield video
sn shield subtitle
ss positioned drag as second set
t to video / audio playback length
bytes provided targeting drag dynamic policy, 0 to not drag a draggable, -1 automatically
nodisp off graphical display window
format using the set f Force parsing
window_title title of the window display is provided
af filters disposed audio
codec provided enforce the codec decoding
autorotate video automatic rotation

Visual analysis tool

ffplay -showmode 1 1.mp3

ffplay -vismv pf 1.mp4     查看B帧和P帧的预测信息

pf P-frame forward motion estimation display
bf B-frame forward motion estimation display
bb B-frame motion estimation rearwardly display
Here Insert Picture Description

Here Insert Picture Description

How to Play decodes each macroblock
ffplay -debug vis_mb_type 1.mp4

Here Insert Picture Description
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/asd501823206/article/details/92798749
Recommended