From 90ce380fccd84d2be8640c8785a38904661af45e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 14 Jun 2021 03:44:25 +0200 Subject: Always choose non-av1 and non HDR stream for youtube video to support hardware decoding --- src/plugins/Youtube.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/plugins/Youtube.cpp') 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); -- cgit v1.2.3