FFmpeg 快速上手:命令行详解、工具、教程、电子书

FFmpeg 简介

 

FFmpeg 是一个开源的音视频处理工具,诞生已22年。它可以用来处理音视频的编解码、格式转换、剪辑、合并、抽取、压缩、解压缩、滤镜、字幕等等。它可以在 Windows、Linux、Mac 等多种平台上使用。

FFmpeg由法国天才程序员Fabrice Bellard在2000年时开发出初版。不过后来 FFmpeg 社区出现分裂,包括 Fabrice Bellard 在内的部分 FFmpeg 开发者决定脱离原组织重新创建新项目,称作 libav。后来 FFmpeg 项目负责人 Michael Niedermayer 将 libav 的代码合并到了 FFmpeg。

除了 FFmpeg,其他许多知名开源项目,诸如 TinyCC、QEMU、JSLinux 以及比较新的 QuickJS 均出自 Fabrice Bellard 之手,详情查看  https://bellard.org/

FFmpeg 单词中的 “FF” 指的是 “Fast Forward(快速前进)”,MPEG 是制定国际标准的组织,负责制定影音压缩及传输的规格标准。

FFmpeg 耻辱柱

FFmpeg 最被人熟知的还有它创建的 “耻辱柱”(已于2014年下线,不过其 网页源码[1] 仍保留这些名单)。因为 FFmpeg 属于自由软件,采用了 LGPL 和 GPL 许可证(具体依据所选的组件),所以任何人都可以在遵守协议的情况下自由使用。不过很多播放软件使用了 FFmpeg 的代码后并没有遵守开源协议公开任何源代码。FFmpeg 社区便将违反开源协议的公司、组织和个人网站贴在 “耻辱柱”。韩国播放软件 KMPlayer 以及国产播放器暴风影音、QQ 影音都曾上过榜。

FFmpeg 安装

Windows

Windows 平台上 FFmpeg 安装比较简单,只需要下载 FFmpeg 的压缩包,解压后将 bin 目录添加到环境变量即可。

下载地址:Download FFmpeg[2]

Linux

Linux 平台上 FFmpeg 安装比较简单,只需要使用包管理器安装即可。

Ubuntu/Debian:

sudo apt install ffmpeg

CentOS/RHEL:

sudo yum install ffmpeg

Arch Linux:

sudo pacman -S ffmpeg

MacOS

brew install ffmpeg

FFmpeg 工作流程

ffmpeg的主要工作流程相对比较简单,具体如下。

  1. \1. 解封装(Demuxing)
  2. \2. 解码(Decoding)
  3. \3. 编码(Encoding)
  4. \4. 封装(Muxing)

具体为6个步骤:

  1. \1. 读取输入源
  2. \2. 进行音视频的解封装
  3. \3. 解码每一帧音视频数据
  4. \4. 编码每一帧音视频数据
  5. \5. 进行音视频的重新封装
  6. \6. 输出到目标

FFmpeg工作流程

FFmpeg 命令

FFmpeg 命令格式

ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

举个例子,以下命令将 input.mp4 通过H.264编码器转码为 output.mp4:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset veryfast output.mp4

其中 -i 表示输入文件,-c:v 用于指定视频编码器, libx264 是 H.264 编码的一个实现,-crf 表示视频质量,-preset veryfast 表示预设的编码速度,output.mp4 表示输出文件。

FFmpeg 命令参数

通过ffmpeg -h可以看到ffmpeg常见的命令大概分为6个部分,具体如下:

  • • ffmpeg信息查询部分
  • • 公共操作参数部分
  • • 文件主要操作参数部分
  • • 视频操作参数部分
  • • 音频操作参数部分
  • • 字幕操作参数部分

常用参数如下:

  • • -i:输入文件
  • • -y:覆盖输出文件
  • • -f:指定输出文件格式
  • • -c:指定编解码器
  • • -c copy 表示音视频保持原有编码
  • • -b:指定比特率
  • • -s:指定分辨率
  • • -r:指定帧率
  • • -t:指定转码时长
  • • -ss:指定转码开始时间
  • • -acodec:指定音频编码器
  • • -vcodec:指定视频编码器
  • • -ac:指定音频通道数
  • • -ar:指定音频采样率
  • • -ab:指定音频比特率
  • • -vn 禁用视频
  • • -an 禁用音频
  • • -map:指定转码流
  • • -metadata:指定输出文件元数据
  • • -threads:指定线程数
  • • -preset:指定编码速度
  • • -crf:指定视频质量
  • • -pix_fmt:指定像素格式
  • • -filter_complex:指定复杂滤镜
  • • -vf:指定简单滤镜
  • • -hide_banner 所有FFmpeg的工具通常会显示版权声明,建置(build)选项和程式库(library)版本。这个选项可以用来隐藏这些讯息。

FFmpeg 常用命令

视频转码(指定分辨率)

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset veryfast -s 1280x720 output.mp4

提取音频

ffmpeg -i input.mp4 -vn -acodec copy output.aac

截取视频

ffmpeg -i input.mp4 -ss 00:00:10 -t 00:00:10 -c copy output.mp4

裁剪画面

ffmpeg -i input.mp4 -filter:v "crop=1280:720:0:0" output.mp4

旋转画面

ffmpeg -i input.mp4 -vf "transpose=1" output.mp4

添加水印

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output.mp4

添加字幕

ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt" output.mp4

合并多个视频到一个视频

list.txt 即为视频列表,每行一个视频文件名

ffmpeg -f concat -i list.txt -c copy output.mp4

合并视频音频

ffmpeg -i input.mp4 -i input.aac -c copy output.mp4

FFmpeg 命令行生成器

FFmpeg 涉及到很多参数,如果每次都要记住这些参数,那就太麻烦了,所以我们可以使用在线的命令行生成器,这样就可以很方便的生成命令行了。

FFmpeg Commander[3]

FFmpeg Commander

FFmpeg Command Generator[4]

FFmpeg Command Generator

ffmpeg - CMD Generator[5]

ffmpeg string creator[6]

FFmpeg GUI

命令行写起来很麻烦,所以我们可以使用 GUI 工具来代替命令行。这里介绍几个非常好用的 GUI 工具。

handbrake

HandBrake 是一个由志愿者构建的开源工具,用于将视频从几乎任何格式转换为精选的现代、广泛支持的编解码器。

HandBrake: Open Source Video Transcoder[7]

HandBrake

HandBrake Documentation — Supported source formats[8]

One of HandBrake’s strengths is its ability to open a wide variety of video formats. HandBrake uses FFmpeg under the hood and generally can open whatever FFmpeg will, in addition to disc-based formats like DVD and Blu-ray.

QuickCut

Quick Cut 是一款轻量、强大、好用的视频处理软件。它是一个轻量的工具,而不是像 Davinci Resolve、Adobe Premiere 那样专业的、复杂的庞然大物。Quick Cut 可以满足普通人一般的视频处理需求:压缩视频、转码视频、倒放视频、合并片段、根据字幕裁切片段、自动配字幕、自动剪辑……

Quick Cut 发行版 - http://Gitee.com[9]

Quick Cut

Shutter Encoder

我个比较喜欢的一个 GUI 工具,批量转换很方便。

Shutter Encoder encoding|converting video FREE PC|Mac[10]

Shutter Encoder

ShanaEncoder

ShanaEncoder Download - Shana[11]

QWinFF

Home | QWinFF[12]

ciano

robertsanseries/ciano: A multimedia file converter focused on simplicity.[13]

App Ciano - Robert San[14]

FFaudioConverter

Release FFaudioConverter 0.31.0 · Bleuzen/FFaudioConverter[15]

FFmpeg 教程

FFmpeg 教程

哔哩哔哩搜索UP主:音视频开发进阶

FFmpeg 电子书

文末名片免费领取音视频开发学习资料,内容包括(C/C++,Linux 服务器开发,FFmpeg ,webRTC ,rtmp ,hls ,rtsp ,ffplay ,srs)以及音视频学习路线图等等。

 

FFmpeg从入门到精通

FFmpeg从入门到精通

本书是一本介绍FFmpeg的实战技术指南,全书共10章,分为两个部分。部分(第1~7章)为FFmpeg的命令行使用篇,介绍了FFmpeg的基础组成部分、FFmpeg工具使用、FFmpeg的封装操作、FFmpeg的转码操作、FFmpeg的流媒体操作、FFmpeg的滤镜操作、FFmpeg的设备操作。第二部分(第8~10章)为FFmpeg的API使用篇,介绍了FFmpeg封装部分的API使用操作、FFmpeg编解码部分的API使用操作,FFmpeg滤镜部分的API使用操作,相关操作均以实例方式进行说明,包括新API及旧API的操作。

Understanding FFmpeg with source code FFMPEG Fundementals

Understanding FFmpeg with source code FFMPEG Fundementals

In this book, we will review the ffmpeg source code and learn about ffmpeg's capabilities. In the first part, we will consider ffmpeg in general terms. In the second part, we will discuss the ffmpeg methods related to video. In this section, we will also examine the ffmpeg filters closely.

In the third part, we will learn the details and methods of audio. In the fourth and fifth part, we will learn about Interlaced video and I-B-P frames. In the sixth part, we will learn what is codec and how does ffmpeg handle it. In the seventh part, we will try to explain how video encoding and audio encoding take place in ffmpeg, with sample codes. In the eighth part, we will try to explain how decoding works in fmmpeg and how to make a sample player with the help of SDL. In parts 9, 10 and 11, we will show the video and audio multiplexing methods. In the twelfth part, how to convert a video file into another format. We will learn all the transcoding steps. In the thirteenth part, we will learn all streaming protocols. In the last part, we will learn how to manage video and audio devices with ffmpeg.

FFMPEG - From Zero to Hero

FFMPEG - From Zero to Hero

If you ever wondered how the developers of YouTube or Vimeo cope with billions of video uploads or how Netflix processes its catalogue at scale or, again, if you want to discover how to create and develop your own video platform, you may want to know more about FFMPEG.

FFMPEG Quick Hacks

FFMPEG Quick Hacks

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值