On Fri, Mar 27, 2015 at 7:09 PM, Michael Niedermayer <michae...@gmx.at> wrote:
> On Thu, Mar 26, 2015 at 01:25:18AM +0100, Mariusz Szczepańczyk wrote: > > From: Lukasz Marek <lukasz.m.lu...@gmail.com> > > > > --- > > .gitignore | 1 + > > configure | 2 + > > doc/Makefile | 1 + > > doc/examples/Makefile | 3 +- > > doc/examples/avio_list_dir.c | 105 > +++++++++++++++++++++++++++++++++++++++++++ > > 5 files changed, 111 insertions(+), 1 deletion(-) > > create mode 100644 doc/examples/avio_list_dir.c > > > > diff --git a/.gitignore b/.gitignore > > index d2088e5..71d4d64 100644 > > --- a/.gitignore > > +++ b/.gitignore > > @@ -36,6 +36,7 @@ > > /doc/avoptions_codec.texi > > /doc/avoptions_format.texi > > /doc/doxy/html/ > > +/doc/examples/avio_list_dir > > /doc/examples/avio_reading > > /doc/examples/decoding_encoding > > /doc/examples/demuxing_decoding > > diff --git a/configure b/configure > > index a96bfb7..cd84d2b 100755 > > --- a/configure > > +++ b/configure > > @@ -1321,6 +1321,7 @@ COMPONENT_LIST=" > > > > EXAMPLE_LIST=" > > avio_reading_example > > + avio_list_dir_example > > decoding_encoding_example > > demuxing_decoding_example > > extract_mvs_example > > @@ -2653,6 +2654,7 @@ zoompan_filter_deps="swscale" > > > > # examples > > avio_reading="avformat avcodec avutil" > > +avio_list_dir="avformat avutil" > > avcodec_example_deps="avcodec avutil" > > decoding_encoding_example_deps="avcodec avformat avutil" > > demuxing_decoding_example_deps="avcodec avformat avutil" > > diff --git a/doc/Makefile b/doc/Makefile > > index 697142f..4573531 100644 > > --- a/doc/Makefile > > +++ b/doc/Makefile > > @@ -36,6 +36,7 @@ DOCS-$(CONFIG_MANPAGES) += $(MANPAGES) > > DOCS-$(CONFIG_TXTPAGES) += $(TXTPAGES) > > DOCS = $(DOCS-yes) > > > > +DOC_EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir > > DOC_EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading > > DOC_EXAMPLES-$(CONFIG_AVCODEC_EXAMPLE) += avcodec > > DOC_EXAMPLES-$(CONFIG_DECODING_ENCODING_EXAMPLE) += decoding_encoding > > diff --git a/doc/examples/Makefile b/doc/examples/Makefile > > index 9f03f04..9699f11 100644 > > --- a/doc/examples/Makefile > > +++ b/doc/examples/Makefile > > @@ -11,7 +11,8 @@ CFLAGS += -Wall -g > > CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS) > > LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS) > > > > -EXAMPLES= avio_reading \ > > +EXAMPLES= avio_list_dir \ > > + avio_reading \ > > decoding_encoding \ > > demuxing_decoding \ > > extract_mvs \ > > diff --git a/doc/examples/avio_list_dir.c b/doc/examples/avio_list_dir.c > > new file mode 100644 > > index 0000000..d0e8598 > > --- /dev/null > > +++ b/doc/examples/avio_list_dir.c > > @@ -0,0 +1,105 @@ > > +/* > > + * Copyright (c) 2014 Lukasz Marek > > + * > > + * Permission is hereby granted, free of charge, to any person > obtaining a copy > > + * of this software and associated documentation files (the > "Software"), to deal > > + * in the Software without restriction, including without limitation > the rights > > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or > sell > > + * copies of the Software, and to permit persons to whom the Software is > > + * furnished to do so, subject to the following conditions: > > + * > > + * The above copyright notice and this permission notice shall be > included in > > + * all copies or substantial portions of the Software. > > + * > > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS OR > > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > MERCHANTABILITY, > > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT > SHALL > > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR > OTHER > > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > ARISING FROM, > > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > DEALINGS IN > > + * THE SOFTWARE. > > + */ > > + > > +#include <libavcodec/avcodec.h> > > +#include <libavformat/avformat.h> > > +#include <libavformat/avio.h> > > + > > +static const char *type_string(int type) > > +{ > > + switch (type) { > > + case AVIO_ENTRY_DIRECTORY: > > + return "<DIR>"; > > + case AVIO_ENTRY_FILE: > > + return "<FILE>"; > > + case AVIO_ENTRY_BLOCK_DEVICE: > > + return "<BLOCK DEVICE>"; > > + case AVIO_ENTRY_CHARACTER_DEVICE: > > + return "<CHARACTER DEVICE>"; > > + case AVIO_ENTRY_NAMED_PIPE: > > + return "<PIPE>"; > > + case AVIO_ENTRY_SYMBOLIC_LINK: > > + return "<LINK>"; > > + case AVIO_ENTRY_SOCKET: > > + return "<SOCKET>"; > > + case AVIO_ENTRY_UNKNOWN: > > + default: > > + break; > > + } > > + return "<UNKNOWN>"; > > +} > > + > > +int main(int argc, char *argv[]) > > +{ > > + const char *input_dir = NULL; > > + AVIODirEntry *entry = NULL; > > + AVIODirContext *ctx = NULL; > > + int ret; > > + char filemode[4]; > > + > > + av_log_set_level(AV_LOG_DEBUG); > > + > > + if (argc != 2) { > > + fprintf(stderr, "usage: %s input_dir\n" > > + "API example program to show how to list files in > directory " > > + "accessed through AVIOContext.\n", argv[0]); > > + return 1; > > + } > > + input_dir = argv[1]; > > + > > + /* register codecs and formats and other lavf/lavc components*/ > > + av_register_all(); > > + > > + if ((ret = avio_open_dir(&ctx, input_dir, NULL)) < 0) { > > + av_log(NULL, AV_LOG_ERROR, "Cannot open directory: %s.\n", > av_err2str(ret)); > > + return 1; > > + } > > + > > > + for (;;) { > > + if ((ret = avio_read_dir(ctx, &entry)) < 0) { > > + av_log(NULL, AV_LOG_ERROR, "Cannot list directory: %s.\n", > av_err2str(ret)); > > + return 1; > > + } > > + if (!entry) > > + break; > > + if (entry->filemode == -1) { > > + snprintf(filemode, 4, "???"); > > + } else { > > + snprintf(filemode, 4, "%3"PRIo64, entry->filemode); > > + } > > + av_log(NULL, AV_LOG_INFO, "%-9s %10"PRId64" %30s > %"PRId64"(%"PRId64") %s %"PRId64" %"PRId64" %"PRId64"\n", > > + type_string(entry->type), > > + entry->size, > > + entry->name, > > + entry->user_id, > > + entry->group_id, > > + filemode, > > + entry->modification_timestamp, > > + entry->access_timestamp, > > + entry->status_change_timestamp); > > this seems missing a header line in the printout that lists what > each column represents > I've added the header line. Mariusz
From a3e24c138fd08a749e6b934f3dff4129217aaeba Mon Sep 17 00:00:00 2001 From: Lukasz Marek <lukasz.m.lu...@gmail.com> Date: Sat, 5 Jul 2014 18:12:04 +0200 Subject: [PATCH 2/4] doc/examples: add directory listing example --- .gitignore | 1 + configure | 2 + doc/Makefile | 1 + doc/examples/Makefile | 3 +- doc/examples/avio_list_dir.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 doc/examples/avio_list_dir.c diff --git a/.gitignore b/.gitignore index d2088e5..71d4d64 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ /doc/avoptions_codec.texi /doc/avoptions_format.texi /doc/doxy/html/ +/doc/examples/avio_list_dir /doc/examples/avio_reading /doc/examples/decoding_encoding /doc/examples/demuxing_decoding diff --git a/configure b/configure index a96bfb7..cd84d2b 100755 --- a/configure +++ b/configure @@ -1321,6 +1321,7 @@ COMPONENT_LIST=" EXAMPLE_LIST=" avio_reading_example + avio_list_dir_example decoding_encoding_example demuxing_decoding_example extract_mvs_example @@ -2653,6 +2654,7 @@ zoompan_filter_deps="swscale" # examples avio_reading="avformat avcodec avutil" +avio_list_dir="avformat avutil" avcodec_example_deps="avcodec avutil" decoding_encoding_example_deps="avcodec avformat avutil" demuxing_decoding_example_deps="avcodec avformat avutil" diff --git a/doc/Makefile b/doc/Makefile index 697142f..4573531 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -36,6 +36,7 @@ DOCS-$(CONFIG_MANPAGES) += $(MANPAGES) DOCS-$(CONFIG_TXTPAGES) += $(TXTPAGES) DOCS = $(DOCS-yes) +DOC_EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir DOC_EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading DOC_EXAMPLES-$(CONFIG_AVCODEC_EXAMPLE) += avcodec DOC_EXAMPLES-$(CONFIG_DECODING_ENCODING_EXAMPLE) += decoding_encoding diff --git a/doc/examples/Makefile b/doc/examples/Makefile index 9f03f04..9699f11 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -11,7 +11,8 @@ CFLAGS += -Wall -g CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS) LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS) -EXAMPLES= avio_reading \ +EXAMPLES= avio_list_dir \ + avio_reading \ decoding_encoding \ demuxing_decoding \ extract_mvs \ diff --git a/doc/examples/avio_list_dir.c b/doc/examples/avio_list_dir.c new file mode 100644 index 0000000..37b80c5 --- /dev/null +++ b/doc/examples/avio_list_dir.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2014 Lukasz Marek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <libavcodec/avcodec.h> +#include <libavformat/avformat.h> +#include <libavformat/avio.h> + +static const char *type_string(int type) +{ + switch (type) { + case AVIO_ENTRY_DIRECTORY: + return "<DIR>"; + case AVIO_ENTRY_FILE: + return "<FILE>"; + case AVIO_ENTRY_BLOCK_DEVICE: + return "<BLOCK DEVICE>"; + case AVIO_ENTRY_CHARACTER_DEVICE: + return "<CHARACTER DEVICE>"; + case AVIO_ENTRY_NAMED_PIPE: + return "<PIPE>"; + case AVIO_ENTRY_SYMBOLIC_LINK: + return "<LINK>"; + case AVIO_ENTRY_SOCKET: + return "<SOCKET>"; + case AVIO_ENTRY_UNKNOWN: + default: + break; + } + return "<UNKNOWN>"; +} + +int main(int argc, char *argv[]) +{ + const char *input_dir = NULL; + AVIODirEntry *entry = NULL; + AVIODirContext *ctx = NULL; + int cnt, ret; + char filemode[4], uid_and_gid[20]; + + av_log_set_level(AV_LOG_DEBUG); + + if (argc != 2) { + fprintf(stderr, "usage: %s input_dir\n" + "API example program to show how to list files in directory " + "accessed through AVIOContext.\n", argv[0]); + return 1; + } + input_dir = argv[1]; + + /* register codecs and formats and other lavf/lavc components*/ + av_register_all(); + + if ((ret = avio_open_dir(&ctx, input_dir, NULL)) < 0) { + av_log(NULL, AV_LOG_ERROR, "Cannot open directory: %s.\n", av_err2str(ret)); + return 1; + } + + cnt = 0; + for (;;) { + if ((ret = avio_read_dir(ctx, &entry)) < 0) { + av_log(NULL, AV_LOG_ERROR, "Cannot list directory: %s.\n", av_err2str(ret)); + return 1; + } + if (!entry) + break; + if (entry->filemode == -1) { + snprintf(filemode, 4, "???"); + } else { + snprintf(filemode, 4, "%3"PRIo64, entry->filemode); + } + snprintf(uid_and_gid, 20, "%"PRId64"(%"PRId64")", entry->user_id, entry->group_id); + if (cnt == 0) + av_log(NULL, AV_LOG_INFO, "%-9s %12s %30s %10s %s %16s %16s %16s\n", + "TYPE", "SIZE", "NAME", "UID(GID)", "UGO", "MODIFIED", + "ACCESSED", "STATUS_CHANGED"); + av_log(NULL, AV_LOG_INFO, "%-9s %12"PRId64" %30s %10s %s %16"PRId64" %16"PRId64" %16"PRId64"\n", + type_string(entry->type), + entry->size, + entry->name, + uid_and_gid, + filemode, + entry->modification_timestamp, + entry->access_timestamp, + entry->status_change_timestamp); + avio_free_directory_entry(&entry); + cnt++; + }; + + avio_close_dir(&ctx); + + return 0; +} -- 2.3.3
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel