日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

FFmpeg中实现对多媒体信息的获取与打印av_dump_format

發布時間:2025/3/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FFmpeg中实现对多媒体信息的获取与打印av_dump_format 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

獲取mediainfo

首先調用av_register_all將所有的編碼器和解碼器注冊好

來看下具體的注冊實現

void av_register_all(void) {ff_thread_once(&av_format_next_init, av_format_init_next); } // 看下av_format_init_next的實現 // 可以看到函數內部是實現了將編碼器和解碼器使用指針進行串聯的操作 // 如果有輸出或者輸入列表,將輸出或輸入列表也進行串聯 static void av_format_init_next(void) {AVOutputFormat *prevout = NULL, *out;AVInputFormat *previn = NULL, *in;ff_mutex_lock(&avpriv_register_devices_mutex);// 編碼器串聯for (int i = 0; (out = (AVOutputFormat*)muxer_list[i]); i++) {if (prevout)prevout->next = out;prevout = out;}//實現輸出列表的串聯if (outdev_list) {for (int i = 0; (out = (AVOutputFormat*)outdev_list[i]); i++) {if (prevout)prevout->next = out;prevout = out;}}//實現解碼器的串聯for (int i = 0; (in = (AVInputFormat*)demuxer_list[i]); i++) {if (previn)previn->next = in;previn = in;}//實現輸入列表的串聯if (indev_list) {for (int i = 0; (in = (AVInputFormat*)indev_list[i]); i++) {if (previn)previn->next = in;previn = in;}}ff_mutex_unlock(&avpriv_register_devices_mutex); }

調用avformat_open_input

調用 avformat_open_input根據輸入的音視頻內容構造 AVFormatContext結構體,函數功能如下:

/**打開一個流,并讀取頭部信息* Open an input stream and read the header. The codecs are not opened.* The stream must be closed with avformat_close_input().* ps可以用戶提供,如果為NULL該函數會進行內存申請* @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).* May be a pointer to NULL, in which case an AVFormatContext is allocated by this* function and written into ps.* Note that a user-supplied AVFormatContext will be freed on failure.指向要打開的多媒體文件* @param url URL of the stream to open.不指定,使用自動偵測* @param fmt If non-NULL, this parameter forces a specific input format.* Otherwise the format is autodetected.* @param options A dictionary filled with AVFormatContext and demuxer-private options.* On return this parameter will be destroyed and replaced with a dict containing* options that were not found. May be NULL.** @return 0 on success, a negative AVERROR on failure.** @note If you want to use custom IO, preallocate the format context and set its pb field.*/ int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options);

調用av_dump_format打印文件信息

/*** Print detailed information about the input or output format, such as* duration, bitrate, streams, container, programs, metadata, side data,* codec and time base.** @param ic the context to analyze* @param index index of the stream to dump information about* @param url the URL to print, such as source or destination file* @param is_output Select whether the specified context is an input(0) or output(1)*/ void av_dump_format(AVFormatContext *ic,int index,const char *url,int is_output);

調用av_dump_format(pFmtCtx, 0, pSrcName, 0);實現對基本信息的打印,這里為了方便觀看,可以自己實現一個函數,對多媒體數據進行打印。

這為了更好理解媒體信息記錄的格式,自己實現了一個簡單的打印接口,僅用于參考

// // Created by andrew on 2020/11/8. //#include <iostream> #include <string> extern "C" { #include <libavformat/avformat.h> #include <libavutil/log.h> #include <libavutil/dict.h> } using namespace std;// 聲明一下 因為原函數是在.c中聲明的結構體 struct AVDictionary {int count;AVDictionaryEntry *elems; };// 打印媒體信息的簡單示例 void my_av_input_dump_format(AVFormatContext *ic, int index,const char *url, int is_output){string pSrt = (is_output != 0) ? "output":"input";cout << "音視頻輸入輸出類型:" << pSrt <<endl;cout << "index = " << index << endl;if(is_output){cout << "fromat name:" << ic->oformat->name << endl;}elsecout << "fromat name:" << ic->iformat->name << endl;// urlcout << "from :" << url << endl;//ic->metadataint i = 0;i = ic->metadata->count;for (i = 0; i < ic->metadata->count; i++){cout << " " <<ic->metadata->elems[i].key << ":" <<ic->metadata->elems[i].value << endl;} }int main(int argc, char *argv[]){// 設置日志等級av_log_set_level(AV_LOG_DEBUG);if(argc< 2){av_log(NULL, AV_LOG_ERROR, "you should input media file!\n");return -1;} // 所有獲取音視頻信息都要首先注冊av_register_all();int errCode = -1;AVFormatContext *pFmtCtx = NULL;const char *pSrcName = argv[1];if((errCode = avformat_open_input(&pFmtCtx, pSrcName, NULL, NULL)) < 0){av_log(NULL, AV_LOG_ERROR, "avformat open input failed.\n");exit(1);}//官方接口 // av_dump_format(pFmtCtx, 0, pSrcName, 0);my_av_input_dump_format(pFmtCtx, 0, pSrcName, 0);//釋放資源avformat_close_input(&pFmtCtx);return 0; }

執行輸出結果:

音視頻輸入輸出類型:input index = 0 fromat name:mov,mp4,m4a,3gp,3g2,mj2 from :/work/test/test.mp4major_brand:isomminor_version:512compatible_brands:isomiso2avc1mp41track:0artist:段奧娟album:comment:163 key(Don't modify):ZWxeTBkln0EQUjdDVUZQXrJzMh33POt0FgWTvjgge2X8BzXmyZaXb9C8+H2VGrdLG7XRTMrkXzzfV9VNH7sp0KlFimbjkVbsWksXY5YrzqFNXeJX1gvrBWCV+m3aYddkvy0HxucdcxCoCrYsrnzxL97sgxi0M2VHh6PREC3j6Uz4hfWkIMGhul9aszAuzEvbUUIQXSZRHgpkVW3g3oTEwqY5CexOWMIgIZAjlFIMxafAnGU8ujxA+ufq/l/r+dQMW9OmRQVt2n4Gz1t83TrPZg==title:元気滿分encoder:Lavf57.71.100 [AVIOContext @ 0x55bf28f2d080] Statistics: 200364 bytes read, 0 seeks libgcov profiling error:/work/ffmpeg_doc/cmake-build-debug-coverage/src/CMakeFiles/ffmpeg_mediainfo.dir/ffmpeg_avformat/ffmpeg_mediainfo.cpp.gcda:overwriting an existing profile data with a different timestamp

總結

以上是生活随笔為你收集整理的FFmpeg中实现对多媒体信息的获取与打印av_dump_format的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。