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`日志