From 71faaae22fea09eec6513613dd7353a1b33f4c2e Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 5 Jun 2023 14:33:00 +0300 Subject: [PATCH] Support precise video duration. --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/DocumentsManager.cpp | 10 ++++++---- td/telegram/MessageContent.cpp | 2 +- td/telegram/StoryContent.cpp | 8 +++++++- td/telegram/VideosManager.cpp | 13 ++++++++----- td/telegram/VideosManager.h | 5 +++-- td/telegram/VideosManager.hpp | 12 ++++++++++++ td/telegram/cli.cpp | 6 +++++- 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b52b1d63b..d118d3f7a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4856,8 +4856,8 @@ inputStoryContentPhoto photo:InputFile added_sticker_file_ids:vector = In //@description A video story //@video Video to be sent. The video size must be 720x1280. The video must be stored in MPEG4 format, encoded by x265 codec and must be streamable //@added_sticker_file_ids File identifiers of the stickers added to the video, if applicable -//@duration Duration of the video, in seconds; 0-60 -inputStoryContentVideo video:InputFile added_sticker_file_ids:vector duration:int32 = InputStoryContent; +//@duration Precise duration of the video, in seconds; 0-60 +inputStoryContentVideo video:InputFile added_sticker_file_ids:vector duration:double = InputStoryContent; //@description Contains information about interactions with a story diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 503444423..f54d95cc2 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -121,10 +121,12 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo UNREACHABLE(); } } + double video_precise_duration = 0.0; int32 video_duration = 0; int32 video_preload_prefix_size = 0; string video_waveform; if (video != nullptr) { + video_precise_duration = video->duration_; video_duration = static_cast(std::ceil(video->duration_)); if (document_subtype == Subtype::Story) { video_preload_prefix_size = video->preload_prefix_size_; @@ -536,10 +538,10 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo std::move(custom_emoji), sticker_format, load_data_multipromise_ptr); break; case Document::Type::Video: - td_->videos_manager_->create_video(file_id, std::move(minithumbnail), std::move(thumbnail), - std::move(animated_thumbnail), has_stickers, vector(), - std::move(file_name), std::move(mime_type), video_duration, dimensions, - supports_streaming, video_preload_prefix_size, !is_web); + td_->videos_manager_->create_video( + file_id, std::move(minithumbnail), std::move(thumbnail), std::move(animated_thumbnail), has_stickers, + vector(), std::move(file_name), std::move(mime_type), video_duration, video_precise_duration, + dimensions, supports_streaming, video_preload_prefix_size, !is_web); break; case Document::Type::VideoNote: td_->video_notes_manager_->create_video_note(file_id, std::move(minithumbnail), std::move(thumbnail), diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 7cbaf3169..43a5262fa 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2103,7 +2103,7 @@ static Result create_input_message_content( bool has_stickers = !sticker_file_ids.empty(); td->videos_manager_->create_video(file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids), std::move(file_name), std::move(mime_type), - input_video->duration_, + input_video->duration_, input_video->duration_, get_dimensions(input_video->width_, input_video->height_, nullptr), input_video->supports_streaming_, 0, false); diff --git a/td/telegram/StoryContent.cpp b/td/telegram/StoryContent.cpp index 457580bb3..94b583e83 100644 --- a/td/telegram/StoryContent.cpp +++ b/td/telegram/StoryContent.cpp @@ -17,6 +17,8 @@ #include "td/utils/common.h" +#include + namespace td { class StoryContentPhoto final : public StoryContent { @@ -159,11 +161,15 @@ Result> get_input_story_content( false, false)); file_id = td->file_manager_->copy_file_id(file_id, FileType::VideoStory, owner_dialog_id, "get_input_story_content"); + if (input_story->duration_ < 0 || input_story->duration_ > 60.0) { + return Status::Error(400, "Invalid video duration specified"); + } auto sticker_file_ids = td->stickers_manager_->get_attached_sticker_file_ids(input_story->added_sticker_file_ids_); bool has_stickers = !sticker_file_ids.empty(); td->videos_manager_->create_video(file_id, string(), PhotoSize(), AnimationSize(), has_stickers, - std::move(sticker_file_ids), "story.mp4", "video/mp4", input_story->duration_, + std::move(sticker_file_ids), "story.mp4", "video/mp4", + static_cast(std::ceil(input_story->duration_)), input_story->duration_, get_dimensions(720, 1280, nullptr), true, 0, false); return make_unique(file_id, FileId()); diff --git a/td/telegram/VideosManager.cpp b/td/telegram/VideosManager.cpp index 7bbc70eef..627abd738 100644 --- a/td/telegram/VideosManager.cpp +++ b/td/telegram/VideosManager.cpp @@ -65,11 +65,12 @@ FileId VideosManager::on_get_video(unique_ptr