初識 FFmpeg
FFmpeg 是一個多媒體編解碼庫。它能夠?qū)崿F(xiàn)很多文件格式的編解碼,若要知道具體支持什么格式可在編譯ffmpeg庫之后在命令行輸入# ./configure --help 通過幫助信息來查看。像 avi 這種常用的視頻格式 ffmpeg 里面已經(jīng)自帶了解碼庫。像 xvid、x264 等格式的文件需要添加 xvid 和 x264 的庫來支持。因為在 ffmpeg里面,xvid 跟 x264 的庫只是一個空殼子。
當我們調(diào)用 ffmpeg里面的庫(主要是libavformat和libavcodec文件)來解碼視頻文件后,我們可以通過 SDL庫 或者 QT 庫 將解碼出的數(shù)字信息轉(zhuǎn)化成圖像畫在屏幕上,這樣,視頻文件就顯示出來了(即播放器)。聽起來很簡單,但制作的過程可 非一般。
ffmpeg的源碼目錄下有ffmpeg.c、、ffplar.c、ffserver.c這三個文件。現(xiàn)在通過ffmpeg/doc 目錄下的文檔來認識下 這三個文件。 -------------------------------------------------------------------------------------------
FFmpeg ->FFmpeg is a very fast video and audio converter. It can also grab from a live audio/video source. The command line interface is designed to be intuitive, in the sense that FFmpeg tries to figure out all parameters that can possibly be derived automatically. You usually only have to specify the target bitrate you want.FFmpeg can also convert from any sample rate to any other, and resize video on the fly with a high quality polyphase filter.As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.
->如何使用 ffmpeg的命令行?,以下是一些例子。具體可參考ffmpeg/doc/ffmpeg.texi,里面描述的相當詳盡。 ->ffmpeg [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}... ->To set the video bitrate of the output file to 64kbit/s: ffmpeg -i input.avi -b 64k output.avi
->To force the frame rate of the output file to 24 fps: ffmpeg -i input.avi -r 24 output.avi
->To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps: ffmpeg -r 1 -i input.m2v -r 24 output.avi ...... ...... 摘自ffmpeg/doc/ffmpeg.texi -------------------------------------------------------------------------------------------
FFplay ->FFplay is a very simple and portable media player using the FFmpeg libraries and the SDL library. It is mostly used as a testbed for the various FFmpeg APIs.
->ffplay [options] @file{input_file}
摘自ffmpeg/doc/ffplay.texi -------------------------------------------------------------------------------------------
FFserver ->FFserver is a streaming server for both audio and video. It supports several live feeds, streaming from files and time shifting on live feeds (you can seek to positions in the past on each live feed, provided you specify a big enough feed storage in ffserver.conf).FFserver runs in daemon mode by default; that is, it puts itself in the background and detaches from its TTY, unless it is launched in debug mode or a NoDaemon option is specified in the configuration file.
摘自ffmpeg/doc/ffserver.texi -----------------------------------------------------------------------------------------
FFMPEG的庫會在不斷的更新,更新之后的一些API是用法可能會跟之前的API有很大的不同,而網(wǎng)上對最新
庫的資料的討論可能會比較少,這時我們就可以參考FFMPEG庫里面自帶的資料。
api-example.c
/** * @file * avcodec API use example. * * Note that this library only handles codecs (mpeg, mpeg4, etc...), * not file formats (avi, vob, etc...). See library 'libavformat' for the * format handling */ /* * 該文件所在位置 ffmpeg/libavcodec/api-example.c * 該文件講的是如何運用庫 libavcodec 來實現(xiàn)文件的編碼和解碼。 * 該文件主要包含部分: * 1、Audio encoding example * Audio decoding * 2、Video encoding example * Video decoding * 3、int main(int argc, char **argv) 。1 與 2 的實現(xiàn) */
output-example.c
/* * Libavformat API example: Output a media file in any supported * libavformat format. The default codecs are used.
*/
假如我們想自己寫個播放器的時候,主要參考下api-example.c和output-example.c就可以了。
api-example.c 講的是音視頻解碼函數(shù)的使用。
output-example.c 講的是如何將解碼出來的幀轉(zhuǎn)換成一定格式的數(shù)據(jù)。
|