整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

ffmpeg命令行工具

ffmpeg命令行工具

于ffmpeg命令行的使用 之前一直都是通过百度(惭愧),一边找 一边用 感觉写起来比较麻烦 就在这记录下 方便以后温习

我们都知道从官网下来的可以直接运行的程序有三个 一个是ffmpeg.exe ffplay.exe ffprobe.exe

关于ffmpeg的官网里边 一般是提供三种(static shared dev)

第一个static是提供了之前说的那三个程序 并且人家把各个dll集成了进去 导致程序的大小比较大

第二个shared 也提供了那三个程序 只不过大小就小得多 因为它还提供了各种dll

第三个就完全适用于开发人员 提供了lib以及头文件

这边我们就直接来说说提供的那三个程序怎么用(直接点是没用的哈 直接在命令行里边用就好)

ffmpeg是用来转码的工具 ffplay是用来播放的 ffprobe是用来查看文件格式的

**************************************************************************************************************************************

首先我们来看下ffmpeg

http://ffmpeg.org/ffmpeg.html 官方说明

我自己输入 ffmpeg -h

首先会显示ffmpeg的版本 以及编译这个用的GCC的版本 以及编译之前configure的选项 之后就是依赖各种库的版本

基本的信息显示完了以后 就会告诉你怎么使用

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

当然我们也可以活用help信息

Getting help:

-h -- print basic options 会打印基本的选项

-h long -- print more options 会打印更多的选项

-h full -- print all options (including all format and codec specific options, very long) 打印所有的选项(包括所有格式和编解码器特定选项,很长)

-h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter 可以打印指定的选项

See man ffmpeg for detailed description of the options. 当然了你要想看得仔细 有关选项的详细描述,请参阅man ffmpeg。

下面我们就来看看各个选项(之后再来一个个试)

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 显示支持的设备(这里显示的只是很大的范围 并不会显示具体的设备 比如我输入ffmpeg -devices 只会像是下面输出的那样)

Devices:

D.=Demuxing supported 可以理解为输入设备(我们可以这么理解 解封装是获取流 这个设备其实干的也是获取流的事)

.E=Muxing supported 可以理解为输出设备(同理 输出设备是使用流的 和封装类似)

--

E caca caca (color ASCII art) output device

D dshow DirectShow capture

D lavfi Libavfilter virtual input device

E sdl,sdl2 SDL2 output device

D vfwcap VfW video capture

-codecs show available codecs 显示支持的编解码器(看清楚 是编解码器)

需要注意的就是前面的那些什么 D,E,V,A,S,I,L,S的一类的意思

D.....=Decoding supported 解码

.E....=Encoding supported 编码

..V...=Video codec 视频

..A...=Audio codec 音频

..S...=Subtitle codec 字幕

...I..=Intra frame-only codec 帧内编解码器

....L.=Lossy compression 有损

.....S=Lossless compression 无损

-decoders show available decoders 显示支持的解码器

-encoders show available encoders 显示支持的编码器

-bsfs show available bit stream filters 显示可用的比特流过滤器

-protocols show available protocols 显示支持的协议

-filters show available filters 显示可用的过滤器(需要注意下下面的几个的意思 现在我还是没有搞懂什么意思 要去找找代码看看了)

Filters:

T..=Timeline support

.S.=Slice threading

..C=Command support

A=Audio input/output

V=Video input/output

N=Dynamic number and/or type of input/output

|=Source or sink filter

-pix_fmts show available pixel formats 显示可用像素格式

Pixel formats:

I....=Supported Input format for conversion 支持转换的输入格式

.O...=Supported Output format for conversion 支持的转换输出格式

..H..=Hardware accelerated format 硬件加速格式

...P.=Paletted format 调色格式

....B=Bitstream format 位流格式

下面这个是输出的格式

FLAGS NAME (标志名称)NB_COMPONENTS (组成数量 yuv420 就是有三个组成的) BITS_PER_PIXEL(每个像素占得位数)

-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 设定log等级 "quiet" "panic" "fatal" "error" "warning" "info" "verbose" "debug" "trace"

补充说明: Flags can also be used alone by adding a ’+’/’-’ prefix to set/reset a single flag without affecting other flags or changing loglevel. When setting both flags and loglevel, a ’+’ separator is expected between the last flags value and before loglevel.

意思就是----还可以单独使用标志,添加‘+’/‘-’前缀来设置/重置单个标志,而不影响其他标志或更改日志级别。当同时设置标志和日志级别时,需要在最后一个标志值之间和日志级别之前使用。

eg:ffmpeg -loglevel repeat+level+verbose -i input output

-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 ratio of errors (0.0: no errors, 1.0: 100% error maximum error rate 错误率(0:无错误,1:100%错误最大错误率)

-bits_per_raw_sample number set the number of bits per raw sample 设置每个原始样本的位数

-vol volume change audio volume (256=normal) 改变音频音量(256=正常)

Per-file main options: 每个文件的主要选项

-f fmt force format 强迫使用格式‘fmt’

-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 编码或转码音频/视频的“ duration”秒

-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 设置相对于eof的起始时间偏移量。

-seek_timestamp enable/disable seeking by timestamp with -ss 使用-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 "dv50" with optional prefixes "pal-", "ntsc-" or "film-") 指定目标文件类型( "vcd", "svcd", "dvd", "dv" or "dv50",可选前缀为 "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 输入参数变化的 reinit滤波图

-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) 设置帧速率(Hz值、分数或缩写)

-s size set frame size (WxH or abbreviation) 设置帧大小(WXH或缩写——Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576)

-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) 设定高宽比(4:3,16:9或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) 选择通行证号码(1到3)

-vf filter_graph set video filters 设置视频滤波器

-ab bitrate audio bitrate (please use -b:a) 音频比特率(请使用-b:a)

-b bitrate video bitrate (please use -b:v) 视频比特率(请使用-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) 改变音频音量(256=正常)

-af filter_graph set audio filters 设置音频过滤器

Subtitle options: 字幕选项

-s size set frame size (WxH or abbreviation) 设置帧大小(WxH或省略)

-sn disable subtitle 禁用字幕

-scodec codec force subtitle codec ('copy' to copy stream) 强制字幕编解码器(“复制流)

-stag fourcc/tag force subtitle tag/fourcc 强制字幕标签/fourcc码

-fix_sub_duration fix subtitles duration 修正字幕持续时间

-canvas_size size set canvas size (WxH or abbreviation) 设置画布大小(WXH或缩写)

-spre preset set the subtitle options to the indicated preset 将字幕选项设置为指定的预置

好了 我们就开始用实例进行巩固

ffmpeg -i cyq.avi out.avi

这个是最简单的转码命令 转码的内部参数都是取的默认值

我们来看下相关的参数

后来才意识到之前为什么会写错 现在 我们再来重温一遍ffmpeg的书写格式

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

ffmpeg + 全局的选项(可省略)+{输入文件选项 -i 文件} +{输出文件选项 文件}

**************************************************************************************************************************************

ffplay 是用SDL来写的一个播放器

(官方的解释:ffplay是一个非常简单和可移植的媒体播放器,使用ffmpeg库和SDL库。它主要用作各种ffmpeg API的测试床。)

他的功能可谓是很强大 但是就是没有图形化的操作界面 只能通过键盘来操作

这边就分 快捷键以及选项来进行说明

http://ffmpeg.org/ffplay.html 官网的使用说明

我们先来看下ffplay -h

因为显示的东西太多 我这边就来挑选着记录

前边显示的和ffmpeg的差不多

我们先看下他的用法:ffplay [options] input_file

接下来看下主选项:

Main options:

-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

-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

-sources device list sources of the input device 显示输入设备的自动检测源。

-sinks device list sinks of the output device 显示输出设备的自动检测接收器。

-x width force displayed width

-y height force displayed height

-s size set frame size (WxH or abbreviation)

-fs force full screen 强制全屏(和ffmpeg中的fs是不一样的用法)

-an disable audio

-vn disable video

-sn disable subtitling

-ss pos seek to a given position in seconds 以秒为单位寻找给定位置

-t duration play "duration" seconds of audio/video 播放音频/视频的“ duration”秒

-bytes val seek by bytes 0=off 1=on -1=auto 按字节查找 0=OFF 1=ON -1=AUTO

-nodisp disable graphical display 禁用图形显示

-noborder borderless window 无边界窗口

-volume volume set startup volume 0=min 100=max 设置启动 volume0=min 100=max

-f fmt force format

-window_title window title set window title 窗口标题集窗口标题

-af filter_graph set audio filters 设置音频过滤器

-showmode mode select show mode (0=video, 1=waves, 2=RDFT) 选择显示模式(0=视频,1=波形,2=RDFT)

-i input_file read specified file 读取指定文件

将学到:

  • 逻辑文件夹结构和物理文件夹结构

  • 虚拟名称和物理名称

  • Web URL 和 Web 路径


逻辑文件夹结构

下面是典型的 ASP.NET 网站文件夹结构:

  • "Account" 文件夹包含登录和安全文件

  • "App_Data" 文件夹包含数据库和数据文件

  • "Images" 文件夹包含图片

  • "Scripts" 文件夹包含浏览器脚本

  • "Shared" 文件夹包含公共的文件(比如布局和样式文件)


物理文件夹结构

在上述网站中的"Images"文件夹在计算机上的物理文件夹结构可能如下:

C:\Documents\MyWebSites\Demo\Images


虚拟名称和物理名称

以上面的例子为例:

网站图片的虚拟名称可能是"Images/pic31.jpg"。

对应的物理名称是"C:\Documents\MyWebSites\Demo\Images\pic31.jpg"。


URL 和路径

URL 是用来访问网站中的文件: http://www.w3cschool.cc/html/html-tutorial.html

URL 对应于服务器上的物理文件:C:\MyWebSites\w3cschool\html\html-tutorial.html

虚拟路径是物理路径的一种简写表示。如果您使用虚拟路径,当您更改域名或者将您的网页移到其他服务器上时,您可以不用更新路径。

URLhttp://www.w3cschool.cc/html/html-tutorial.html
服务器名称w3cschool
虚拟路径/html/html-tutorial.html
物理路径C:\MyWebSites\w3cschool\html\html-tutorial.html

磁盘驱动器的根目录如下书写 C: ,但是网站的根目录是 / (斜线)。

Web 文件夹的虚拟路径通常是与物理文件夹不相同。

在您的代码中,根据您的编码需要决定使用物理路径和和虚拟路径。

ASP.NET 文件夹路径有 3 种工具:~ 运算符、Server.MapPath 方法 和 Href 方法。



~ 运算符

使用 ~ 运算符,在编程代码中规定虚拟路径。

如果您使用 ~ 运算符,在您的站点迁移到其他不同的文件夹或者位置时,您可以不用更改您的任何代码:

var myImagesFolder="~/images";

var myStyleSheet="~/styles/StyleSheet.css";


Server.MapPath 方法

Server.MapPath 方法将虚拟路径(/index.html)转换成服务器能理解的物理路径(C:\Documents\MyWebSites\Demo\default.html)。

当您需要打开服务器上的数据文件时,您可以使用这个方法(只有提供完整的物理路径才能访问数据文件):

var pathName="~/dataFile.txt";

var fileName=Server.MapPath(pathName);


Href 方法

Href 方法将代码中的使用的路径转换成浏览器可以理解的路径(浏览器无法理解 ~ 运算符)。

您可以使用 Href 方法创建资源(比如图像文件 和 CSS 文件)的路径。

一般会在 HTML 中的 <a>、<img> 和 <link> 元素中使用此方法:

@{var myStyleSheet="~/Shared/Site.css";}

<!-- This creates a link to the CSS file. -->

<link rel="stylesheet" type="text/css" href="@Href(myStyleSheet)" />

<!-- Same as : -->

<link rel="stylesheet" type="text/css" href="/Shared/Site.css" />

Href 方法是 WebPage 对象的一种方法。

近开发electron-vue的时候遇到一个坑

于是到网上一顿找

但根据每个人的写法或用的框架不一致

导致网上的资料不是正确的

最终结果是也没找到解决方案

就像在平坦的柏油路上奔驰

一个小坑会让你措不及防而翻车

坑1、在vue-cli创建的electron项目中,dev环境下用axios访问接口跨域问题

这个问题好解决

在vue.config.js配置中写入如下代码

module.exports={
	// 第三方插件配置
	pluginOptions: {
		electronBuilder: {
			builderOptions: {
				"win": { //win相关配置
					"icon": "./public/logo.ico", //图标,当前图标在根目录下,注意这里有两个坑
					"target": [{
						"target": "nsis", //利用nsis制作安装程序
						"arch": [
							"x64", //64位
						]
					}]
				},
				"mac": {
					"icon": "./public/inv_tool.ico"
				},
				"nsis": {
					"oneClick": false, // 是否一键安装
					"allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
					"allowToChangeInstallationDirectory": true, // 允许修改安装目录
					"installerIcon": "./public/logo.ico", // 安装图标
					"uninstallerIcon": "./public/logo.ico", //卸载图标
					"installerHeaderIcon": "./public/logo.ico", // 安装时头部图标
					"createDesktopShortcut": true, // 创建桌面图标
					"createStartMenuShortcut": true, // 创建开始菜单图标
					"shortcutName": "AppDemo", // 图标名称
				},
			}
		}
	},
	lintOnSave: false,
	devServer: {
		host: '0.0.0.0',
		port: 8080,
		hotOnly: true, // 热加载
		proxy: { //配置跨域
			'/apiUrl': {
				target: 'http://118.192.93.6:8080/tool',
				ws: true,
				changOrigin: true, //允许跨域
				pathRewrite: {
					'^/apiUrl': ''
				}
			}
		}
	},
}

注意打包的ico文件要用256*256的

其中nsis可根据项目需求自行选择要不要安装配置选择

如果不需要他自带的安装程序包,要自定义好看安装程序包

可以去看我的文章《关于客户端自定义安装界面开发分享》

以上是解决dev环境下访问接口跨域问题的解决方案

坑2、在npm run electron:build之后,运行程序,所有的访问接口Request URL

都会变成file:///D:xxx/xxx/正确的应该是http://xxx或者https://xxx

是因为electron中设置了win.loadURL访问了本地index.html文件导致

if (process.env.WEBPACK_DEV_SERVER_URL) {// dev环境
	win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
	win.webContents.openDevTools()
} else {// 打包环境
	createProtocol('app')
	win.loadURL(`file://${__dirname}/index.html`);
}

这个问题解决办法挺low的,但是很实用

在vue的main.js中写入下面一段代码

Vue.prototype.$api="http://118.192.93.6:8080/tool";

在axios请求中直接写成

_this.$axios('post',_this.$api+'/login',data
	.then(data=> {
  ......
})

然后你会发现打包完就可以访问了,但dev环境下缺少了proxy代理,这样也不行啊

所以最终结果写成这样就可以解决问题了

Vue.prototype.$api=process.env.NODE_ENV=='development' ? "/invoice" : "http://116.196.95.4:8080/tool";

以上内容亲测有效

如果帮助你解决了问题

请点赞

收藏

转发喔

感谢支持!