From 5baf78fddef6905670780952c0d743f2d10bfc47 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 10 Sep 2019 19:16:09 +0200 Subject: [PATCH] Decoding subtitles streams. --- Kyoo.Transcoder/src/Stream.h | 18 +++++++------- Kyoo.Transcoder/src/Transcoder.cpp | 25 +++++++++++++------- Kyoo/InternalAPI/Transcoder/Transcoder.cs | 2 +- Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs | 4 ++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Kyoo.Transcoder/src/Stream.h b/Kyoo.Transcoder/src/Stream.h index af98f920..4fda3f6f 100644 --- a/Kyoo.Transcoder/src/Stream.h +++ b/Kyoo.Transcoder/src/Stream.h @@ -7,12 +7,12 @@ #include -extern "C" API struct Stream -{ - std::string title; - std::string languageCode; - std::string format; - bool isDefault; - bool isForced; - std::string path; -}; \ No newline at end of file +//extern "C" API struct Stream +//{ +// std::string title; +// std::string languageCode; +// std::string format; +// bool isDefault; +// bool isForced; +// std::string path; +//}; \ No newline at end of file diff --git a/Kyoo.Transcoder/src/Transcoder.cpp b/Kyoo.Transcoder/src/Transcoder.cpp index 9f7b0092..089d3919 100644 --- a/Kyoo.Transcoder/src/Transcoder.cpp +++ b/Kyoo.Transcoder/src/Transcoder.cpp @@ -13,11 +13,6 @@ int Init() return 42; } -//Video ScanVideo(std::string path) -//{ -// -//} - void ExtractSubtitles(const char* path) { AVFormatContext* formatContext = NULL; @@ -34,13 +29,25 @@ void ExtractSubtitles(const char* path) return; } - AVDictionaryEntry* metadata = NULL; - - while ((metadata = av_dict_get(formatContext->metadata, "", metadata, AV_DICT_IGNORE_SUFFIX))) + for (unsigned int i = 0; i < formatContext->nb_streams; i++) { - std::cout << metadata->key << " - " << metadata->value << std::endl; + AVStream* stream = formatContext->streams[i]; + const AVCodecContext* streamContext = stream->codec; + + if (streamContext->codec_type == AVMEDIA_TYPE_SUBTITLE) + { + const AVCodec* dec = streamContext->codec; + std::cout << "Stream #" << i << ", stream type: " << streamContext->codec_type << " codec: " << dec->long_name << std::endl; + } } + //const char* outputPath = "subtitle.ass"; + //if (avformat_alloc_output_context2(&formatContext, NULL, NULL, outputPath) < 0) + //{ + // std::cout << "Error: Can't create output file at " << outputPath << std::endl; + // return; + //} + avformat_close_input(&formatContext); return; diff --git a/Kyoo/InternalAPI/Transcoder/Transcoder.cs b/Kyoo/InternalAPI/Transcoder/Transcoder.cs index 2e477740..2942abe1 100644 --- a/Kyoo/InternalAPI/Transcoder/Transcoder.cs +++ b/Kyoo/InternalAPI/Transcoder/Transcoder.cs @@ -13,7 +13,7 @@ namespace Kyoo.InternalAPI public void ExtractSubtitles(string path) { - Debug.WriteLine("&Transcoder extract subs: " + TranscoderAPI.ExtractSubtitles(path)); + TranscoderAPI.ExtractSubtitles(path); } public void GetVideo(string path) diff --git a/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs b/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs index 516a9ee1..40571d2a 100644 --- a/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs +++ b/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs @@ -7,9 +7,9 @@ namespace Kyoo.InternalAPI.TranscoderLink private const string TranscoderPath = @"C:\Projects\Kyoo\Debug\Kyoo.Transcoder.dll"; [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - public extern static string Init(); + public extern static int Init(); [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - public extern static string ExtractSubtitles(string path); + public extern static void ExtractSubtitles(string path); } }