初识 FFmpeg
FFmpeg 是一个多媒体编解码库。它能够实现很多文件格式的编解码,若要知道具体支持什么格式可在编译ffmpeg库之后在命令行输入# ./configure --help 通过帮助信息来查看。像 avi 这种常用的视频格式 ffmpeg 里面已经自带了解码库。像 xvid、x264 等格式的文件需要添加 xvid 和 x264 的库来支持。因为在 ffmpeg里面,xvid 跟 x264 的库只是一个空壳子。
当我们调用 ffmpeg里面的库(主要是libavformat和libavcodec文件)来解码视频文件后,我们可以通过 SDL库 或者 QT 库
将解码出的数字信息转化成图像画在屏幕上,这样,视频文件就显示出来了(即播放器)。听起来很简单,但制作的过程可
非一般。
ffmpeg的源码目录下有ffmpeg.c、、ffplar.c、ffserver.c这三个文件。现在通过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有很大的不同,而网上对最新
库的资料的讨论可能会比较少,这时我们就可以参考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 来实现文件的编码和解码。
* 该文件主要包含部分:
* 1、Audio encoding example
* Audio decoding
* 2、Video encoding example
* Video decoding
* 3、int main(int argc, char **argv) 。1 与 2 的实现
*/
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 讲的是音视频解码函数的使用。
output-example.c 讲的是如何将解码出来的帧转换成一定格式的数据。
阅读(2894) | 评论(0) | 转发(0) |