当前位置:网站首页>FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)

FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)

2022-08-09 13:51:00 One Leaf Knows Autumn @qqy

Manipulate directory important functions

  • avio_open_dir() 打开目录
  • avio_read_dir() Read information about each file in the directory,Including file size, etc
  • avio_close_dir() 关闭目录,释放资源

Manipulate the important structure of the directory

  • AVIODirContext 操作目录的上下文
  • AVIODirEntry 目录项,用于存放文件名,文件大小等信息

实战 简单的ls命令

在linux、mac等系统下,终端输入lsYou can see what files are in the current directory,what are their properties
使用ls -alt,可以查看更详细的信息
在这里插入图片描述

#include <libavutil/log.h>
#include <libavformat/avformat.h>

int main(int argc, char *argv[])
{
    
	int ret;
	AVIODirContext *ctx = NULL;
	AVIODirEntry *entry = NULL;
	av_log_set_level(AV_LOG_INFO);

	ret = avio_open_dir(&ctx, "./", NULL); //打开目录
	if(ret < 0){
    
		av_log(NULL, AV_LOG_ERROR, "Cant open dir:%s\n", av_err2str(ret));
		return -1;
	}
	
	while(1){
    
		avio_read_dir(ctx, &entry); //读取目录
		if(ret < 0){
    
			av_log(NULL, AV_LOG_ERR, "Cant rad dir:%s\n", av_err2str(ret));
			goto __fail;
		}

		if(!entry){
    
			break; //If read to the end,break out of the loop
		}

		av_log(NULL, AV_LOG_INFO, "%12"PRId64" %s \n", entry->size, entry->name);

	avio_free_directory_entry(&entry);
	}
__fail:
	avio_close_dir(&ctx);
	return 0;
}
原网站

版权声明
本文为[One Leaf Knows Autumn @qqy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091244282704.html