From e2cefa816e007b38988a7de0b2f0660b83abf9de Mon Sep 17 00:00:00 2001 From: Rikin Patel Date: Sat, 19 Jul 2025 22:36:16 +0530 Subject: [PATCH] Documente example for upload video with thumbnail --- EXAMPLES.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/EXAMPLES.md b/EXAMPLES.md index e32e10d..abb6f81 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -224,6 +224,48 @@ var inputFile = await client.UploadFileAsync(Filepath); await client.SendMediaAsync(peer, "Here is the photo", inputFile); ``` + +## Upload a video with custom thumbnail +```csharp +const string videoPath = @"C:\...\video.mp4"; +const string thumbnailPath = @"C:\...\thumbnail.jpg"; + +var chats = await client.Messages_GetAllChats(); +InputPeer peer = chats.chats[1234567890]; // the chat we want + +// Extract video information using FFMpegCore or similar library +var mediaInfo = await FFmpeg.GetMediaInfo(videoPath); +var videoStream = mediaInfo.VideoStreams.FirstOrDefault(); +int width = videoStream?.Width ?? 0; +int height = videoStream?.Height ?? 0; +int duration = (int)(mediaInfo.Duration.TotalSeconds); + +// Upload both video file and thumbnail +var inputFile = await client.UploadFileAsync(videoPath); +var inputThumb = await client.UploadFileAsync(thumbnailPath); + +// Create video media with thumbnail and attributes +var media = new InputMediaUploadedDocument +{ + file = inputFile, + thumb = inputThumb, + mime_type = "video/mp4", + attributes = new DocumentAttribute[] { + new DocumentAttributeVideo { + w = width, + h = height, + duration = duration, + flags = DocumentAttributeVideo.Flags.supports_streaming + }, + new DocumentAttributeFilename { file_name = Path.GetFileName(videoPath) } + }, + flags = InputMediaUploadedDocument.Flags.has_thumb +}; + +await client.SendMessageAsync(peer, Path.GetFileName(videoPath), media); +``` +*Note: This example requires FFMpegCore NuGet package for video metadata extraction. You can also manually set width, height, and duration if you know the video properties.* + ## Send a grouped media album using photos from various sources ```csharp