ffmpeg:處理視訊編碼以及視訊格式
阿新 • • 發佈:2021-10-13
Fast Forward MPEG (ffmpeg) 使用匯總
靠,我當初用ffmpeg只是因為想轉B站的視訊,誰他媽能想到我會再搞實驗室的事情的時候再次用到這玩意,順帶還學一把視訊編碼等相關的知識啊。
但是這個東西嘛,真的就很好用。
ffmpeg的全程是Fast Forward MPEG , 而MEPG的又是Moving Picture Experts Group。的縮寫我總是記不住這個命令的正確拼寫格式,所以記一下全程幫助記憶。
基本概念與用法
基本用法介紹可以參考 ffmpeg基本用法 是一篇簡書博文,我後面的內容基本上也是轉載於這篇博文
1.基本工作流
The transcoding process in ffmpeg for each output can be described by the following diagram: _______ ______________ | | | | | input | demuxer | encoded data | decoder | file | ---------> | packets | -----+ |_______| |______________| | v _________ | | | decoded | | frames | |_________| ________ ______________ | | | | | | | output | <-------- | encoded data | <----+ | file | muxer | packets | encoder |________| |______________| # 主要處理流程。 #1.解複用器demuxer和解碼器decoder用來解碼,得到未被壓縮的幀 #2.編碼器encoder將資料幀重新編碼 #3.新的編碼包經過muxer寫入使用者想要的outputfile
2.相關概念介紹
過濾器(Filter)
在多媒體處理中,filter的意思是被編碼到輸出檔案之前用來修改輸入檔案內容的一個軟體工具。如:視訊翻轉,旋轉,縮放等。
語法:[input_link_label1]… filter_name=parameters [output_link_label1]…
1、視訊過濾器 -vf
如input.mp4視訊按順時針方向旋轉90度
ffplay -i input.mp4 -vf transpose=1
如input.mp4視訊水平翻轉(左右翻轉)
ffplay -i input.mp4 -vf hflip
2、音訊過濾器 -af
實現慢速播放,聲音速度是原始速度的50%
offplay input.mp3 -af atempo=0.5
基本引數介紹
ffmpeg -i "imput.mp4" #檢視相關資訊
ffmpeg –i input.mp4 –r fps output.mp4 #修改幀率 使用-r引數
ffmpeg -i clip.mpg -vf fps=fps=25 clip.webm #修改幀率 使用fps filter
匯出AVI rawvideo供imageJ使用
ffmpeg -i "m3v1mp4.mp4" -vcodec rawvideo -pix_fmt uyvy422 -acodec $audio-codec "m3v1mp4.avi" ffmpeg -i "m3v1mp4.mp4" -vcodec rawvideo -pix_fmt uyvy422 "m3v1mp4.avi" #上面那個會報錯
移除音軌
刪除根據流號刪除
識別流號碼
$ ffmpeg -i in.mp4
...
Stream #0:0: Video: ...
Stream #0:1: Audio: ...
Stream #0:2: Audio: ...
使用-map _file_:_stream_選擇要處理和輸出的流
$ ffmpeg -i in.mp4 -map 0:0 -map 0:2 -vcodec copy -acodec copy out.mp4
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 input.mp4 #檢視視訊幀數 (當然- - 你也可以直接用-i看fps就好了,這個要解碼視訊還是挺慢的)
> -v error:這隱藏了“info”輸出(版本資訊等),使解析更容易。
> -count_frames:計算每個流的幀數,並在相應的流部分中報告。
> -select_streams v:0 :僅選擇視訊流。
> -show_entries stream = nb_read_frames :只顯示讀取的幀數。
> -of default = nokey = 1:noprint_wrappers = 1 :將輸出格式(也稱為“writer”)設定為預設值,不列印每個欄位的鍵(nokey = 1),不列印節頭和頁尾(noprint_wrappers = 1)。
————————————————
版權宣告:本文為CSDN博主「hairuiJY」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/u010368556/article/details/102943897