Вот упрощенная версия кода, который я использую для редактирования сообщения с обработанным видео:
Код: Выделить всё
video_file = await video.get_file()
print(video_file)
random = randint(0,9999)
input_path = f"input_{user_id}_{random}.mp4"
output_path = f"output_{user_id}_{random}.mp4"
await video_file.download_to_drive(input_path)
loop = asyncio.get_event_loop()
executor = ThreadPoolExecutor()
await loop.run_in_executor(executor, process_video_sync, input_path, output_path, watermark_path, settings)
try:
if return_file:
return open(output_path, 'rb')
if channel:
chat_id = post.chat_id
message_id = post.message_id
caption = post.caption if post.caption else ""
if settings['has_signature']:
signature = settings['signature']
else:
caption = post.caption_html if post.caption_html else (post.caption or "")
video_clip = VideoFileClip(output_path)
await context.bot.edit_message_media(
chat_id=chat_id,
message_id=message_id,
media=InputMediaVideo(media=open(output_path, 'rb'), width=video_clip.w, height=video_clip.h, caption=caption, parse_mode="HTML")
)
elif update.message:
caption = update.message.caption if update.message.caption else ""
video_clip = VideoFileClip(output_path)
with open(output_path, 'rb') as video_file:
await update.message.reply_video(
video=InputFile(video_file),
caption=caption,
width=video_clip.w,
height=video_clip.h,
supports_streaming=True
)
except Exception as e:
logger.error("Error in sending video. Exception Type:", e.args[0][0], "Message:", e.args[0][1])
finally:
os.remove(input_path)
os.remove(output_path)
Как я могу гарантировать, что при редактировании видео на канале соотношение сторон останется таким же, как оригинал, и его не обрезают и не превращают в квадрат?
Подробнее здесь: https://stackoverflow.com/questions/790 ... -to-square