1 avcodec_find_decoder()
/** * Find a registered decoder with a matching codec ID. * * @param id CodecID of the requested decoder * @return A decoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_decoder(enum CodecID id); // 通過code ID查找一個已經注冊的音視頻解碼器 // 引入 #include "libavcodec/avcodec.h" // 實現在: \ffmpeg\libavcodec\utils.c // 查找解碼器之前,必須先調用av_register_all注冊所有支持的解碼器 // 查找成功返回解碼器指針,否則返回NULL // 音視頻解碼器保存在一個鏈表中,查找過程中,函數從頭到尾遍歷鏈表,通過比較解碼器的ID來查找
2 avcodec_find_decoder_by_name()
/** * Find a registered decoder with the specified name. * * @param name name of the requested decoder * @return A decoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_decoder_by_name(const char *name); // 通過一個指定的名稱查找一個已經注冊的音視頻解碼器 // 引入 #include "libavcodec/avcodec.h" // 實現在: \ffmpeg\libavcodec\utils.c // 查找解碼器之前,必須先調用av_register_all注冊所有支持的解碼器 // 查找成功返回解碼器指針,否則返回NULL // 音視頻解碼器保存在一個鏈表中,查找過程中,函數從頭到尾遍歷鏈表,通過比較解碼器的name來查找
3 avcodec_find_encoder()
/** * Find a registered encoder with a matching codec ID. * * @param id CodecID of the requested encoder * @return An encoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_encoder(enum CodecID id); // 通過code ID查找一個已經注冊的音視頻編碼器 // 引入 #include "libavcodec/avcodec.h" // 實現在: \ffmpeg\libavcodec\utils.c // 查找編碼器之前,必須先調用av_register_all注冊所有支持的編碼器 // 查找成功返回編碼器指針,否則返回NULL // 音視頻編碼器保存在一個鏈表中,查找過程中,函數從頭到尾遍歷鏈表,通過比較編碼器的ID來查找
4 avcodec_find_encoder_by_name()
/**
* Find a registered encoder with the specified name. * * @param name name of the requested encoder * @return An encoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_encoder_by_name(const char *name); // 通過一個指定的名稱查找一個已經注冊的音視頻編碼器 // 引入 #include "libavcodec/avcodec.h" // 實現在: \ffmpeg\libavcodec\utils.c // 查找編碼器之前,必須先調用av_register_all注冊所有支持的編碼器 // 查找成功返回編碼器指針,否則返回NULL // 音視頻編碼器保存在一個鏈表中,查找過程中,函數從頭到尾遍歷鏈表,通過比較編碼器的名稱來查找
5 avcodec_open()
/** * Initialize the AVCodecContext to use the given AVCodec. Prior to using this * function the context has to be allocated. * * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for * retrieving a codec. * * @warning This function is not thread safe! * * @code * avcodec_register_all(); * codec = avcodec_find_decoder(CODEC_ID_H264); * if (!codec) * exit(1); * * context = avcodec_alloc_context(); * * if (avcodec_open(context, codec) < 0) * exit(1); * @endcode * * @param avctx The context which will be set up to use the given codec. * @param codec The codec to use within the context. * @return zero on success, a negative value on error * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close */ int avcodec_open(AVCodecContext *avctx, AVCodec *codec); // 使用給定的AVCodec初始化AVCodecContext // 引入#include "libavcodec/avcodec.h" // 方法: avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), avcodec_find_decoder() and avcodec_find_encoder() 提供了快速獲取一個codec的途徑 // 該方法在編碼和解碼時都會用到 // 返回0時成功,打開作為輸出時,參數設置不對的話,調用會失敗
6 av_guess_format()
/** * Return the output format in the list of registered output formats * which best matches the provided parameters, or return NULL if * there is no match. * * @param short_name if non-NULL checks if short_name matches with the * names of the registered formats * @param filename if non-NULL checks if filename terminates with the * extensions of the registered formats * @param mime_type if non-NULL checks if mime_type matches with the * MIME type of the registered formats */ AVOutputFormat *av_guess_format(const char *short_name, const char *filename, const char *mime_type); // 返回一個已經注冊的最合適的輸出格式 // 引入#include "libavformat/avformat.h" // 可以通過 const char *short_name 獲取,如"mpeg" // 也可以通過 const char *filename 獲取,如"E:\a.mp4"
7 av_new_stream()
/** * Add a new stream to a media file. * * Can only be called in the read_header() function. If the flag * AVFMTCTX_NOHEADER is in the format context, then new streams * can be added in read_packet too. * * @param s media file handle * @param id file-format-dependent stream ID */ AVStream *av_new_stream(AVFormatContext *s, int id); // 為媒體文件添加一個流,一般為作為輸出的媒體文件容器添加音視頻流 // 引入 #include "libavformat/avformat.h" // 再打開源文件時用戶一般不需要直接調用該方法
8 dump_format()
#if FF_API_DUMP_FORMAT /** * @deprecated Deprecated in favor of av_dump_format(). */ attribute_deprecated void dump_format(AVFormatContext *ic, int index, const char *url, int is_output); #endif // 該函數的作用就是檢查下初始化過程中設置的參數是否符合規范 // 有些版本中為 av_dump_format
9 av_set_parameters()
#if FF_API_FORMAT_PARAMETERS /** * @deprecated pass the options to avformat_write_header directly. */ attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap); #endif // 設置初始化參數 // 不贊成跳過該方法,直接調用 avformat_write_header/av_write_header
10 av_write_header()
#if FF_API_FORMAT_PARAMETERS /** * Allocate the stream private data and write the stream header to an * output media file. * @note: this sets stream time-bases, if possible to stream->codec->time_base * but for some formats it might also be some other time base * * @param s media file handle * @return 0 if OK, AVERROR_xxx on error * * @deprecated use avformat_write_header. */ attribute_deprecated int av_write_header(AVFormatContext *s); #endif // 把流頭信息寫入到媒體文件中 // 返回0成功
#if FF_API_FORMAT_PARAMETERS /** * Allocate the stream private data and write the stream header to an * output media file. * @note: this sets stream time-bases, if possible to stream->codec->time_base * but for some formats it might also be some other time base * * @param s media file handle * @return 0 if OK, AVERROR_xxx on error * * @deprecated use avformat_write_header. */ attribute_deprecated int av_write_header(AVFormatContext *s); #endif // 把流頭信息寫入到媒體文件中 // 返回0成功