Implementing a adprintf for windows

This commit is contained in:
Zoe Roux
2021-04-15 21:34:08 +02:00
parent 06c3205098
commit d2ad81e4a1
5 changed files with 44 additions and 7 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -8,13 +8,20 @@
#include <stdio.h>
#if defined(_WIN32) || defined(WIN32)
#define kmkdir(dir, mode) mkdir(dir)
#include <io.h>
#include <stddef.h>
#include <stdarg.h>
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 <unistd.h>
#define kmkdir(dir, mode) mkdir(dir, mode)
#endif
#ifdef __MINGW32__

View File

@@ -5,6 +5,7 @@
#include "compatibility.h"
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#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

View File

@@ -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);
}