ffmpeg-打开媒体文件-avio_open_dir-avio_read_dir

vio_open_dir


avio_read_dir


avio_free_directory_entry


avio_close


Code
#include 
void dir_function(void)
{
	AVIOContext * ctx = NULL;		// 目录操作上下文
	AVIODirEntry * entry = NULL;	// 目录项
	av_log_set_level(AV_LOG_DEBUG);	// 设置日志等级
	int ret = avio_open_dir(&ctx, "./A", NULL);
	if (ret < 0)
	{
		av_log(NULL, AV_LOG_ERROR, "cant open dir %s\n", av_err2str(ret));
		goto __fail;
	}
#if 0
	ret = avio_read_dir(ctx, &entry);
	av_log(NULL, AV_LOG_INFO, 
			"File Name:%s, File Size:%ld\n", entry->name, entry->size);
		avio_free_directory_entry(&entry);
	avio_free_directory_entry(&entry);
	goto __fail;
#endif
	while (1)
	{
		ret = avio_read_dir(ctx, &entry);
		if (ret < 0)
		{
			av_log(NULL, AV_LOG_ERROR, "Cant read dir\n");
			goto __fail;
		}
		// 如果entry是NULL,则代表目录到末尾退出
		if (!entry)
			break;
		av_log(NULL, AV_LOG_INFO, 
			"File Name:%s, File Size:%ld\n", entry->name, entry->size);
		avio_free_directory_entry(&entry);
	}
__fail:
	avio_close(&ctx);
}

参考链接

posted @ 2024-01-24 17:18  steve的miao  阅读(47)  评论(0编辑  收藏  举报