ffmpeg教程
一、命名格式
ffmpeg input(s) [codec options] output(s)
輸入(input)
參數 -i Input.file/stream_url 輸入可以為一個文件,也可以是一個視頻流地址。
“-re” 選項標識以實時方式讀取文件;這允許使用文件作為 "live” 數據源。
編碼器(Codecs)
A huge array of options is available here, however we’ll only cover two things: Copying codecs and changing codecs to H264 for video and AAC for audio. H264/AAC 是最常用的編碼器are the most common codecs at the moment there’s a good chance you already have these in your files, otherwise re-encoding them to H264/AAC with the default settings of ffmpeg will almost certainly give you what you want. If not feel free to check out the ffmpeg documentation here.
使用-c:v設置視頻編碼;
使用-c:a設置音頻編碼;
使用-c設置音頻和視頻編碼。
Copying codecs (options)
The copying of codecs couldn’t be easier with ffmpeg. You only need to use -c copy to copy both the video and audio codecs. Copying the codecs allows you to ingest a media file/stream and record it or change it to a different format. You can also only copy a specific codec like this: -c:v copy for video and -c:a copy for audio. The neat thing about using the copy option is that it will not re-encode your media data, making this an extremely fast operation.
Encoding to H264/AAC (options)
Ffmpeg允許改變video and audio track separately. You can copy a video track while only editing the audio track if you wish. Copying is always done with the copy codec. An encode to H264/AAC is done by using the option -c:a aac -strict -2 -c:v h264. Older versions of ffmpeg might require the equivalent old syntax -acodec aac -strict -2 -vcodec h264 instead.
輸出(output)
The output of ffmpeg can either be a file or a push over a stream url. To record it to a file use outputfile.ext; almost any media type can be chosen by simply using the right extension. To push over a stream use -f FORMAT STREAM_URL. The most commonly used format for live streaming will be RTMP, but RTMP streams internally use the FLV format. That means you’ll have to use -f flv rtmp://SERVERIP:PORT/live/STREAMNAME for this. Other stream types may auto-select their format based on the URL, similar to how this works for files.
案例
(1)攝像頭信息采集和錄制推流
攝像頭名稱要通過這個命令拿到,然后替換掉下面的“Integrated Camera”這個名稱即可推流或者錄制成文件
ffmpeg -list_devices true -f dshow -i dummy
ffmpeg -f dshow -i video=“Integrated Camera” -vcodec libx264 -acodec copy -preset:v ultrafast -tune:v zerolatency -f flv rtmp://eguid.cc:1935/rtmp/eguid
(2)桌面屏幕錄制
1、屏幕錄制并保存成文件
ffmpeg -f gdigrab -i desktop eguid.mp4
2、屏幕錄制并推流
ffmpeg -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast
-tune:v zerolatency -f flv rtmp://eguid.cc:1935/rtmp/destop
(3)視頻文件推流
ffmpeg -re -i eguid.flv -vcodec copy -acodec copy -f flv -y
rtmp://eguid.cc:1935/rtmp/eguid
四、轉流(rtsp轉rtmp為例)
ffmpeg -i rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov
-rtsp_transport tcp -vcodec h264 -acodec aac -f flv rtmp://eguid.cc:1935/rtmp/eguid
五、拉流
ffmpeg -i rtmp://eguid.cc:1935/rtmp/eguid -vcodec h264 -f flv -acodec
aac -ac 2 eguid.flv
(6)音頻推流
ffmpeg -f mp3 -i sender.mp3 -acodec libmp3lame -ab 128k -ac 2 -ar
44100 -re -f rtp rtp://10.14.35.23:1234
流媒體服務
livego
Nginx RMTP模塊
RED5
客戶端
VLC media player
總結
- 上一篇: 制作资源
- 下一篇: Ventoy 制作可启动 U 盘的开源工