FFmpeg
Files
I/O Read/Write

Files

file  avio.h
 

Detailed Description

Directory listing

The directory listing API makes it possible to list files on remote servers.

Some of possible use cases:

Opening a directory

At first, a directory needs to be opened by calling avio_open_dir() supplied with a URL and, optionally, AVDictionary containing protocol-specific parameters. The function returns zero or positive integer and allocates AVIODirContext on success.

if (avio_open_dir(&ctx, "smb://example.com/some_dir", NULL) < 0) {
fprintf(stderr, "Cannot open directory.\n");
abort();
}

This code tries to open a sample directory using smb protocol without any additional parameters.

Reading entries

Each directory's entry (i.e. file, another directory, anything else within AVIODirEntryType) is represented by AVIODirEntry. Reading consecutive entries from an opened AVIODirContext is done by repeatedly calling avio_read_dir() on it. Each call returns zero or positive integer if successful. Reading can be stopped right after the NULL entry has been read – it means there are no entries left to be read. The following code reads all entries from a directory associated with ctx and prints their names to standard output.

AVIODirEntry *entry = NULL;
for (;;) {
if (avio_read_dir(ctx, &entry) < 0) {
fprintf(stderr, "Cannot list directory.\n");
abort();
}
if (!entry)
break;
printf("%s\n", entry->name);
}
avio_free_directory_entry
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
Definition: avio.c:605
ctx
AVFormatContext * ctx
Definition: movenc.c:48
NULL
#define NULL
Definition: coverity.c:32
AVIODirEntry::name
char * name
Filename.
Definition: avio.h:87
avio_read_dir
int avio_read_dir(AVIODirContext *s, AVIODirEntry **next)
Get next directory entry.
Definition: avio.c:577
AVIODirEntry
Describes single entry of the directory.
Definition: avio.h:86
printf
printf("static const uint8_t my_array[100] = {\n")
avio_open_dir
int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
Open directory for reading.
Definition: avio.c:539
AVIODirContext
Definition: avio.h:103