FFMPEG AVDictionary 配置参数
AVDictionary 的用法簡介
AVDictionary 所在的頭文件在 libavutil/dict.h,其定義如下:
struct AVDictionary { int count; AVDictionaryEntry *elems; };其中,AVDictionaryEntry 的定義如下:
typedef struct AVDictionaryEntry { char *key; char *value; } AVDictionaryEntry;下面就用示例的方式簡單介紹下用法
創建一個字典
AVDictionary *d = NULL;銷毀一個字典
av_dict_free(&d);添加一對 key-value
av_dict_set(&d, "name", "jhuster", 0); av_dict_set_int(&d, "age", "29", 0);獲取 key 的值
AVDictionaryEntry *t = NULL;t = av_dict_get(d, "name", NULL, AV_DICT_IGNORE_SUFFIX); av_log(NULL, AV_LOG_DEBUG, "name: %s", t->value);t = av_dict_get(d, "age", NULL, AV_DICT_IGNORE_SUFFIX); av_log(NULL, AV_LOG_DEBUG, "age: %d", (int) (*t->value));遍歷字典
AVDictionaryEntry *t = NULL; while ((t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX))) {av_log(NULL, AV_LOG_DEBUG, "%s: %s", t->key, t->value); }ffmpeg 參數的傳遞
ffmpeg 中很多 API 都是靠 AVDictionary 來傳遞參數的,比如常用的:
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options);最后一個參數就是 AVDictionary,我們可以在打開碼流前指定各種參數,比如:探測時間、超時時間、最大延時、支持的協議的白名單等等,例如:
AVDictionary *options = NULL; av_dict_set(&options, “probesize”, “4096", 0); av_dict_set(&options, “max_delay”, “5000000”, 0); AVFormatContext *ic = avformat_alloc_context(); if (avformat_open_input(&ic, url, NULL, &options) < 0) {LOGE("could not open source %s", url);return -1; }那么,我們怎么知道 ffmpeg 的這個 API 支持哪些可配置的參數呢 ?
我們可以查看 ffmpeg 源碼,比如 avformat_open_input 是結構體 AVFormatContext 提供的 API,在 libavformat/options_table.h 中定義了 AVFormatContext 所有支持的 options 選項,如下所示:
 https://www.ffmpeg.org/doxygen/trunk/libavformat_2options__table_8h-source.html
同理,AVCodec 相關 API 支持的 options 選項則可以在 libavcodec/options_table.h 文件中找到,如下所示:
https://www.ffmpeg.org/doxygen/3.1/libavcodec_2options__table_8h_source.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的FFMPEG AVDictionary 配置参数的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Go 质数
- 下一篇: FFMPEG avformat_open
