D
D
drqqv2022-02-22 21:58:55
Python
drqqv, 2022-02-22 21:58:55

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)


In this everything works stably
def main():
    capture = cv2.VideoCapture("avaria.mp4")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Musickk, 2022-02-22
@drqqv

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, "Я сохранил ваше видео!"

do not forget in the folder (in my case it is the folder test ) create a folder videos

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question