aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/Youtube.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 338ada9..ce7e8fa 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -1837,6 +1837,22 @@ namespace QuickMedia {
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());
}
+ static const YoutubeVideoFormat* get_highest_resolution_mp4_non_av1(const std::vector<YoutubeVideoFormat> &video_formats, int max_height) {
+ for(const YoutubeVideoFormat &video_format : video_formats) {
+ 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)
+ return &video_format;
+ }
+ return nullptr;
+ }
+
+ static const YoutubeVideoFormat* get_highest_resolution_non_mp4(const std::vector<YoutubeVideoFormat> &video_formats, int max_height) {
+ for(const YoutubeVideoFormat &video_format : video_formats) {
+ if(video_format.height <= max_height && video_format.base.mime_type.find("mp4") == std::string::npos)
+ return &video_format;
+ }
+ return nullptr;
+ }
+
std::string YoutubeVideoPage::get_video_url(int max_height, bool &has_embedded_audio) {
if(!hls_manifest_url.empty()) {
has_embedded_audio = true;
@@ -1848,12 +1864,17 @@ namespace QuickMedia {
return "";
}
- for(const auto &video_format : video_formats) {
- 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;
- }
+ const YoutubeVideoFormat *best_mp4 = get_highest_resolution_mp4_non_av1(video_formats, max_height);
+ const YoutubeVideoFormat *best_non_mp4 = get_highest_resolution_non_mp4(video_formats, max_height);
+ // We prefer mp4 (h264) because it has the best hardware decoding support
+ if(best_mp4 && (!best_non_mp4 || best_mp4->height >= best_non_mp4->height)) {
+ print_chosen_format(*best_mp4);
+ has_embedded_audio = best_mp4->has_embedded_audio;
+ return best_mp4->base.url;
+ } else if(best_non_mp4) {
+ print_chosen_format(*best_non_mp4);
+ has_embedded_audio = best_non_mp4->has_embedded_audio;
+ return best_non_mp4->base.url;
}
print_chosen_format(video_formats.back());