Add storyVideo.main_frame_timestamp.

This commit is contained in:
levlam 2024-07-16 16:28:49 +03:00
parent ee094ea46e
commit ac90866224
8 changed files with 35 additions and 15 deletions

View File

@ -4184,8 +4184,9 @@ inputStoryAreas areas:vector<inputStoryArea> = InputStoryAreas;
//@minithumbnail Video minithumbnail; may be null
//@thumbnail Video thumbnail in JPEG or MPEG4 format; may be null
//@preload_prefix_size Size of file prefix, which is supposed to be preloaded, in bytes
//@main_frame_timestamp Timestamp of the frame, used as video thumbnail
//@video File containing the video
storyVideo duration:double width:int32 height:int32 has_stickers:Bool is_animation:Bool minithumbnail:minithumbnail thumbnail:thumbnail preload_prefix_size:int32 video:file = StoryVideo;
storyVideo duration:double width:int32 height:int32 has_stickers:Bool is_animation:Bool minithumbnail:minithumbnail thumbnail:thumbnail preload_prefix_size:int32 main_frame_timestamp:double video:file = StoryVideo;
//@class StoryContent @description Contains the content of a story

View File

@ -125,12 +125,14 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
double video_precise_duration = 0.0;
int32 video_duration = 0;
int32 video_preload_prefix_size = 0;
double video_start_ts = 0.0;
string video_waveform;
if (video != nullptr) {
video_precise_duration = video->duration_;
video_duration = static_cast<int32>(std::ceil(video->duration_));
if (document_subtype == Subtype::Story) {
video_preload_prefix_size = video->preload_prefix_size_;
video_start_ts = video->video_start_ts_;
}
video_is_animation = video->nosound_;
auto video_dimensions = get_dimensions(video->w_, video->h_, "documentAttributeVideo");
@ -543,7 +545,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
td_->videos_manager_->create_video(
file_id, std::move(minithumbnail), std::move(thumbnail), std::move(animated_thumbnail), has_stickers,
vector<FileId>(), std::move(file_name), std::move(mime_type), video_duration, video_precise_duration,
dimensions, supports_streaming, video_is_animation, video_preload_prefix_size, !is_web);
dimensions, supports_streaming, video_is_animation, video_preload_prefix_size, video_start_ts, !is_web);
break;
case Document::Type::VideoNote:
td_->video_notes_manager_->create_video_note(file_id, std::move(minithumbnail), std::move(thumbnail),

View File

@ -2992,7 +2992,7 @@ static Result<InputMessageContent> create_input_message_content(
std::move(sticker_file_ids), std::move(file_name), std::move(mime_type),
input_video->duration_, input_video->duration_,
get_dimensions(input_video->width_, input_video->height_, nullptr),
input_video->supports_streaming_, false, 0, false);
input_video->supports_streaming_, false, 0, 0.0, false);
content = make_unique<MessageVideo>(file_id, std::move(caption), input_video->has_spoiler_ && !is_secret);
break;

View File

@ -164,10 +164,11 @@ Result<MessageExtendedMedia> MessageExtendedMedia::get_message_extended_media(
string mime_type = MimeType::from_extension(path_view.extension());
bool has_stickers = !sticker_file_ids.empty();
td->videos_manager_->create_video(
file_id, string(), std::move(thumbnail), AnimationSize(), has_stickers, std::move(sticker_file_ids),
std::move(file_name), std::move(mime_type), type->duration_, type->duration_,
get_dimensions(paid_media->width_, paid_media->height_, nullptr), type->supports_streaming_, false, 0, false);
td->videos_manager_->create_video(file_id, string(), std::move(thumbnail), AnimationSize(), has_stickers,
std::move(sticker_file_ids), std::move(file_name), std::move(mime_type),
type->duration_, type->duration_,
get_dimensions(paid_media->width_, paid_media->height_, nullptr),
type->supports_streaming_, false, 0, 0.0, false);
result.video_file_id_ = file_id;
break;
}

View File

@ -290,10 +290,10 @@ Result<unique_ptr<StoryContent>> get_input_story_content(
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",
static_cast<int32>(std::ceil(input_story->duration_)), input_story->duration_,
get_dimensions(720, 1280, nullptr), true, input_story->is_animation_, 0, false);
td->videos_manager_->create_video(
file_id, string(), PhotoSize(), AnimationSize(), has_stickers, std::move(sticker_file_ids), "story.mp4",
"video/mp4", static_cast<int32>(std::ceil(input_story->duration_)), input_story->duration_,
get_dimensions(720, 1280, nullptr), true, input_story->is_animation_, 0, 0.0, false);
return make_unique<StoryContentVideo>(file_id, FileId());
}

View File

@ -21,6 +21,8 @@
#include "td/utils/misc.h"
#include "td/utils/Status.h"
#include <cmath>
namespace td {
VideosManager::VideosManager(Td *td) : td_(td) {
@ -65,7 +67,7 @@ td_api::object_ptr<td_api::storyVideo> VideosManager::get_story_video_object(Fil
return td_api::make_object<td_api::storyVideo>(
video->precise_duration, video->dimensions.width, video->dimensions.height, video->has_stickers,
video->is_animation, get_minithumbnail_object(video->minithumbnail), std::move(thumbnail),
video->preload_prefix_size, td_->file_manager_->get_file_object(file_id));
video->preload_prefix_size, video->start_ts, td_->file_manager_->get_file_object(file_id));
}
FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
@ -83,7 +85,8 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
}
if (v->duration != new_video->duration || v->precise_duration != new_video->precise_duration ||
v->dimensions != new_video->dimensions || v->supports_streaming != new_video->supports_streaming ||
v->is_animation != new_video->is_animation || v->preload_prefix_size != new_video->preload_prefix_size) {
v->is_animation != new_video->is_animation || v->preload_prefix_size != new_video->preload_prefix_size ||
std::fabs(v->start_ts - new_video->start_ts) > 1e-3) {
LOG(DEBUG) << "Video " << file_id << " info has changed";
v->duration = new_video->duration;
v->precise_duration = new_video->precise_duration;
@ -91,6 +94,7 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
v->supports_streaming = new_video->supports_streaming;
v->is_animation = new_video->is_animation;
v->preload_prefix_size = new_video->preload_prefix_size;
v->start_ts = new_video->start_ts;
}
if (v->file_name != new_video->file_name) {
LOG(DEBUG) << "Video " << file_id << " file name has changed";
@ -190,7 +194,7 @@ void VideosManager::create_video(FileId file_id, string minithumbnail, PhotoSize
AnimationSize animated_thumbnail, bool has_stickers, vector<FileId> &&sticker_file_ids,
string file_name, string mime_type, int32 duration, double precise_duration,
Dimensions dimensions, bool supports_streaming, bool is_animation,
int32 preload_prefix_size, bool replace) {
int32 preload_prefix_size, double start_ts, bool replace) {
auto v = make_unique<Video>();
v->file_id = file_id;
v->file_name = std::move(file_name);
@ -206,6 +210,7 @@ void VideosManager::create_video(FileId file_id, string minithumbnail, PhotoSize
v->supports_streaming = supports_streaming;
v->is_animation = is_animation;
v->preload_prefix_size = preload_prefix_size;
v->start_ts = start_ts;
v->has_stickers = has_stickers;
v->sticker_file_ids = std::move(sticker_file_ids);
on_get_video(std::move(v), replace);

View File

@ -39,7 +39,7 @@ class VideosManager {
void create_video(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail,
bool has_stickers, vector<FileId> &&sticker_file_ids, string file_name, string mime_type,
int32 duration, double precise_duration, Dimensions dimensions, bool supports_streaming,
bool is_animation, int32 preload_prefix_size, bool replace);
bool is_animation, int32 preload_prefix_size, double start_ts, bool replace);
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
tl_object_ptr<telegram_api::InputFile> input_file,
@ -80,6 +80,7 @@ class VideosManager {
PhotoSize thumbnail;
AnimationSize animated_thumbnail;
int32 preload_prefix_size = 0;
double start_ts = 0.0;
bool supports_streaming = false;
bool is_animation = false;

View File

@ -24,6 +24,7 @@ void VideosManager::store_video(FileId file_id, StorerT &storer) const {
bool has_animated_thumbnail = video->animated_thumbnail.file_id.is_valid();
bool has_preload_prefix_size = video->preload_prefix_size != 0;
bool has_precise_duration = video->precise_duration != 0 && video->precise_duration != video->duration;
bool has_start_ts = video->start_ts != 0.0;
BEGIN_STORE_FLAGS();
STORE_FLAG(video->has_stickers);
STORE_FLAG(video->supports_streaming);
@ -31,6 +32,7 @@ void VideosManager::store_video(FileId file_id, StorerT &storer) const {
STORE_FLAG(has_preload_prefix_size);
STORE_FLAG(has_precise_duration);
STORE_FLAG(video->is_animation);
STORE_FLAG(has_start_ts);
END_STORE_FLAGS();
store(video->file_name, storer);
store(video->mime_type, storer);
@ -51,6 +53,9 @@ void VideosManager::store_video(FileId file_id, StorerT &storer) const {
if (has_precise_duration) {
store(video->precise_duration, storer);
}
if (has_start_ts) {
store(video->start_ts, storer);
}
}
template <class ParserT>
@ -59,6 +64,7 @@ FileId VideosManager::parse_video(ParserT &parser) {
bool has_animated_thumbnail;
bool has_preload_prefix_size;
bool has_precise_duration;
bool has_start_ts;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(video->has_stickers);
PARSE_FLAG(video->supports_streaming);
@ -66,6 +72,7 @@ FileId VideosManager::parse_video(ParserT &parser) {
PARSE_FLAG(has_preload_prefix_size);
PARSE_FLAG(has_precise_duration);
PARSE_FLAG(video->is_animation);
PARSE_FLAG(has_start_ts);
END_PARSE_FLAGS();
parse(video->file_name, parser);
parse(video->mime_type, parser);
@ -90,6 +97,9 @@ FileId VideosManager::parse_video(ParserT &parser) {
} else {
video->precise_duration = video->duration;
}
if (has_start_ts) {
parse(video->start_ts, parser);
}
if (parser.get_error() != nullptr || !video->file_id.is_valid()) {
return FileId();
}