Answer the question
In order to leave comments, you need to log in
How to make the bot save the video on the server as a file?
I need the bot to build a heat map. The processing code without integration into the bot works fine, everything is done correctly, I upload an mp4 file and everything is processed normally, but if a message.video.file_id is submitted for processing, the processing crashes. So far, the only options are to save the video to the device and subsequently make the handler take the video from the device.
In this case, everything crashes
@bot.message_handler(content_types=['video'])
def video_maker(message):
def main():
capture = cv2.VideoCapture(message.video.file_id)
def main():
capture = cv2.VideoCapture("avaria.mp4")
Answer the question
In order to leave comments, you need to log in
The answer to your question:
@bot.message_handler(content_types=['video'])
def video_maker(message):
chat_id = message.chat.id
file_info = bot.get_file(message.video.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'test/' + file_info.file_path
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "Я сохранил ваше видео!"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question