diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-06-14 03:44:25 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-06-14 03:44:30 +0200 |
commit | 90ce380fccd84d2be8640c8785a38904661af45e (patch) | |
tree | 1ed7f2f84cbde435d62829265219951452604aa8 | |
parent | 44faa1d09df085fc93a3168101ece371b3c4c5d8 (diff) |
Always choose non-av1 and non HDR stream for youtube video to support hardware decoding
-rw-r--r-- | plugins/Youtube.hpp | 1 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 19 |
2 files changed, 16 insertions, 4 deletions
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp index 7a6ea00..28b50bb 100644 --- a/plugins/Youtube.hpp +++ b/plugins/Youtube.hpp @@ -8,6 +8,7 @@ namespace QuickMedia { struct YoutubeFormat { std::string url; int bitrate = 0; + std::string mime_type; }; struct YoutubeVideoFormat { diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index ce359d4..338ada9 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1833,6 +1833,10 @@ namespace QuickMedia { return url.substr(index, end - index); } + static void print_chosen_format(const YoutubeVideoFormat &format) { + fprintf(stderr, "Choosing youtube video format: width: %d, height: %d, fps: %d, bitrate: %d, mime type: %s\n", format.width, format.height, format.fps, format.base.bitrate, format.base.mime_type.c_str()); + } + std::string YoutubeVideoPage::get_video_url(int max_height, bool &has_embedded_audio) { if(!hls_manifest_url.empty()) { has_embedded_audio = true; @@ -1845,12 +1849,14 @@ namespace QuickMedia { } for(const auto &video_format : video_formats) { - if(video_format.height <= max_height) { + if(video_format.height <= max_height && (video_format.base.mime_type.find("mp4") == std::string::npos || video_format.base.mime_type.find("av01") == std::string::npos)) { + print_chosen_format(video_format); has_embedded_audio = video_format.has_embedded_audio; return video_format.base.url; } } + print_chosen_format(video_formats.back()); has_embedded_audio = video_formats.back().has_embedded_audio; return video_formats.back().base.url; } @@ -2060,18 +2066,23 @@ namespace QuickMedia { } } + // TODO: Support HDR? + const Json::Value &quality_label_json = format["qualityLabel"]; + if(quality_label_json.isString() && strstr(quality_label_json.asCString(), "HDR")) continue; + YoutubeFormat youtube_format_base; const Json::Value &mime_type_json = format["mimeType"]; if(!mime_type_json.isString()) continue; + youtube_format_base.mime_type = mime_type_json.asString(); const Json::Value &bitrate_json = format["bitrate"]; if(!bitrate_json.isInt()) continue; youtube_format_base.bitrate = bitrate_json.asInt(); - if(strncmp(mime_type_json.asCString(), "video/", 6) == 0) { + if(strncmp(youtube_format_base.mime_type.c_str(), "video/", 6) == 0) { bool has_embedded_audio = false; - const char *codecs_p = strstr(mime_type_json.asCString(), "codecs=\""); + const char *codecs_p = strstr(youtube_format_base.mime_type.c_str(), "codecs=\""); if(codecs_p) { codecs_p += 8; const char *codecs_sep_p = strchr(codecs_p, ','); @@ -2104,7 +2115,7 @@ namespace QuickMedia { } video_formats.push_back(std::move(video_format)); - } else if(strncmp(mime_type_json.asCString(), "audio/", 6) == 0) { + } else if(strncmp(youtube_format_base.mime_type.c_str(), "audio/", 6) == 0) { YoutubeAudioFormat audio_format; audio_format.base = std::move(youtube_format_base); |