mirror of
https://github.com/zoriya/Kyoo.Transcoder.git
synced 2025-12-06 06:26:11 +00:00
Cleaning up, trying to support windows
This commit is contained in:
@@ -9,8 +9,10 @@
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define kmkdir(dir, mode) mkdir(dir)
|
||||
#include <io.h>
|
||||
#else
|
||||
#define kmkdir(dir, mode) mkdir(dir, mode)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "helper.h"
|
||||
#include <stdlib.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -94,16 +93,20 @@ void extract_attachment(stream *font, const char *out_path, AVStream *stream)
|
||||
return;
|
||||
strcpy(font->path, out_path);
|
||||
strcat(font->path, "/Attachments/");
|
||||
if (path_mkdir(font->path, 0755) < 0)
|
||||
return free(font->path);
|
||||
if (path_mkdir(font->path, 0755) < 0) {
|
||||
free(font->path);
|
||||
return;
|
||||
}
|
||||
strcat(font->path, filename->value);
|
||||
long count = strchr(filename->value, '.') - filename->value;
|
||||
unsigned long count = strchr(filename->value, '.') - filename->value;
|
||||
if (count > 0)
|
||||
font->title = strndup(filename->value, count);
|
||||
|
||||
int fd = open(font->path, O_WRONLY | O_CREAT, 0644);
|
||||
if (fd == -1)
|
||||
return perror("Kyoo couldn't extract an attachment.");
|
||||
if (fd == -1) {
|
||||
perror("Kyoo couldn't extract an attachment.");
|
||||
return;
|
||||
}
|
||||
write(fd, stream->codecpar->extradata, stream->codecpar->extradata_size);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ stream *extract_infos(const char *path,
|
||||
stream *streams;
|
||||
|
||||
if (open_input_context(&ctx, path) != 0)
|
||||
return free(streams), NULL;
|
||||
return NULL;
|
||||
*stream_count = ctx->nb_streams;
|
||||
*track_count = 0;
|
||||
streams = calloc(ctx->nb_streams, sizeof(stream));
|
||||
@@ -105,8 +105,10 @@ stream *extract_infos(const char *path,
|
||||
if (!list_empty((void **)output_list, ctx->nb_streams))
|
||||
write_to_outputs(output_list, ctx);
|
||||
avformat_close_input(&ctx);
|
||||
if (!output_list)
|
||||
return free(streams), NULL;
|
||||
if (!output_list) {
|
||||
free(streams);
|
||||
return NULL;
|
||||
}
|
||||
free(output_list);
|
||||
return streams;
|
||||
}
|
||||
@@ -43,9 +43,12 @@ static int *prepare_streammap(AVFormatContext *in_ctx, AVFormatContext *out_ctx)
|
||||
static AVDictionary *create_options_context(const char *out_path)
|
||||
{
|
||||
AVDictionary *options = NULL;
|
||||
char seg_path[strlen(out_path) + 22];
|
||||
int folder_index = strrchr(out_path, '/') - out_path;
|
||||
char *seg_path = malloc(sizeof(char) * strlen(out_path) + 22);
|
||||
int folder_index;
|
||||
|
||||
if (!seg_path)
|
||||
return NULL;
|
||||
folder_index = (int)(strrchr(out_path, '/') - out_path);
|
||||
sprintf(seg_path, "%.*s/segments/", folder_index, out_path);
|
||||
if (path_mkdir(seg_path, 0755) < 0) {
|
||||
fprintf(stderr, "Error: Couldn't create segment output folder. "
|
||||
@@ -53,7 +56,7 @@ static AVDictionary *create_options_context(const char *out_path)
|
||||
return NULL;
|
||||
}
|
||||
strcat(seg_path, "%v-%03d.ts");
|
||||
av_dict_set(&options, "hls_segment_filename", seg_path, 0);
|
||||
av_dict_set(&options, "hls_segment_filename", seg_path, AV_DICT_DONT_STRDUP_VAL);
|
||||
av_dict_set(&options, "hls_base_url", "segments/", 0);
|
||||
av_dict_set(&options, "hls_list_size", "0", 0);
|
||||
av_dict_set(&options, "streaming", "1", 0);
|
||||
|
||||
Reference in New Issue
Block a user