vim ffmpeg_list.cvim
#include <libavutil/log.h> #include <libavformat/avformat.h> int main(int arc, char *argv[]) { int ret; // 文件內容上下文 AVIODirContext *ctx = NULL; // 文件信息上下文 AVIODirEntry *entry = NULL; // 設置日誌等級 av_log_set_level(AV_LOG_INFO); // 打開文件夾, ctx:上下文, ./當前文件夾 ret = avio_open_dir(&ctx, "./", NULL); if (ret < 0){ av_log(NULL, AV_LOG_ERROR, "找不到文件夾%s\n", av_err2str(ret)); return -1; } while(1){ // 讀文件夾操做 ret = avio_read_dir(ctx, &entry); // 若是讀取失敗 if (ret < 0){ av_log(NULL, AV_LOG_ERROR, "Cant read dir: %s\n", av_err2str(ret)); // return -1; 這裏直接退出可能會忘記文件的退出,照成內存泄漏,使用goto goto __fail; } // 若是讀取成功,須要判斷一下entry if(!entry){ break; } // 打印文件信息, PRId64 是 64的宏信息 av_log(NULL, AV_LOG_INFO, "%12"PRId64" %s \n", entry->size, entry->name); // 要進行entry的釋放 avio_free_directory_entry(&entry); } // 關閉文件夾 __fail: avio_close_dir(&ctx); return 0; }
編譯:函數
clang -g -o list ffmpeg_list.c `pkg-config --libs liavformat libavutil`日誌