aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/FileAnalyzer.hpp2
-rw-r--r--src/FileAnalyzer.cpp5
-rw-r--r--src/plugins/Matrix.cpp29
3 files changed, 25 insertions, 11 deletions
diff --git a/include/FileAnalyzer.hpp b/include/FileAnalyzer.hpp
index 92bd042..be0cc25 100644
--- a/include/FileAnalyzer.hpp
+++ b/include/FileAnalyzer.hpp
@@ -34,7 +34,7 @@ namespace QuickMedia {
bool is_content_type_image(ContentType content_type);
const char* content_type_to_string(ContentType content_type);
- bool video_get_first_frame(const char *filepath, const char *destination_path, int width, int height);
+ bool video_get_first_frame(const char *filepath, const char *destination_path);
class FileAnalyzer {
public:
diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp
index adfb7cc..b397def 100644
--- a/src/FileAnalyzer.cpp
+++ b/src/FileAnalyzer.cpp
@@ -87,9 +87,8 @@ namespace QuickMedia {
return 0;
}
- bool video_get_first_frame(const char *filepath, const char *destination_path, int width, int height) {
- std::string thumbnail_size = std::to_string(width) + "x" + std::to_string(height);
- const char *program_args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", filepath, "-vframes", "1", "-f", "singlejpeg", "-s", thumbnail_size.c_str(), destination_path, nullptr };
+ bool video_get_first_frame(const char *filepath, const char *destination_path) {
+ const char *program_args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", filepath, "-vframes", "1", "-f", "singlejpeg", destination_path, nullptr };
std::string ffmpeg_result;
if(exec_program(program_args, nullptr, nullptr) != 0) {
fprintf(stderr, "Failed to execute ffmpeg, maybe its not installed?\n");
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 6050b18..4ac4da1 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3205,13 +3205,28 @@ namespace QuickMedia {
char tmp_filename[] = "/tmp/quickmedia_video_frame_XXXXXX";
int tmp_file = mkstemp(tmp_filename);
if(tmp_file != -1) {
- if(video_get_first_frame(filepath.c_str(), tmp_filename, thumbnail_max_size.x, thumbnail_max_size.y)) {
- UploadInfo upload_info_ignored; // Ignore because it wont be set anyways. Thumbnails dont have thumbnails.
- PluginResult upload_thumbnail_result = upload_file(room, tmp_filename, thumbnail_info, upload_info_ignored, err_msg, false);
- if(upload_thumbnail_result != PluginResult::OK) {
- close(tmp_file);
- remove(tmp_filename);
- return upload_thumbnail_result;
+ if(video_get_first_frame(filepath.c_str(), tmp_filename)) {
+ char tmp_filename_thumbnail[] = "/tmp/quickmedia_thumbnail_XXXXXX";
+ int tmp_file_thumbnail = mkstemp(tmp_filename_thumbnail);
+ if(tmp_file_thumbnail != -1) {
+ std::string thumbnail_path;
+ if(create_thumbnail(tmp_filename, tmp_filename_thumbnail, thumbnail_max_size))
+ thumbnail_path = tmp_filename_thumbnail;
+ else
+ thumbnail_path = tmp_filename;
+
+ UploadInfo upload_info_ignored; // Ignore because it wont be set anyways. Thumbnails dont have thumbnails.
+ PluginResult upload_thumbnail_result = upload_file(room, thumbnail_path, thumbnail_info, upload_info_ignored, err_msg, false);
+ if(upload_thumbnail_result != PluginResult::OK) {
+ close(tmp_file_thumbnail);
+ remove(tmp_filename_thumbnail);
+ return upload_thumbnail_result;
+ }
+
+ close(tmp_file_thumbnail);
+ remove(tmp_filename_thumbnail);
+ } else {
+ fprintf(stderr, "Failed to create temporary file for video thumbnail, ignoring thumbnail...\n");
}
} else {
fprintf(stderr, "Failed to get first frame of video, ignoring thumbnail...\n");