telethon-secret-chat icon indicating copy to clipboard operation
telethon-secret-chat copied to clipboard

Video Bytes are corrupted!

Open mojtabaasg opened this issue 3 years ago • 8 comments

When someone sends me a video in secret chat, any video, the video is corrupted. This is my code:

async def downloader(event):
    if event.decrypted_event and not isinstance(event.decrypted_event.file, InputEncryptedFileEmpty):
        cache = manager.download_secret_media(event.decrypted_event)
        file_name = event.decrypted_event.media.mime_type.split("/")[0] + '.' + event.decrypted_event.media.mime_type.split("/")[1]  # video.mp4
        with open(f"./{file_name}", "wb") as f:
            f.write(cache)
            f.close()

This code works with all file types except videos after saving videos with this way, video can not be opened by any app. am I wrong or there is a problem?

mojtabaasg avatar Jun 18 '21 16:06 mojtabaasg

I requested from my friend to send me random video. this is the video he sent: https://user-images.githubusercontent.com/83122377/122592580-b3bc1480-d079-11eb-8c6e-c58fa7bcf9ce.mp4

and this is the video I saved using code above: https://user-images.githubusercontent.com/83122377/122592644-ce8e8900-d079-11eb-8b3c-1e5078ea562f.mp4

mojtabaasg avatar Jun 18 '21 16:06 mojtabaasg

can you also provide the telegram version that was used? (android or macOS).

painor avatar Jun 18 '21 16:06 painor

Its an unofficial app in android

mojtabaasg avatar Jun 18 '21 18:06 mojtabaasg

I tried with official Telegram app 1 min ago and this problem again

mojtabaasg avatar Jun 18 '21 18:06 mojtabaasg

same as @mojtabaasg i tried sending video file from the official Telegram client on android and the video file can't be opened. And yes! it works fine for other file like photo

Touexe avatar Jul 01 '21 08:07 Touexe

any solution for this?

Touexe avatar Dec 20 '21 23:12 Touexe

well just found out the problem is telethon itself. any downloading message with key and iv provided will be messed up and corrupted. not just video file, I have tried sending a pdf file and rar file. both are corrupted after sending. I once tried sending a video file without compression (sending as document), the video file is not really corrupted, its playable only in the first chunk.

Edited : Found solution that worked for me! I decided not to make the file being decrypted in chunk during downloading in telethon _download_file function. Instead, I let the encrypted file fully written on disk and later decrypted the file later. And it worked! @painor maybe you could provide a fix for that using this solution?

Touexe avatar Jan 09 '22 14:01 Touexe

@Touexe can u share code how u downloaded in enc. format and then decry. it on disk

0tanvi00 avatar Aug 18 '24 08:08 0tanvi00