From d2ad81e4a169ac6f506b373d670542cd0d87cfc4 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 15 Apr 2021 21:34:08 +0200 Subject: [PATCH] Implementing a adprintf for windows --- CMakeLists.txt | 3 ++- README.md | 2 +- include/compatibility.h | 11 +++++++++-- src/compatibility.c | 29 +++++++++++++++++++++++++++++ src/extractor.c | 6 +++--- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f689b7d..0d63f65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,11 @@ set_property(TARGET transcoder PROPERTY C_STANDARD 11) set_property(TARGET transcoder PROPERTY POSITION_INDEPENDENT_CODE ON) target_link_libraries(transcoder avformat avcodec avutil) -target_link_libraries(transcoder m pthread) if(WIN32) target_link_libraries(transcoder wsock32 ws2_32) target_link_libraries(transcoder Secur32 Secur32) target_link_libraries(transcoder Bcrypt Bcrypt) +else() + target_link_libraries(transcoder m pthread) endif() diff --git a/README.md b/README.md index c35a523..40f768a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A C library using FFMPEG (libav) to process videos files for kyoo. ## Features - - Return streams informations (language, title, codec, arrengements) + - Return streams informations (language, title, codec, arrangement) - Extract subtitles, fonts & chapters to an external file - Transmux to hls (TODO support multi-audio) diff --git a/include/compatibility.h b/include/compatibility.h index 6f427ce..cddf1e5 100644 --- a/include/compatibility.h +++ b/include/compatibility.h @@ -8,13 +8,20 @@ #include #if defined(_WIN32) || defined(WIN32) - #define kmkdir(dir, mode) mkdir(dir) #include #include + #include + char *strndup(const char *str, size_t count); + int asprintf(char **buffer, const char *fmt, ...); + int vasprintf(char **buffer, const char *fmt, va_list args); + + #define kmkdir(dir, mode) mkdir(dir) + #define S_ISDIR(x) (x & S_IFDIR) #else - #define kmkdir(dir, mode) mkdir(dir, mode) #include + + #define kmkdir(dir, mode) mkdir(dir, mode) #endif #ifdef __MINGW32__ diff --git a/src/compatibility.c b/src/compatibility.c index 53d088c..d2ab144 100644 --- a/src/compatibility.c +++ b/src/compatibility.c @@ -5,6 +5,7 @@ #include "compatibility.h" #include #include +#include #if defined(_WIN32) || defined(WIN32) char *strndup(const char *str, size_t count) @@ -18,4 +19,32 @@ char *strndup(const char *str, size_t count) memcpy(ret, str, len); return ret; } + +int asprintf(char **buffer, const char *fmt, ...) +{ + va_list args; + int ret; + + va_start(args, fmt); + ret = vasprintf(buffer, fmt, args); + va_end(args); + return ret; +} + +int vasprintf(char **buffer, const char *fmt, va_list args) +{ + va_list copy; + char *ret; + int len; + + va_copy(copy, args); + len = vsprintf(NULL, fmt, args); + va_end(copy); + + *buffer = malloc(sizeof(char) * (len + 1)); + if (!*buffer) + return 0; + vsprintf(*buffer, fmt, args); + return len; +} #endif \ No newline at end of file diff --git a/src/extractor.c b/src/extractor.c index 3402fb6..16e1948 100644 --- a/src/extractor.c +++ b/src/extractor.c @@ -132,7 +132,7 @@ void extract_chapters(AVFormatContext *ctx, const char *out_path) *tmp = '\0'; strcat(path, ".txt"); - int fd = open(path, O_WRONLY | O_CREAT, 0644); + FILE *file = fopen(path, "w"); for (unsigned i = 0; i < ctx->nb_chapters; i++) { AVDictionaryEntry *name = av_dict_get(ctx->chapters[i]->metadata, "title", NULL, 0); @@ -143,8 +143,8 @@ void extract_chapters(AVFormatContext *ctx, const char *out_path) continue; double start = chapter->start * av_q2d(chapter->time_base); double end = chapter->end * av_q2d(chapter->time_base); - dprintf(fd, "%f %f %s\n", start, end, name->value); + fprintf(file, "%f %f %s\n", start, end, name->value); } - close(fd); + fclose(file); free(path); } \ No newline at end of file