diff --git a/Kyoo.Transcoder/include/stream.h b/Kyoo.Transcoder/include/stream.h index 2717f49d..175e50c1 100644 --- a/Kyoo.Transcoder/include/stream.h +++ b/Kyoo.Transcoder/include/stream.h @@ -1,10 +1,4 @@ #pragma once -#ifdef TRANSCODER_EXPORTS -#define API __declspec(dllexport) -#else -#define API __declspec(dllimport) -#endif - #include #include @@ -18,20 +12,38 @@ extern "C" struct Stream char *path; Stream() - : title(NULL), language(NULL), codec(NULL), is_default(NULL), is_forced(NULL), path(NULL) {} + : title(nullptr), language(nullptr), codec(nullptr), is_default(nullptr), is_forced(nullptr), path(nullptr) {} Stream(const char* title, const char* languageCode, const char* codec, bool isDefault, bool isForced) - : title(NULL), language(NULL), codec(NULL), is_default(isDefault), is_forced(isForced), path(NULL) + : title(nullptr), language(nullptr), codec(nullptr), is_default(isDefault), is_forced(isForced), path(nullptr) { - if(title != NULL) + if(title != nullptr) this->title= strdup(title); - if (languageCode != NULL) + if (languageCode != nullptr) language = strdup(languageCode); else language = strdup("und"); - if (codec != NULL) + if (codec != nullptr) this->codec = strdup(codec); } + + Stream(const char *title, const char *languageCode, const char *codec, bool isDefault, bool isForced, const char *path) + : title(nullptr), language(nullptr), codec(nullptr), is_default(isDefault), is_forced(isForced), path(nullptr) + { + if (title != nullptr) + this->title = strdup(title); + + if (languageCode != nullptr) + language = strdup(languageCode); + else + language = strdup("und"); + + if (codec != nullptr) + this->codec = strdup(codec); + + if (path != nullptr) + this->path = strdup(path); + } }; \ No newline at end of file diff --git a/Kyoo.Transcoder/include/transcoder.h b/Kyoo.Transcoder/include/transcoder.h index 24a7e338..47488853 100644 --- a/Kyoo.Transcoder/include/transcoder.h +++ b/Kyoo.Transcoder/include/transcoder.h @@ -13,6 +13,8 @@ extern "C" API int Init(); extern "C" API int transmux(const char *path, const char *out_path, float *playable_duration); +extern "C" API Stream *get_track_info(const char *path, int *stream_count, int *track_count); + //Take the path of the file and the path of the output directory. It will return the list of subtitle streams in the streams variable. The int returned is the number of subtitles extracted. extern "C" API Stream* extract_subtitles(const char *path, const char *outPath, int *streamCount, int *subtitleCount); diff --git a/Kyoo.Transcoder/src/Transcoder.cpp b/Kyoo.Transcoder/src/Transcoder.cpp index 12d1be86..210619f8 100644 --- a/Kyoo.Transcoder/src/Transcoder.cpp +++ b/Kyoo.Transcoder/src/Transcoder.cpp @@ -98,6 +98,43 @@ int transmux(const char *path, const char *out_path, float *playable_duration) return 0; } +Stream *get_track_info(const char *path, int *stream_count, int *track_count) +{ + AVFormatContext *ctx = NULL; + Stream *streams; + + if (open_input_context(&ctx, path) != 0) + return nullptr; + + *stream_count = ctx->nb_streams; + *track_count = 0; + streams = new Stream[*stream_count]; + + //Initialize output and set headers. + for (int i = 0; i < *stream_count; i++) + { + AVStream *stream = ctx->streams[i]; + const AVCodecParameters *codecpar = stream->codecpar; + + if (codecpar->codec_type == AVMEDIA_TYPE_VIDEO || codecpar->codec_type == AVMEDIA_TYPE_AUDIO) + { + AVDictionaryEntry *languageptr = av_dict_get(stream->metadata, "language", NULL, 0); + + *track_count += 1; + + streams[i] = Stream(codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? "VIDEO" : NULL, // title + languageptr ? languageptr->value : NULL, // language + avcodec_get_name(codecpar->codec_id), // format + stream->disposition & AV_DISPOSITION_DEFAULT, // isDefault + stream->disposition & AV_DISPOSITION_FORCED, // isForced + path); // path + } + else + streams[i] = Stream(); + } + avformat_close_input(&ctx); + return streams; +} Stream *extract_subtitles(const char *path, const char *out_path, int *stream_count, int *subtitle_count) { @@ -124,7 +161,10 @@ Stream *extract_subtitles(const char *path, const char *out_path, int *stream_co const AVCodecParameters *in_codecpar = in_stream->codecpar; if (in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) + { output_list[i] = NULL; + streams[i] = Stream(); + } else { *subtitle_count += 1; diff --git a/Kyoo/ClientApp/src/app/player/player.component.html b/Kyoo/ClientApp/src/app/player/player.component.html index 9a5998d8..9f424835 100644 --- a/Kyoo/ClientApp/src/app/player/player.component.html +++ b/Kyoo/ClientApp/src/app/player/player.component.html @@ -63,7 +63,7 @@

{{this.minutes | number: '2.0-0'}}:{{this.seconds | number: '2.0-0'}} / {{this.maxMinutes | number: '2.0-0'}}:{{this.maxSeconds | number: '2.0-0'}}

-