ffmpeg 入门_python入门笔记

ffmpeg 入门_python入门笔记写在前面最近在读《FFmpeg从入门到精通》这本书,结合着雷神的博客,学习音视频的知识~在学习的过程中,也记录了一些摘要。因为是边看边记的,所以一些要点在看到后面的时候,需要反过来整理前面的。我用有道云笔记写的markdown没法加图片,所以就先把这部分发了出来。后续会针对内容和排版一步步的优化,如果你被这凌乱的内容辣到了眼睛,请谅解哈哈哈~2019.06.18第一章+第二章知识点(未…

大家好,又见面了,我是你们的朋友全栈君。

写在前面

最近在读《FFmpeg从入门到精通》这本书,结合着雷神的博客,学习音视频的知识~ 在学习的过程中,也记录了一些摘要。因为是边看边记的,所以一些要点在看到后面的时候,需要反过来整理前面的。我用有道云笔记写的markdown没法加图片,所以就先把这部分发了出来。后续会针对内容和排版一步步的优化,如果你被这凌乱的内容辣到了眼睛,请谅解哈哈哈~

2019.06.18

第一章 FFmpeg简介
第二章 FFmpeg工具使用基础


简介

书中开头用几个实例操作,让读着对FFmpeg的操作有一个直观的认识。例如以下的几个方法:

纵向镜像反转一半
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

在这里插入图片描述
上面操作的含义:将图片分为main和tmp两部分,截取tmp的上半部分,反转,合并时位置在下半部分

原图

在这里插入图片描述

效果图

在这里插入图片描述

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

ffmpeg的主要工作流程

1 解封装 Demuxing
2 解码 Decoding
3 编码 Encoding
4 封装 Muxing

其中需要经过六个步骤

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

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

ffprobe -show_streams 1.mp4

在这里插入图片描述

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

在这里插入图片描述

以上命令中参数含义:
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

在这里插入图片描述

 ffprobe -show_format 1.mp4

在这里插入图片描述

ffprobe -show_frames 1.mp4

在这里插入图片描述
[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

在这里插入图片描述
[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

可以作为播放器,也可以作为很多音视频数据的图形化分析工具,通过ffplay可以看到视频图像的运动估计方向、音频数据的波形等

参数:

x  强制设置视频显示窗口的宽度
y
s  设置视频显示的宽高
fs  强制全屏显示
an  屏蔽音频
vn   屏蔽视频
sn  屏蔽字幕
ss  根据设置的秒进行定位拖动
t   设置播放视频/音频的长度
bytes  设置定位拖动的策略,0为不可拖动,1为可拖动,-1为自动
nodisp  关闭图形化显示窗口
f    强制使用设置的格式进行解析
window_title   设置显示窗口的标题
af   设置音频的滤镜
codec  强制使用设置的codec进行解码
autorotate  自动旋转视频

可视化分析工具

ffplay -showmode 1 1.mp3

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

pf P帧向前运动估计显示
bf B帧向前运动估计显示
bb B帧向后运动估计显示
在这里插入图片描述

在这里插入图片描述

播放器如何解码每个宏块
ffplay -debug vis_mb_type 1.mp4

在这里插入图片描述
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/124911.html原文链接:https://javaforall.net

(0)
上一篇 2022年4月19日 下午9:40
下一篇 2022年4月19日 下午9:40


相关推荐

  • badboy设置中文_badboy中文手册

    badboy设置中文_badboy中文手册BadBoy 手册一 badboy 简介 Badboy 监控 internetexpl 的活动 提供录制 回放功能 录制功能 badboy 窗口的顶部显示当前是否处于录制状态 如果点击 play 按钮 badboy 自动关闭录制功能 等到 play 结束后 可以点击 recording 按钮 继续录制脚本 Remark 必须等到上一步的 request 处理完毕后 才能点击发送下一个 request 否则下一个 reques

    2026年3月19日
    2
  • WPF 实现测量显示文本长度

    WPF 实现测量显示文本长度

    2021年6月14日
    173
  • spring boot jedis_spring整合redis详解

    spring boot jedis_spring整合redis详解1.1.Jedis所需要的jar包redis.clientsjedis3.2.01.1.连接Redis注意事项 禁用Linux的防火墙:Linux(CentOS7)里执行命令systemctlstop/disablefirewalld.serviceredis.conf中注释掉bind127.0.0.1,然后protected-modeno1.2.Jedis常用操作1.2.1.创建动态的工程1.2.1.创建测试程序publicstat

    2025年10月15日
    3
  • acwing-9. 分组背包问题(分组背包)

    acwing-9. 分组背包问题(分组背包)有 N 组物品和一个容量是 V 的背包。每组物品有若干个,同一组内的物品最多只能选一个。每件物品的体积是 vij,价值是 wij,其中 i 是组号,j 是组内编号。求解将哪些物品装入背包,可使物品总体积不超过背包容量,且总价值最大。输出最大价值。输入格式第一行有两个整数 N,V,用空格隔开,分别表示物品组数和背包容量。接下来有 N 组数据:每组数据第一行有一个整数 Si,表示第 i 个物品组的物品数量;每组数据接下来有 Si 行,每行有两个整数 vij,wij,用空格隔开,分别表示第 i

    2022年8月9日
    6
  • 掌握SQLite数据库迁移:轻松应对版本更新与数据同步

    掌握SQLite数据库迁移:轻松应对版本更新与数据同步

    2026年3月14日
    3
  • jar包提示没有主清单属性_jar什么意思

    jar包提示没有主清单属性_jar什么意思看pom.xml。将同事写的一个java项目打包成jar包,发布,运行提示没有主清单属性。究其原因,在pom.xml里的build设置。原设置:<!–maven的插件–><build><!–配置java版本不配置的话默认父类配置的是1.6–><pluginManagement><plugins><plugin&g

    2025年9月13日
    14

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号