From 47bb22a4aee886deb54ca432bdb14747bf2e9160 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 30 Apr 2021 16:33:07 +0200 Subject: Support webp thumbnails --- src/FileAnalyzer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/FileAnalyzer.cpp') diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp index 9f05919..bd13a01 100644 --- a/src/FileAnalyzer.cpp +++ b/src/FileAnalyzer.cpp @@ -21,7 +21,7 @@ namespace QuickMedia { // What about audio ogg files that are not opus? // TODO: Test all of these - static const std::array magic_numbers = { + static const std::array magic_numbers = { MagicNumber{ {'R', 'I', 'F', 'F', -1, -1, -1, -1, 'A', 'V', 'I', ' '}, 12, ContentType::VIDEO_AVI }, MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'p', 'i', 's', 'o', 'm'}, 12, ContentType::VIDEO_MP4 }, MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'p', 'm', 'p', '4', '2'}, 12, ContentType::VIDEO_MP4 }, @@ -47,7 +47,8 @@ namespace QuickMedia { MagicNumber{ {'G', 'I', 'F', '8', '7', 'a'}, 6, ContentType::IMAGE_GIF }, MagicNumber{ {'G', 'I', 'F', '8', '9', 'a'}, 6, ContentType::IMAGE_GIF }, MagicNumber{ {'B', 'M'}, 2, ContentType::IMAGE_BMP }, - MagicNumber{ {'R', 'I', 'F', 'F', -1, -1, -1, -1, 'W', 'E', 'B', 'V', 'P'}, 6, ContentType::IMAGE_WEBP } + MagicNumber{ {'R', 'I', 'F', 'F', -1, -1, -1, -1, 'W', 'E', 'B', 'P'}, 12, ContentType::IMAGE_WEBP }, + MagicNumber{ {'R', 'I', 'F', 'F', -1, -1, -1, -1, 'W', 'E', 'B', 'V', 'P'}, 13, ContentType::IMAGE_WEBP } }; bool is_content_type_video(ContentType content_type) { @@ -121,7 +122,7 @@ namespace QuickMedia { Path destination_path_tmp = destination_path; destination_path_tmp.append(".ftmp"); - const char *program_args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", filepath, "-vframes", "1", "-f", "singlejpeg", destination_path_tmp.data.c_str(), nullptr }; + const char *program_args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", filepath, "-vframes", "1", "-f", "singlejpeg", "--", destination_path_tmp.data.c_str(), nullptr }; std::string ffmpeg_result; if(exec_program(program_args, nullptr, nullptr) != 0) { fprintf(stderr, "Failed to execute ffmpeg, maybe its not installed?\n"); @@ -129,7 +130,8 @@ namespace QuickMedia { } if(width > 0 && height > 0) { - if(create_thumbnail(destination_path_tmp, destination_path, sf::Vector2i(width, height))) { + FileAnalyzer file_analyzer; + if(file_analyzer.load_file(destination_path_tmp.data.c_str(), false) && create_thumbnail(destination_path_tmp, destination_path, sf::Vector2i(width, height), file_analyzer.get_content_type())) { remove(destination_path_tmp.data.c_str()); return true; } -- cgit v1.2.3