Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Fail to add thumbnail for uploaded videos

Open alphamodel opened this issue 4 years ago • 16 comments

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:

  • send using file path
  • upload video and send using uploaded object
  • send file without attributes
  • set video attributes with 0 width and 0 height
  • add proper attributes for the video
  • resize the jpeg thumb file with longer edge of 200px and 10kb size
  • resize the jpeg thumb file with 200x200px and less than 10kb size
  • resize the jpeg thumb file with longer edge of 320px and less than 200kb size

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 avatar Apr 13 '20 10:04 alphamodel

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.

alphamodel avatar Apr 20 '20 11:04 alphamodel

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.

Lonami avatar Apr 21 '20 15:04 Lonami

@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.

alphamodel avatar Apr 22 '20 04:04 alphamodel

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

Lonami avatar Apr 22 '20 07:04 Lonami

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.

alphamodel avatar Apr 24 '20 10:04 alphamodel

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

Lonami avatar Apr 28 '20 18:04 Lonami

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

alphamodel avatar Apr 29 '20 06:04 alphamodel

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.

Lonami avatar Apr 29 '20 06:04 Lonami

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?

alphamodel avatar Apr 29 '20 11:04 alphamodel

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

Lonami avatar Apr 29 '20 11:04 Lonami

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.

SpEcHiDe avatar May 06 '20 04:05 SpEcHiDe