diff --git a/util.h b/util.h index d3b3861005f2df24a17b82c92978309b2ca20131..d9e9da14f405cc8e7c5c9d911c118e5ec791fd1f 100644 --- a/util.h +++ b/util.h @@ -13,6 +13,8 @@ char *mprintf(const char *fmt, ...); void *xmalloc(size_t size); char *hashfile(char *path); +double fileduration(char *path); +size_t filesize(char *path); /* JSON av parsing */ void parse_dict(AVDictionary **d, char *s); diff --git a/util/fileduration.c b/util/fileduration.c new file mode 100644 index 0000000000000000000000000000000000000000..3f868f9ab80a5980db85a6e54d1277f2c440c53f --- /dev/null +++ b/util/fileduration.c @@ -0,0 +1,16 @@ +#include <libavformat/avformat.h> + +#include "../util.h" + +double fileduration(char *path) +{ + double res; + AVFormatContext *demux; + demux = 0; + if (avformat_open_input(&demux, path, 0, 0) < 0) + return 0; + avformat_find_stream_info(demux, 0); + res = demux->duration*av_q2d(AV_TIME_BASE_Q); + avformat_close_input(&demux); + return res; +} diff --git a/util/filesize.c b/util/filesize.c new file mode 100644 index 0000000000000000000000000000000000000000..dec050a432c6f0088b6d91d74110b4565f32c116 --- /dev/null +++ b/util/filesize.c @@ -0,0 +1,12 @@ +#include <unistd.h> +#include <sys/stat.h> + +#include "../util.h" + +size_t filesize(char *path) +{ + struct stat s; + if (stat(path, &s)) + return 0; + return s.st_size; +}