ssebastianoo / yt-dlp-telegram

Use yt-dlp on Telegram
https://t.me/SatoruBot
MIT License
37 stars 13 forks source link

pass width/height when uploading videos to telegram to render them properly #11

Open ImpressionableRaccoon opened 17 hours ago

ImpressionableRaccoon commented 17 hours ago

Hi! I really appreciate your bot! Thank you for providing a free deployed solution! 🙂

However, when I'm trying to download some big videos from instagram, they are showing as squares in telegram clients.

image

So it happens because telegram doesn't analyze big files (10mb+) and duration/widht/height/thumbnail parameters need to be provided manually.

Here are two examples:

bot.send_video(chat_id=chat_id, video=open("video.mp4", 'rb'))
bot.send_video(chat_id=chat_id, video=open("video.mp4", 'rb'), width=720, height=1280)
image

And a few links for testing: https://www.instagram.com/reel/DDH5sRRuoA9 https://www.instagram.com/reel/DAduPHBy891

ssebastianoo commented 16 hours ago

I never noticed this, thanks for reporting it, I’ll try to fix it this afternoon. I guess I can just force the resolution to be 9:16 when instagram is the provider but this means that it also happens with other services that I probably can’t predict so I’ll search for a workaround

ImpressionableRaccoon commented 15 hours ago

Maybe it's good idea to use ffmpeg to get all needed metadata and thumbnail

$ ffprobe -v error -select_streams v:0 -show_entries stream=width,height -show_entries format=duration -of json video.mp4
{
    "streams": [
        {
            "width": 720,
            "height": 1280
        }
    ],
    "format": {
        "duration": "53.565578"
    }
}

$ ffmpeg -i video.mp4 -ss 00:00:00.000 -vframes 1 thumbnail.jpg

And then provide it like this

bot.send_video(
    chat_id=chat_id,
    video=open("video.mp4", 'rb'),

    width=720,
    height=1280,
    duration=53,
    thumbnail=open("thumbnail.jpg", 'rb'),
)

Now it looks really well even in the media tab

image
ssebastianoo commented 13 hours ago

should be fixed, yt-dlp gives you the width and height in info['requested_downloads']

https://github.com/ssebastianoo/yt-dlp-telegram/commit/810b573b5a13ed55f4c3eaeae8a5ef678056b80f

if you can test it and confirm that it works I'll close the issue