From 690048e7206687013487f1da1e23d73644890eb8 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 24 Nov 2019 23:22:25 +0100 Subject: [PATCH] Adding video and audio codec detection in the crawler. Adding multiple audio support for the playback method detector. --- Kyoo.Transcoder/include/stream.h | 34 +++++++++----- Kyoo.Transcoder/include/transcoder.h | 2 + Kyoo.Transcoder/src/Transcoder.cpp | 40 ++++++++++++++++ .../src/app/player/player.component.html | 2 +- .../videoSupport/playbackMethodDetector.js | 2 +- .../playbackMethodDetector.js.map | 2 +- .../videoSupport/playbackMethodDetector.ts | 2 +- Kyoo/InternalAPI/Crawler/Crawler.cs | 13 ++++-- .../LibraryManager/ILibraryManager.cs | 4 +- .../LibraryManager/LibraryManager.cs | 9 ++-- Kyoo/InternalAPI/Transcoder/ITranscoder.cs | 9 ++-- Kyoo/InternalAPI/Transcoder/Transcoder.cs | 9 ++++ Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs | 35 +++++++++++++- Kyoo/Models/Track.cs | 46 ++++++++++--------- Kyoo/Models/WatchItem.cs | 8 +++- 15 files changed, 167 insertions(+), 50 deletions(-) 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'}}

-