-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlist.c
More file actions
48 lines (45 loc) · 1.21 KB
/
list.c
File metadata and controls
48 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* copyright (c) 2024 Jack Lau
*
* This file is a tutorial about listing files through ffmpeg API
*
* FFmpeg version 4.1.7
* Tested on Ubuntu 22.04, compiled with GCC 11.4.0
*/
#include <libavformat/avformat.h>
int main(int argc, char *argv[])
{
int ret;
//init
AVIODirContext *ctx=NULL;
AVIODirEntry *entry=NULL;
av_log_set_level(AV_LOG_INFO);
//open the directory
ret = avio_open_dir(&ctx, "./", NULL);
if(ret < 0){
av_log(NULL, AV_LOG_ERROR, "failed to open the directory:%s\n",av_err2str(ret));
goto end;
}
//read the files
while(1){
ret = avio_read_dir(ctx, &entry);
if(ret < 0){
av_log(NULL, AV_LOG_ERROR, "failed to read the directory:%s\n",av_err2str(ret));
goto end;
}
//if all of the files listed, then break the loop
if(!entry){
break;
}
//print the info of file's size and name
av_log(NULL, AV_LOG_INFO, "%12"PRId64" %s \n",
entry->size,
entry->name);
//free the memory of entry
avio_free_directory_entry(&entry);
}
end:
//free the memory of ctx
avio_close_dir(&ctx);
return 0;
}