于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
虛擬路徑是物理路徑的一種簡寫表示。如果您使用虛擬路徑,當您更改域名或者將您的網頁移到其他服務器上時,您可以不用更新路徑。
URL | http://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";
以上內容親測有效
如果幫助你解決了問題
請點贊
收藏
轉發喔
感謝支持!
*請認真填寫需求信息,我們會在24小時內與您取得聯系。