LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.36k stars 1.35k forks source link

Fail to add thumbnail for uploaded videos #1435

Open alphamodel opened 4 years ago

alphamodel commented 4 years ago

I cannot get video thumbnail displayed. The code used to send out video is standard code in the manual. I tried all possible ways I can find to send the video. Following are the things I have tried:

All files are send with supports_streaming=True. If additional attribute is provided, supports_streaming is also set to True in the attributes. Does anyone succeed in upload video files larger than 100 MB with thumbnail?

  await client.send_file(
      username,
      uploaded_file,
      caption=caption,
      attributes=attributes,
      thumb=tmpfile,
      supports_streaming=True)

Sample thumbnail used when calling send_file:

joBBEfdnT2g

alphamodel commented 4 years ago

BTW, I tried to use pyrogram to send video, and it works. I also checked code for these two functions, they are almost identical. Any idea what is going on here?

Both libraries use InputMediaUploadedDocument to upload video with thumbnail, but telethon does not work while pyrogram works as expected.

Lonami commented 4 years ago

If you've found how to solve the issue, please indicate what the solution is.

If the issue is not solved, please reopen it or let me know so I can reopen it.

alphamodel commented 4 years ago

@Lonami No, I do not find solution within telethon. It seems no one is interested in the issue, and pyrogram is able to provide the functionality as mentioned in the last comment, so it may be called partial solved.

Lonami commented 4 years ago

Well, I am interested in solving issues within my library. Whether I have the time or interest to tackle them now is another matter.

alphamodel commented 4 years ago

I partially traced the code, for the case when the file is uploaded using upload_file function, the send_file code does not handle thumbnail at all:

https://github.com/LonamiWebs/Telethon/blob/a353ae3b6511592bdb25dbf47075eaeb75a2acdb/telethon/client/uploads.py#L642-L659

Sorry, seems in the current repo the code is patched already. I have tested the current version is working as expected.

Lonami commented 4 years ago

Weird thing, I'm testing both libraries with output.mp4.zip and none show the custom thumbnail in Telegram Desktop (bot is a Telethon client, app is a client using the other library):

desktop = pathlib.Path(...)
with bot, app:
    bot.send_file('lonami', desktop / 'output.mp4', thumb=desktop / 'oh.jpg')
    app.send_video('lonami', desktop / 'output.mp4', thumb=desktop / 'oh.jpg')

image

alphamodel commented 4 years ago

@Lonami Are the size or dimensions of image too large?

Lonami commented 4 years ago

The file size is 26KB which I hoped would be small enough for a thumbnail used in such a large video preview but maybe it has to be even smaller. If this is the case maybe Telethon could do the resizing…

Edit: tried with a 2742 bytes JPEG file, 62x57 pixels, still doesn't work.

alphamodel commented 4 years ago

Maybe for file larger than 10MB, telegram will not generate thumbnail for it and use the custom one. Otherwise, telegram will use thumbnail generated by its server?

Lonami commented 4 years ago

Maybe the video needs to be larger than 10MB, but that would be a very silly restriction.

SpEcHiDe commented 4 years ago

this is how I had done using an old version of Telethon, but I think it still works with the newer versions.

Also, less than 10MB video thumbnails are generated by Telegram servers, and bots can't currently override it, to the best of my knowledge.

mancausoft commented 1 year ago

I have the same problem. my code:

async def send_correcly_media(event, files):
   media = []
   thumbs = []
   attributes = []
   nomedia = []
   for f in files:
      if f.endswith('.mp4'):
         thumb, duration = process_video(f)
         width, height = get_video_dimensions(f)
         media.append(f)
         thumbs.append(thumb)
         attributes.append(DocumentAttributeVideo(duration=duration, w=width, h=height, supports_streaming=True))
      elif f.endswith('.message'):
         pass
      else:
         nomedia.append(f)
   msg = remove_links(event.message.text)
   if media:
      await event.reply(msg, file=media, thumb=thumbs, attributes=attributes, supports_streaming=True)
   if nomedia:
      await event.reply(msg, file=nomedia)

Also all album with videos file created by Telethon works correctly on telegram-desktop but are show as single file on telgram for android :'(

Lonami commented 1 year ago

If you believe the library is doing something wrong, you are welcome to try with raw API. You can also enable debug mode in official clients to learn how they do it, although I do not remember the details on how to achieve that.

mancausoft commented 12 months ago

the bug seems to me here: https://github.com/LonamiWebs/Telethon/blob/v1/telethon/client/uploads.py#L377

the _send_album don't support thumb, so the thumb is not sended

serverworm commented 11 months ago

this problem is very relevant to this day

RevealedSoulEven commented 2 months ago

Still problem. I set custom thumbnail on videos while uploading, more I want to change by forwarding but I can't