From 735f7709b92c2690ed263ce17d7c4b3b8a8d90be Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Sun, 29 Mar 2020 12:28:41 +0400
Subject: [PATCH] Fix sending videos larger than 720p.

---
 Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp b/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp
index b6bd69426..263ff877e 100644
--- a/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp
+++ b/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp
@@ -18,6 +18,7 @@ namespace {
 
 constexpr auto kSkipInvalidDataPackets = 10;
 constexpr auto kMaxInlineArea = 1280 * 720;
+constexpr auto kMaxSendingArea = 3840 * 2160; // usual 4K
 
 // See https://github.com/telegramdesktop/tdesktop/issues/7225
 constexpr auto kAlignImageBy = 64;
@@ -60,7 +61,10 @@ ReaderImplementation::ReadResult FFMpegReaderImplementation::readNextFrame() {
 	do {
 		int res = avcodec_receive_frame(_codecContext, _frame.get());
 		if (res >= 0) {
-			if (_frame->width * _frame->height > kMaxInlineArea) {
+			const auto limit = (_mode == Mode::Inspecting)
+				? kMaxSendingArea
+				: kMaxInlineArea;
+			if (_frame->width * _frame->height > limit) {
 				return ReadResult::Error;
 			}
 			processReadFrame();